I have a binary file that contains an encoding for an image in BGR8. I want to read this file and then convert it to a JPEG encoding in Python. I have the code that can transform a BGR8 encoding into a JPEG one, but I am having problems extracting this information from the file. This is my original code:
import cv2
import numpy as np
def convert(value):
return bytes(cv2.imencode('.jpg',value)[1])
with open("myfile",'rb') as reader:
value = reader.read()
print(type(value))
jpeg = convert(np.float32(value))
print("Converted")
I have to convert to float32 because the imencode function expects a UMat image. However, in this line I am getting the error:
<class 'bytes'>
ValueError: Could not convert string to float: b'<<3\x12\x12\t\x0b\x0e\x06\x0b\x0e\x06\x14\x12\x0f0.+974\x12\x10\r,,$<<4::2<<458.47-14,14,21,.-(01,\x1c\x1d\x18\x10\x13\r\n\r\x07\t\x0c\x06\x0b\x0e\x08\x11\x11\t\x14\x14\x0c01,UVQqm_^ZL%#\x1a\x18\x16\r\x14\x16\x12\x12\x14\x10\x15\x17\x13\x16\x18\x14\x14\x16\x12\x11\x13\x0f\x0c\x0f\t\x1a\x1d\x17951\x14\x10\x0c\x11\x11\x0e;;8DKEFMGGLF@E?CC@AA>??1\x08\n\x12\t\x08\x10\x07\x0c\x0f\x07\x0b\x0e\x06\n\x0e\x04\x08\x0c\x02\t\x0c\x06\t\x0c\x06\t\x0e\x08\x1c!\x1b=C:\r\x13\n\x10\x16\r\x08\x0e\x05\x00\x07\x01\x00\x07\x01\x00\x06\x02\x00\x05\x01\x00\x06\x00\x00\x07\x01\x00\x05\x003\x00\x00\x03\x00\x00\x03\x00\x00\x03\x00\x00\x03\x00\x00\x03\x00\x00\x03\x00\x00\x04\x00\x00\x03\x00\x00\x02\x00\x00\x04\x00\x00\x04\x00\x00\x04\x00\x00\x05\x00\x00\x06\x01\x00\x07\x02\x00\x06\x01\x00\x05\x00\x00\x05\x00\x00\x07\x02\x00\x07\x02\x00\x07\x02\x00\x0b\x06\x01\x0c\x07\x06\x12\x0f\x0c\x18\x15=OMj|zo{xp|yq|wq|wq|wp{v\x10\x14\x10\x12\x16\x12\x19\x1d\x19`d`ilbDG= "\x1a\x15\x17\x0f\\_^psrHNEHNE\x10\x13\r\x11\x14\x0e+*%IHC\x1f YMcZMb[Mb[Nc\\Mb[Nc\\Mb[LbYKaXLaZLaZNb[MaZNb[MaZLbYKaXK`YLaZL`YL`YM_WL^VK_XJ^WL`YL`YP`XP`XM^XN_YN`XN`XN`XL^VO_WN^VL^VL^VO^XO^XO_WN^VL]WM^XL]WL]WM_WL^VL^VL^VH\\UH\\UK\\VK\\VH\\TH\\TJ\\TJ\\TG[SG[SE[RE[RFZRFZREYQEYQDZQDZQE[RE[REYQEYQEYQEYQCYNBXMBXOCYP'
P.S: Only the beginning and the end of the binary are here, I removed large chunks of it to make the question readable.
I don't know what is going on here. I tried other methods of converting but it didn't work. Any ideas on what is the problem?