I’m using the OV7725 based on version 4.4.2. I noticed that night mode is enabled by default. When I tried to manually disable it (code provided below), I call this function relatively frequently in my code due to switching image resolutions. During one of these resolution switches, the image became misaligned—specifically, a portion of the right side of the image shifted to the far left. This error disappeared after switching resolutions again. The issue is not frequent, occurring roughly 1 out of 100 times. Can you explain why this might happen?
Hi, when you change the camera register settings, it may output an incorrect frame. Our driver aborts the DMA transactions, apply the register settings, and then waits some amount of settling time before starting DMA up again.
If you are changing setting manually that control how the camera outputs data you need to follow the above steps. Aborting the DMA system is not exposed in the python API however, but, you can cause this to happen by switching to a different resolution/pixformat and then back.
thks your anwser
- Below is the code I use to manually modify the night mode, along with the corresponding Python code. During operation, I switch the camera resolution between QVGA and VGA depending on the situation. Please check if there are any issues with this implementation.
- If I don’t call
sensor.set_night_mode(False)
every time, but instead modify the default parameters indefault_regs[][2]
, will this resolve the image misalignment issue?{COM5, 0x75}, // 0x75: night mode is false, 0xf5: night mode is true
my code now:
static int set_night_mode(sensor_t *sensor, int enable){
int ret = 0;
uint8_t reg;
ret |= cambus_readb(&sensor->bus, sensor->slv_addr, COM5, ®);
ret |= cambus_writeb(&sensor->bus, sensor->slv_addr, COM5, COM5_SET_AFR(reg, (enable != 0)));
if (enable == 0) {
ret |= cambus_readb(&sensor->bus, sensor->slv_addr, ADVFL, 0);
ret |= cambus_readb(&sensor->bus, sensor->slv_addr, ADVFH, 0);
}
//cambus_readb(&sensor->bus, sensor->slv_addr, COM5, ®);
//printf(“set night mode: %d\n”, reg);
return ret;
}
def initCameraWithMarkerDet(self, status = State.MarkerDet):
sensor.sleep(False)
if status == State.MarkerDet:
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # we run out of memory if the resolution is much bigger...
else:
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA) # we run out of memory if the resolution is much bigger...
sensor.set_windowing((marker_window_size, marker_window_size))
sensor.set_hmirror(is_camera_inverted) # 图像翻转
sensor.set_vflip(is_camera_inverted)
sensor.set_night_mode(False)
#sensor.set_framerate(30)
#sensor.skip_frames(time = 100)
if status == State.MarkerDet:
self.tag_families = 0
self.tag_families |= marker.MarkerType.Small
self.tag_families |= marker.MarkerType.Big
else:
self.tag_families = 0
self.tag_families |= marker.MarkerType.Big
Hi, you just need to stop the DMA system and restart it. Calling set_pixformat/framesize to do this. Then make your changes, wait 100ms or so, then call snapshot() again.
this is right?
def initCameraWithMarkerDet(self, status = State.MarkerDet):
sensor.sleep(False)
if status == State.MarkerDet:
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # we run out of memory if the resolution is much bigger...
else:
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA) # we run out of memory if the resolution is much bigger...
sensor.set_windowing((marker_window_size, marker_window_size))
sensor.skip_frames(time = 100)
sensor.set_hmirror(is_camera_inverted) # 图像翻转
sensor.set_vflip(is_camera_inverted)
sensor.set_night_mode(False)
#sensor.set_framerate(30)
if status == State.MarkerDet:
self.tag_families = 0
self.tag_families |= marker.MarkerType.Small
self.tag_families |= marker.MarkerType.Big
else:
self.tag_families = 0
self.tag_families |= marker.MarkerType.Big
The same camera and version, as well as the camera initialization code, have another issue. In 100 runs, this problem occurred 3 times: the image frequently alternates between very bright and very dark throughout the process. I am not sure if this issue is related to the one mentioned above. I had rarely encountered these problems before, but they started occurring after I began manually disabling the night mode.
Hi, skip frames after you change the camera settings.
Is there a reason you are disabling night mode? The feature exposes frames for longer than normal to handle dark scenes. It only has an impact on the frame rate changing around.
I use it on a drone. In night mode, the exposure time is too long at night, which causes the image to blur and makes it impossible to effectively detect AprilTags. Although turning off night mode makes the image darker, it allows for successful detection.
Please tell me, what is the best way to disable night mode? Is it the best option to turn it off in the initialization parameter list?
Hi, Illray; I don’t know what would be causing the very bright and dark alternating frames. This seems unrelated to night mode. If it is, I don’t know what the fix for it would be. You may need to dive into the OV7725 datasheet and try to figure things out yourself. Note that we stopped producing the OV7725 years ago. You may wish to upgrade to the OV5640.