I've got a bytestring from my camera and I'd like to show the frame with OpenCV WITHOUT saving it (saving time). I've checked this question: Python OpenCV load image from byte string but I get an error failed to import cv from cv2
.
print(frame): b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\...
My code (in a loop ofc):
frame = # need to convert bytestring for imshow()
cv2.imshow('image', frame)
cv2.waitKey(1)
Also, the code worked if I just saved it as a file, then loaded it with cv2.imread(..), but the best would be to skip filesave and load.
So this doesn't work anymore, as cv was removed from OpenCV3.
nparr = np.fromstring(frame, np.uint8)
img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
img_ipl = cv.CreateImageHeader((img_np.shape[1], img_np.shape[0]), cv.IPL_DEPTH_8U, 3)
cv.SetData(img_ipl, img_np.tostring(), img_np.dtype.itemsize * 3 * img_np.shape[1])
cv2.imshow('image', img_ipl)
cv2.waitKey(1)
How can then pass the bytestring without creating a temporary file?