on-internet
← Community

Reading JPG colored image and saving image into raw or binary file using Python OpenCV

Stack Overflow ·

I am trying to read a JPG image and want to save it in binary raw image file. Output should be in planar form, like first Red channel and so on. This code I have made till now, but it is not working. Can you suggest me what should I do? import cv2 H = 512; W = 512; size = H*W; img = cv2.imread('f.jpg') img = cv2.resize(img, (H, W)) name = 'f'+str(H)+'x'+str(W)+'.bin' f = open(name, 'w+b') binary_format = bytearray(img) f.write(binary_format) f.close()

Comments

Sign in or sign up to comment and upvote.

No comments yet.