2016-09-13 7 views
1

私は、自分のノートパソコンに埋め込まれたウェブカメラからキャプチャしたオブジェクトをpythonを使って分類しようとしています。 以下は、私がこのリンク http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/Pythonでウェブカメラのオブジェクトを分類する方法

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 

のようなタイプのエラーを返す私は、エラーについての検索を試みたが、すべての答えを見つけることができませんでした。

私の質問は、ウェブカメラからキャプチャしたオブジェクトを分類する方法ですか?どのように私はこのコードを書き換えることができますか、多分エラーを解決するための良い提案もあります。

ありがとうございます。

答えて

0

エラーが報告されたメッセージのようにある:

image = image_utils.load_img(camera) 

修正は次のようになります。

# image = image_utils.load_img(camera) 
image = image_utils.img_to_array(frame) 
関連する問題