2016-07-01 32 views
0

我剛裝了3(使用this教程)OpenCV中,我發現這個代碼應與我的版本的OpenCV和python(3)工作:Python的錯誤開始在我的樹莓派2 B型OpenCV的

from picamera.array import PiRGBArray 
from picamera import PiCamera 
import time 
import cv2 

# initialize the camera and grab a reference to the raw camera capture 
camera = PiCamera() 
rawCapture = PiRGBArray(camera) 

# allow the camera to warmup 
time.sleep(0.1) 

# grab an image from the camera 
camera.capture(rawCapture, format="bgr") 
image = rawCapture.array 

# display the image on screen and wait for a keypress 
cv2.imshow("Image", image) 
cv2.waitKey(0) 

但我對camera.capture()行收到此錯誤

TypeError: startswith first arg must be bytes or a tuple of bytes, not str

我已經搜索了具有相同錯誤的答案,但我找不到解決方案或處於相同情況的人。我已經確認piCamera正在工作,並且我已經正確安裝了OpenCV。是什麼賦予了?

以下是完整的錯誤消息:

Traceback (most recent call last): 
    File "test_image.py", line 14, in <module> 
    camera.capture(rawCapture, format="bgr") 
    File "/home/pi/.virtualenvs/cv/lib/python3.4/site-packages/picamera/camera.py", line 1371, in capture 
    camera_port, output_port, format, resize, **options) 
    File "/home/pi/.virtualenvs/cv/lib/python3.4/site-packages/picamera/camera.py", line 652, in _get_image_encoder 
    self, camera_port, output_port, format, resize, **options) 
    File "/home/pi/.virtualenvs/cv/lib/python3.4/site-packages/picamera/encoders.py", line 1049, in __init__ 
parent, camera_port, input_port, format, resize, **options) 
    File "/home/pi/.virtualenvs/cv/lib/python3.4/site-packages/picamera/encoders.py", line 534, in __init__ 
    if not resize and format != 'yuv' and input_port.name.startswith('vc.ril.video_splitter'): 
TypeError: startswith first arg must be bytes or a tuple of bytes, not str 
+0

您能否提供包括堆棧跟蹤在內的整個錯誤消息?據我可以看到你在代碼 –

+0

中沒有使用名爲'startswith'的函數,我添加了錯誤消息@LPK –

+0

這看起來很有趣......而且它似乎不是你的錯。我要檢查 –

回答

0

我有同樣的問題。基於this answer,它在picamera/encoders.py中似乎是一個錯誤。在將picamera/encoders.py的第534行的末尾編輯爲:... .startswith(b'vc.ril.video_splitter')後,我能夠獲取圖像。 b告訴開始將字符串視爲字節文字。