首页 > 解决方案 > 如何在 google colab it 中访问网络摄像头以获取以下代码

问题描述

错误:'NoneType' 对象没有属性'shape' 我曾尝试使用 webcam.read() 访问网络摄像头,但它返回 false,在 jupyter notebook 中同样有效,但我希望它像我们一样在 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,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,(x,y-40),(x+w,y),color_dict[label],-1)
    cv2.putText(im, labels_dict[label], (x, y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)

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

标签: pythongoogle-colaboratory

解决方案


推荐阅读