1
파이썬을 사용하여 랩탑에 내장 된 웹캠에서 캡처 한 객체를 분류하려고합니다. 다음은 내가이 링크 http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/웹캠에서 객체를 파이썬으로 분류하는 방법
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()
나는이 수정 된 코드는 바보 보이는 경우 그렇게 용서 파이썬을 사용하여 이미지/객체를 분류하는 새로운 오전에서 수정 한 코드입니다.
나는 코드를 실행하고 내가 오류에 대한 검색을 시도했지만 어떤 답변을 찾을 수 있지 않습니다
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
같은 유형의 오류를 반환합니다.
제 질문은 웹캠에서 캡처 한 객체를 분류하는 방법입니다. 이 코드를 다시 작성하거나 오류를 해결할 수있는 방법에 대한 제안이 있으면 도움이 될 것입니다.
미리 감사드립니다.