Ask Your Question

Revision history [back]

an example

import numpy as np
import cv2 as cv


frame=np.zeros((32,32,3), np.uint8)
frame[16,0:31,:]=255
ret,buf=cv.imencode("toto.jpg",frame)
bufjpg = bytearray(buf)
fs = open("toto.jpg", "wb")
fs.write(bufjpg)
print (buf[0:5])
img=cv.imdecode(buf,cv.IMREAD_COLOR)
cv.imshow("img",img)
cv.waitKey(0)

encode is to convert a Mat in an jpg buffer (example). you can write buffer to disk an open this file in jpg. You can decode this buffer (imdecode) and display on screen

an example

import numpy as np
import cv2 as cv


frame=np.zeros((32,32,3), np.uint8)
frame[16,0:31,:]=255
ret,buf=cv.imencode("toto.jpg",frame)
bufjpg = bytearray(buf)
fs = open("toto.jpg", "wb")
fs.write(bufjpg)
print (buf[0:5])
img=cv.imdecode(buf,cv.IMREAD_COLOR)
cv.imshow("img",img)
cv.waitKey(0)

encode is to convert a Mat in an jpg buffer (example). you can write buffer to disk an open this file in jpg. You can decode this buffer (imdecode) and display on screen

In your example frame is a set of pixel and it is already decode

an example

import numpy as np
import cv2 as cv


frame=np.zeros((32,32,3), np.uint8)
frame[16,0:31,:]=255
ret,buf=cv.imencode("toto.jpg",frame)
bufjpg = bytearray(buf)
fs = open("toto.jpg", "wb")
fs.write(bufjpg)
print (buf[0:5])
(buf[0:15].tostring())
img=cv.imdecode(buf,cv.IMREAD_COLOR)
cv.imshow("img",img)
cv.waitKey(0)

encode is to convert a Mat in an jpg buffer (example). you can write buffer to disk an open this file in jpg. You can decode this buffer (imdecode) and display on screen

In your example frame is a set of pixel and it is already decode