Hello everyone,
I used a F767 Nucleo board and a OV7725 module connecting with jump wires to do my research, but the quality of image was awful, too much interference, so I switch to OpenMV3 M7 board now.
Instead of re-writing code in micropython, I prefer to continue writing my undone C code, so I reference the OpenMV schematic and use CubeMX to re-create my project, and compiling the baremetal firmware myself.
My research need the pure image data without doing color calibration and image compression, so I let OV7725 send RAW RGB data back, and I de-bayer them myself, to see if the captured image is OK.
The image quality is better than before, but the image has noise between different color, like the picture below.
Here is the same scene taken by my phone.
I loaded stock firmware back to OpenMV and used OpenMV IDE to check captured image, found out the image was fine.
In order to solving this problem, I checked the source code of OpenMV firwmware, and tried to make OV7725 configuration of my own project be close to OV7725 configuration of OpenMV. No luck happened.
I start to think maybe it’s my de-bayer function going wrong, so I load OpenMV stock firmware back, and run the following python code on OpenMV:
import sensor, image, time, pyb
sensor.reset()
sensor.set_pixformat(sensor.BAYER)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
img = sensor.snapshot()
print('')
for i in range(img.height()):
a = []
for j in range(img.width()):
a.append(img.get_pixel(j, i))
print(a)
print("**END**")
while(True):
pass
Then I manually copy the printed RAW RGB data as input of my de-bayer function.
The function I already compare it with the macro COLOR_BAYER_TO_RGB565 in the file omv/img/imlib.h of source code, and did some modification, they are almost the same.
void bayer2rgb(char *imgbuf, char *rawbuf, int nr, int nc)
{
int i, j, R, G, B, index;
for (i = 0; i<nr; i++)
{
for (j = 0; j<nc; j++)
{
#define IDX(r,c) ((r)*nc+(c))
if (i % 2 == 0 && j % 2 == 0)
{
R = (rawbuf[IDX(i - 1, j - 1)] + rawbuf[IDX(i - 1, j + 1)] + rawbuf[IDX(i + 1, j - 1)] + rawbuf[IDX(i + 1, j + 1)]) / 4;
G = (rawbuf[IDX(i, j - 1)] + rawbuf[IDX(i, j + 1)] + rawbuf[IDX(i - 1, j)] + rawbuf[IDX(i + 1, j)]) / 4;
B = rawbuf[IDX(i, j)];
}
else if (i % 2 == 1 && j % 2 == 1)
{
R = rawbuf[IDX(i, j)];
G = (rawbuf[IDX(i, j - 1)] + rawbuf[IDX(i, j + 1)] + rawbuf[IDX(i - 1, j)] + rawbuf[IDX(i + 1, j)]) / 4;
B = (rawbuf[IDX(i - 1, j - 1)] + rawbuf[IDX(i - 1, j + 1)] + rawbuf[IDX(i + 1, j - 1)] + rawbuf[IDX(i + 1, j + 1)]) / 4;
}
else if (i % 2 == 1 && j % 2 == 0)
{
R = (rawbuf[IDX(i, j - 1)] + rawbuf[IDX(i, j + 1)]) / 2;
G = rawbuf[IDX(i, j)];
B = (rawbuf[IDX(i - 1, j)] + rawbuf[IDX(i + 1, j)]) / 2;
}
else if (i % 2 == 0 && j % 2 == 1)
{
R = (rawbuf[IDX(i - 1, j)] + rawbuf[IDX(i + 1, j)]) / 2;
B = (rawbuf[IDX(i, j - 1)] + rawbuf[IDX(i, j + 1)]) / 2;
G = rawbuf[IDX(i, j)];
}
#undef IDX
index = (i * nc + j) * 3;
imgbuf[index] = R;
imgbuf[index + 1] = G;
imgbuf[index + 2] = B;
}
}
}
The image generated by this de-bayer function also has the same problem.
I think the possible problem maybe is in my de-bayer function, or the OpenMV firmware just like my own firmware, cannot setup properly for RAW RGB format neither.
I can’t find out possible solution furthermore, so I hope I can get some help here, thanks.