我正在尝试对从image
中取出的frame
或webcam
进行编码,然后在解码时将其发送到服务器我收到此错误
我正在尝试使用以下代码进行编码和解码
import cv2
import cPickle
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
frame = cv2.imencode('.jpg', frame)
data = cPickle.dumps(frame)
res = cPickle.loads(data)
small_frame = cv2.imdecode(res,1)
print(res)
我在解码时遇到错误。我不知道如何解决它。 感谢
错误:
TypeError: buf is not a numerical tuple
答案 0 :(得分:1)
imencode
也会返回成功值。你正在挑选一个(retval, buf)
的元组。你实际上只想腌制buf:
ret, frame = cv2.imencode('.jpg', frame)
(还有一个建议:通过实际检查ret值来节省一些麻烦。)