如何从pycam中的网络摄像头对对象进行分类
我想在我的笔记本电脑上使用python对从我的嵌入式摄像头捕获的对象进行分类。 下面是我从这个链接 http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/如何从pycam中的网络摄像头对对象进行分类
from keras.preprocessing import image as image_utils from imagenet_utils import decode_predictions
from imagenet_utils import preprocess_input
from squeezenet import squeeze
import numpy as np
import cv2
camera = cv2.VideoCapture(0)
while True:
ret, frame = camera.read()
print("[INFO] loading and preprocessing image...")
image = image_utils.load_img(camera)
image = image_utils.img_to_array(image)
image = np.expand_dims(image, axis=0)
image = preprocess_input(image)
print("[INFO] loading network...")
model = squeeze(weights = "imagenet")
#classify the image
print("[INFO] classifying image...")
preds = model.predict(image)
(inID, label) = decode_predictions(preds)[0]
print("ImageNet ID: {}, Label: {}".format(inID, label))
cv2.putText(orig, "Label: {}".format(label), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imshow("Classification", camera)
cv2.waitKey(0)
camera.release()
cv2.destroyAllWindows()
我在使用python如果这个修改后的代码看起来愚蠢所以请原谅我的图像/对象分类新修改的代码。
我运行的代码,它返回一个类型的错误这样
Using Theano backend. Using gpu device 0: GeForce 920MX (CNMeM is disabled, cuDNN 5005)
[INFO] loading and preprocessing image...
Traceback (most recent call last):
File "camdetect.py", line 13, in <module>
image = image_utils.load_img(camera)
File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 165, in load_img
img = Image.open(path)
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2285, in open
fp = io.BytesIO(fp.read())
TypeError: 'tuple' does not have the buffer interface
我试图寻找有关的错误,但没有找到任何答案。
我的问题是如何分类从网络摄像头捕获的对象?如果有任何关于如何重写此代码的建议,或者解决错误也会很好。
在此先感谢。
回答:
的错误在于在报道消息:
image = image_utils.load_img(camera)
的修复可能是:
# image = image_utils.load_img(camera) image = image_utils.img_to_array(frame)
以上是 如何从pycam中的网络摄像头对对象进行分类 的全部内容, 来源链接: utcz.com/qa/261465.html