我在开车后,在我重新开车后,突然使用我的cam。
[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (802) open VIDEOIO ERROR: V4L: can t open camera by index 0
Traceback (most recent call last):
File "test.py", line 20, in <module>
retval, buffer_img = cv2.imencode( .jpg , frame)
cv2.error: OpenCV(4.1.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:877: error: (-215:Assertion failed) !image.empty() in function imencode
cap = cv2.VideoCapture(0) # here it throws an error
import json
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
retval, buffer_img = cv2.imencode( .jpg , frame)
resdata = base64.b64encode(buffer_img)
resdata = "data:image/png;base64,"+ str(resdata.decode("utf-8"))
PARAMS = { image : resdata}
# Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow( frame ,frame)
if cv2.waitKey(1) & 0xFF == ord( q ):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
我也尝试了cap = cv2.VideoCapture(1)
,但显示可以发现照相机。
我如何解决这一问题?