Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Size of image stream in opencv for Python

In Python 3.7 I read an png image with opencv and convert it to an jpg image stream. How can I determine the number of bytes of the stream?

image=cv2.imread('test.png',0)
image_stream = io.BytesIO(cv2.imencode(".jpg",image)[1].tobytes())

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(success, data) = cv2.imencode(".jpg", image)
assert success
print(data.nbytes)

This number of bytes is identical to the size of the bytes object returned by the .tobytes() call. Creating a BytesIO() also does not affect this size.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading