how to decode by imdecode
Hi, there!
I'm using python cv2.
Explain me, please, why does this code (below) returns None (I.e. im == None
eventually) ?
# case 1
frame = np.random.uniform(0, 255, (768, 576, 3))
im = cv2.imdecode(frame, cv2.IMREAD_COLOR)
print(im) # None we see in output
# case 2
frame = np.random.uniform(0, 255, (768, 576))
im = cv2.imdecode(frame, cv2.IMREAD_UNCHANGED)
print(im) # output is None as well
# etc...
And show me the right way, please!
you seem to have no idea, what imdecode is about (or when it should be used)
Yes I do. I wanted to read binary data from file. When I use C++, it's rather easy - just create cv::Mat instance from data pointer. But I hadn't found the same in python wrapper. As I got from answer below the np.array is already the same as Mat object.
no, the input to imdecode is a (1d) byte array like a file on disc (including headers, compressed pixels, etc)
that's not the same as a numpy image in memory, which is, what you're trying above
I've just tried to read an image from a buffer in memory as is. Didn't need any coding like jpg etc. I guess, the closest description in docs is the: link textReads an image from a buffer in memory. (c) Thank you for explanation