如何访问网络摄像头以下代码在谷歌合作实验室

问题描述

错误:“ nonetype”对象没有属性“ shape” 我尝试使用webcam.read()访问网络摄像头,但返回false 同样在jupyter笔记本中工作的地方 但我希望它能像我们一样在Google colab上正常工作

while True:
(rval,im) = webcam.read()
im=cv2.flip(im,1,1) #Flip to act as a mirror

# Resize the image to speed up detection
mini = cv2.resize(im,(im.shape[1] // size,im.shape[0] // size))


# detect MultiScale / faces 
faces = classifier.detectMultiScale(mini)

# Draw rectangles around each face
for f in faces:
    (x,y,w,h) = [v * size for v in f] #Scale the shapesize backup
    #Save just the rectangle faces in SubRecFaces
    face_img = im[y:y+h,x:x+w]
    resized=cv2.resize(face_img,(150,150))
    normalized=resized/255.0
    reshaped=np.reshape(normalized,(1,150,3))
    reshaped = np.vstack([reshaped])
    result=model.predict(reshaped)
    #print(result)
    
    label=np.argmax(result,axis=1)[0]
  
    cv2.rectangle(im,(x,y),(x+w,y+h),color_dict[label],2)
    cv2.rectangle(im,y-40),-1)
    cv2.putText(im,labels_dict[label],y-10),cv2.FONT_HERShey_SIMPLEX,0.8,(255,255,255),2)

对于此代码,我如何从google colab读取我的网络摄像头,因此该代码在本地系统中有效

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)