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
您能否提供包括堆棧跟蹤在內的整個錯誤消息?據我可以看到你在代碼 –
中沒有使用名爲'startswith'的函數,我添加了錯誤消息@LPK –
這看起來很有趣......而且它似乎不是你的錯。我要檢查 –