Skip to content

Commit

Permalink
fix(Examples): Fix ImgCapture RGB888 Conversions (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Carter authored Aug 16, 2023
1 parent 651393a commit 4bb6d3a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Examples/MAX78000/CameraIF/pc_utility/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78000/CameraIF_Debayer/pc_utility/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
8 changes: 5 additions & 3 deletions Examples/MAX78000/ImgCapture/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ img_data_t capture_img(uint32_t w, uint32_t h, pixformat_t pixel_format, dmamode
// camera.h drivers will allocate an SRAM buffer whose size is equal to
// width * height * bytes_per_pixel. See camera.c for implementation details.
printf("Configuring camera\n");
fifomode_t fifo_mode = (pixel_format == PIXFORMAT_RGB888) ? FIFO_THREE_BYTE : FIFO_FOUR_BYTE;
int ret = camera_setup(w, // width
h, // height
pixel_format, // pixel format
FIFO_FOUR_BYTE, // FIFO mode (four bytes is suitable for most cases)
fifo_mode, // FIFO mode (four bytes is suitable for most cases)
dma_mode, // DMA (enabling DMA will drastically decrease capture time)
dma_channel); // Allocate the DMA channel retrieved in initialization

Expand Down Expand Up @@ -239,10 +240,11 @@ cnn_img_data_t stream_img(uint32_t w, uint32_t h, pixformat_t pixel_format, int
// 1. Configure the camera. This is the same as the standard blocking capture, except
// the DMA mode is set to "STREAMING_DMA".
printf("Configuring camera\n");
fifomode_t fifo_mode = (pixel_format == PIXFORMAT_RGB888) ? FIFO_THREE_BYTE : FIFO_FOUR_BYTE;
int ret = camera_setup(w, // width
h, // height
pixel_format, // pixel format
FIFO_FOUR_BYTE, // FIFO mode
fifo_mode, // FIFO mode
STREAMING_DMA, // Set streaming mode
dma_channel); // Allocate the DMA channel retrieved in initialization

Expand Down Expand Up @@ -621,7 +623,7 @@ int main(void)
g_app_settings.dma_mode = USE_DMA;
g_app_settings.imgres_w = IMAGE_XRES;
g_app_settings.imgres_h = IMAGE_YRES;
g_app_settings.pixel_format = PIXFORMAT_RGB565; // This default may change during initialization
g_app_settings.pixel_format = PIXFORMAT_RGB888; // This default may change during initialization

#if defined(CAMERA_MONO)
g_app_settings.pixel_format = PIXFORMAT_BAYER;
Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78000/ImgCapture/utils/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78002/CSI2/utils/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78002/CameraIF/pc_utility/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78002/CameraIF_Debayer/pc_utility/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down
6 changes: 4 additions & 2 deletions Examples/MAX78002/ImgCapture/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ img_data_t capture_img(uint32_t w, uint32_t h, pixformat_t pixel_format, dmamode
// camera.h drivers will allocate an SRAM buffer whose size is equal to
// width * height * bytes_per_pixel. See camera.c for implementation details.
printf("Configuring camera\n");
fifomode_t fifo_mode = (pixel_format == PIXFORMAT_RGB888) ? FIFO_THREE_BYTE : FIFO_FOUR_BYTE;
int ret = camera_setup(w, // width
h, // height
pixel_format, // pixel format
FIFO_FOUR_BYTE, // FIFO mode (four bytes is suitable for most cases)
fifo_mode, // FIFO mode (four bytes is suitable for most cases)
dma_mode, // DMA (enabling DMA will drastically decrease capture time)
dma_channel); // Allocate the DMA channel retrieved in initialization

Expand Down Expand Up @@ -244,10 +245,11 @@ cnn_img_data_t stream_img(uint32_t w, uint32_t h, pixformat_t pixel_format, int
// 1. Configure the camera. This is the same as the standard blocking capture, except
// the DMA mode is set to "STREAMING_DMA".
printf("Configuring camera\n");
fifomode_t fifo_mode = (pixel_format == PIXFORMAT_RGB888) ? FIFO_THREE_BYTE : FIFO_FOUR_BYTE;
int ret = camera_setup(w, // width
h, // height
pixel_format, // pixel format
FIFO_FOUR_BYTE, // FIFO mode
fifo_mode, // FIFO mode
STREAMING_DMA, // Set streaming mode
dma_channel); // Allocate the DMA channel retrieved in initialization

Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78002/ImgCapture/utils/imgConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def yuv422_to_blackAndWhite(bytesequence):

def rgb888_to_rgb(bytesequence):
img = []
for i in range(len(bytesequence) // 3):
offset = i * 3
for i in range(len(bytesequence) // 4):
offset = i * 4
byte1 = bytesequence[offset + 0]
byte2 = bytesequence[offset + 1]
byte3 = bytesequence[offset + 2]
Expand Down

0 comments on commit 4bb6d3a

Please sign in to comment.