python - 如何在 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 读取我的网络摄像头此代码在本地系统中工作
解决方案
推荐阅读
- python - 如何填补时间序列数据中缺失的观测值
- java - 如何在不使用 mockito 执行代码的情况下从方法返回值
- javascript - 在同一选项卡中打开的其他网站可访问的全局变量
- jquery - 如何从 Jquery Ajax 成功数据中更新选择选项
- java - 如何在 Android Studio 中除 MainActivity 之外的其他类中调试?
- reactjs - 状态存在但未发生函数错误。this.setState 不是函数
- java - 在黄瓜特征文件中并行运行场景,一次一个特征文件
- actions-on-google - 不能在不是使用自定义类别创建的项目中指定自定义操作
- android - 批准 Android 上的后台定位?
- pyspark - 如何遍历代码存储库中的 json 文件并增量附加到数据集