Closed hpssjellis closed 3 years ago
I had the same issue trying the read the raw bytes in python. I fixed it by swapping the bytes of the int16 pixel (Big-endian to little-endian).
Here's the python code I used which takes from the pde file included on this github:
from matplotlib import pyplot as plt
import numpy as np
import struct
raw_bytes = np.array([
#copy image bytes here in this format (0x9EF7, 0xFCD6...)
], dtype="i2")
image = np.zeros((len(raw_bytes),3), dtype=int)
for i in range(len(raw_bytes)):
#read 16-bit pixel
pixel = struct.unpack('>h', raw_bytes[i])[0] #unpack will switch the endianness
#convert RGB565 to RGB 24-bit
r = ((pixel >> 11) & 0x1f) << 3;
g = ((pixel >> 5) & 0x3f) << 2;
b = ((pixel >> 0) & 0x1f) << 3;
image[i] = [r,g,b]
image = np.reshape(image,(120, 160,3))
plt.imshow(image)
plt.show()
In C you should be able to swap struct.unpack for something like pixel = (raw_bytes[i]>>8) | (raw_bytes[i]<<8);
@colbybanbury Thanks so much, that makes sense now why everything I tried didn't seem to improve anything.
Only took a few minutes to solve my issue. pixel = (raw_bytes[i]>>8) | (raw_bytes[i]<<8);
was the solution. The image is cropped to 80x80 and I think the camera is a bit out of focus.
Thanks so much.
Glad I could help!
Many machine learning programs expect RGB888 image format, wondering if a function that does that could be included in this library
I am loading my images to EdgeImpulse and using this conversion
I get an image like this. Note the image has already been cropped to 48x48 so the it will look grainy.
which becomes slightly better with this conversion
Any suggestions on how to better convert the OV7670 RGB565 output?