python - How to save jpeg data that is identical to the original jpeg file using OpenCV -


i'm using opencv , python. have loaded jpeg image numpy array. want save jpeg format, since image not modified, don't want compress again. possible create jpeg numpy array identical jpeg loaded from?

i know workflow (decode-encode without doing anything) sounds bit stupid, keeping original jpeg data not option. i'm interested if possible recreate original jpeg using data @ hand.

the question different reading .jpg image , saving without file size change, don't modify in picture. want restore original jpeg file based on data @ hand. assume 1 bypass compression steps (the compression artifacts in data) , write file in jpeg format. question is, if possible opencv.

clarified answer, following comment below:

what makes no sense @ all; have raw, unmodified, rgb data. no don't. have uncompressed data has been reconstructed compressed jpeg file.

the jpeg standards specify how un-compress image / video. there nothing in standard how compression, original image data have been compressed 1 of zillion different ways. have no way of knowing decoding steps required recreate data, cannot reverse them.

image this.

"i have number, 44, please tell me how can original numbers came from"

this is, essentially, asking.

the way can want (other copy original file) read image array before loading opencv. if want save it, write raw array file, this:

fi = 'c:\\path\\to\\image.jpg' fo = 'c:\\path\\to\\copy_image.jpg' open(fi,'rb') myfile:     im_array = np.array(myfile.read())  # stuff here  image = cv2.imdecode(im_array)  # more stuff here  open(fo,'wb') myfile:     myfile.write(im_array) 

of course, means have data stored twice, effectively, in memory, seems me option.

sometimes, no matter how hard want something, have accept cannot done.


Comments