mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
ports/alif: Add 250ms time limited moving average.
The image turning green previously was caused by the rgb stats not being sampled continously (only every 100 frames) coupled with only happening on snapshot. As such, any algorithm causing the fps to slow down would lower the update freq. The new average solution ensures that the rgb average is smoothed over many frames and only keeps the last 250ms of history.
This commit is contained in:
parent
ac20050910
commit
6d927a91f9
@ -65,6 +65,8 @@
|
||||
#define OMV_CSI_CLK_TOLERANCE (500000)
|
||||
#endif
|
||||
|
||||
#define OMV_CSI_RGB_AVG_MAX_MS (250)
|
||||
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif
|
||||
@ -322,6 +324,12 @@ __weak int omv_csi_reset(omv_csi_t *csi, bool hard) {
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
#if defined(OMV_CSI_RGB_AVG_SIZE)
|
||||
// Setup AWB moving average.
|
||||
csi->awb_enabled = true;
|
||||
rgb_moving_average_init(&csi->rgb_avg, OMV_CSI_RGB_AVG_MAX_MS, OMV_CSI_RGB_AVG_SIZE, csi->rgb_avg_buf);
|
||||
#endif // defined(OMV_CSI_RGB_AVG_SIZE)
|
||||
|
||||
// Restore shutdown state on reset.
|
||||
if (!csi->power_on) {
|
||||
omv_csi_shutdown(csi, false);
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
#include "omv_gpu.h"
|
||||
#include "omv_i2c.h"
|
||||
#include "omv_csi.h"
|
||||
#include "average.h"
|
||||
#include "unaligned_memcpy.h"
|
||||
|
||||
// Bits missing from cpi.h
|
||||
@ -230,10 +231,7 @@ static uint32_t omv_csi_get_fb_offset(omv_csi_t *csi) {
|
||||
int alif_csi_snapshot(omv_csi_t *csi, image_t *dst_image, uint32_t flags) {
|
||||
CPI_Type *cpi = csi->base;
|
||||
framebuffer_t *fb = csi->fb;
|
||||
|
||||
vbuffer_t *buffer = NULL;
|
||||
static uint32_t frames = 0;
|
||||
static uint32_t r_stat, gb_stat, gr_stat, b_stat;
|
||||
|
||||
// Configure and re/start the capture if it's not alrady active
|
||||
// and there are no pending buffers (from non-blocking capture).
|
||||
@ -390,13 +388,23 @@ int alif_csi_snapshot(omv_csi_t *csi, image_t *dst_image, uint32_t flags) {
|
||||
// Set the target pixel format before debayer.
|
||||
dst_image->pixfmt = fb->pixfmt;
|
||||
|
||||
// Update AWB stats every n frames.
|
||||
if ((frames++ % 100) == 0) {
|
||||
omv_csi_ioctl(csi, OMV_CSI_IOCTL_GET_RGB_STATS, &r_stat, &gb_stat, &gr_stat, &b_stat);
|
||||
uint32_t r_stat, g_stat, b_stat;
|
||||
if (csi->awb_enabled) {
|
||||
uint32_t gb_stat, gr_stat;
|
||||
int ret = omv_csi_ioctl(csi, OMV_CSI_IOCTL_GET_RGB_STATS, &r_stat, &gb_stat, &gr_stat, &b_stat);
|
||||
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_stat = (gb_stat + gr_stat) / 2;
|
||||
rgb_moving_average_update(&csi->rgb_avg, &r_stat, &g_stat, &b_stat, mp_hal_ticks_ms());
|
||||
} else {
|
||||
rgb_moving_average_get(&csi->rgb_avg, &r_stat, &g_stat, &b_stat);
|
||||
}
|
||||
|
||||
// Debayer frame.
|
||||
imlib_debayer_image_awb(dst_image, &src_image, false, r_stat, (gb_stat + gr_stat) / 2, b_stat);
|
||||
imlib_debayer_image_awb(dst_image, &src_image, false, r_stat, g_stat, b_stat);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#define __OMV_PORTCONFIG_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "average.h"
|
||||
#include "clk.h"
|
||||
#include "i2c.h"
|
||||
#include "i3c.h"
|
||||
@ -137,9 +138,14 @@ struct { \
|
||||
uint8_t datasize; \
|
||||
};
|
||||
|
||||
#define OMV_CSI_PORT_BITS \
|
||||
struct { \
|
||||
CPI_Type *base; \
|
||||
#define OMV_CSI_RGB_AVG_SIZE (60)
|
||||
|
||||
#define OMV_CSI_PORT_BITS \
|
||||
struct { \
|
||||
CPI_Type *base; \
|
||||
bool awb_enabled; \
|
||||
rgb_moving_average_t rgb_avg; \
|
||||
rgb_moving_average_val_t rgb_avg_buf[OMV_CSI_RGB_AVG_SIZE]; \
|
||||
};
|
||||
|
||||
#endif // __OMV_PORTCONFIG_H__
|
||||
|
||||
Loading…
Reference in New Issue
Block a user