Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AE-49] Colour mode mismatch between CameraCaptureRawBytes.ino and CameraRawBytesVisualizer.pde #662

Open
aliphys opened this issue Apr 13, 2023 · 3 comments
Labels
bug Something isn't working Camera nicla Video

Comments

@aliphys
Copy link
Contributor

aliphys commented Apr 13, 2023

Problem

😞 This is what happens when useGreyScale is set to true for the Nicla Vision:
image
😄 This is what is observed, when userGreyScale is set to false for the Nicla Vision
image

This creates three problems:

  • The header comment and code in CameraRawBytesVisualizer conflict in what the default colour mode is
  • From a UX perspective (cc @sebromero ) the User can face additional hurdles in testing out a basic function (e.g this forum post)
  • There is no clear pathway for users to realise the problem, upon seeing the corrupt image.

Details

The CameraCaptureRawBytes sketch is used to send a video stream over Serial to the computer. Which can then be displayed with the CameraRawBytesVisualizer Processing sketch.

A series of pre-directives, configures the IMAGE_MODE to be either CAMERA_RGB (Nicla Vision and GIGA boards) or CAMERA-GREYSCALE (Portenta H7 family).

#ifdef ARDUINO_NICLA_VISION
#include "gc2145.h"
GC2145 galaxyCore;
Camera cam(galaxyCore);
#define IMAGE_MODE CAMERA_RGB565
#elif defined(ARDUINO_PORTENTA_H7_M7)
#include "hm0360.h"
HM0360 himax;
Camera cam(himax);
#define IMAGE_MODE CAMERA_GRAYSCALE
#elif defined(ARDUINO_GIGA)
#include "ov767x.h"
// uncomment the correct camera in use
OV7670 ov767x;
// OV7675 ov767x;
Camera cam(ov767x);
#define IMAGE_MODE CAMERA_RGB565

In the default configuration, the accompanying CameraRawBytesVisualizer sketch is configured to be compatible with CAMERA_GREYSCLE, even though the header comment states that the Processing sketch is for RGB.

/*
This sketch reads a raw Stream of RGB565 pixels
from the Serial port and displays the frame on
the window.
Use with the Examples -> CameraCaptureRawBytes Arduino sketch.
This example code is in the public domain.
*/

// Must match the image mode in the Arduino sketch
final boolean useGrayScale = true;


Thanks @marqdevx , @Hannes7eicher and @jacobhylen for letting me pick your brains 🧠

@aliphys aliphys changed the title Mismatch between CameraCaptureRawBytes and CameraRawBytesVisualizer [AE-49] Mismatch between CameraCaptureRawBytes and CameraRawBytesVisualizer Apr 13, 2023
@aliphys aliphys added bug Something isn't working Camera Video nicla labels Apr 13, 2023
@aliphys aliphys changed the title [AE-49] Mismatch between CameraCaptureRawBytes and CameraRawBytesVisualizer [AE-49] Colour mode mismatch between CameraCaptureRawBytes.ino and CameraRawBytesVisualizer.pde Apr 13, 2023
@aliphys
Copy link
Contributor Author

aliphys commented Apr 13, 2023

Replicated issue on Arduino GIGA R1 WiFi with OV7675 cc @karlsoderby

useGrayScale set to false
image

useGreyScale set to true
image

@aliphys
Copy link
Contributor Author

aliphys commented Apr 27, 2023

Possible solution: Use keyPressed() method in Processing to switch the boolean value for useGrayScale.

Something like:

void keyPressed() {
  if (key == ' ') {
    useGrayScale = !useGrayScale;
  }
}

This does not require the user to change the useGrayScale variable manually, and can be switched without restarting the Processing sketch. -> Smoother user experience and less room for error

@rneurink
Copy link

See case CAMERA_GRAYSCALE:, it is commented out and currently GRAYSCALE sets to camera to use a bayer output. This is why the grayscale image looks really weird. If you uncomment these lines you can get it to work.

int GC2145::setPixelFormat(int32_t pixformat)
{
int ret = 0;
uint8_t reg;
// P0 regs
ret |= regWrite(GC2145_I2C_ADDR, 0xFE, 0x00);
// Read current output format reg
reg = regRead(GC2145_I2C_ADDR, REG_OUTPUT_FMT);
switch (pixformat) {
case CAMERA_RGB565:
ret |= regWrite(GC2145_I2C_ADDR,
REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_RGB565));
break;
case CAMERA_GRAYSCALE:
// TODO: There's no support for extracting GS from YUV so we use Bayer for 1BPP for now.
//ret |= regWrite(GC2145_I2C_ADDR,
// REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_YCBYCR));
//break;
case CAMERA_BAYER:
// There's no BAYER support so it will just look off.
// Make sure odd/even row are switched to work with our bayer conversion.
ret |= regWrite(GC2145_I2C_ADDR,
REG_SYNC_MODE, REG_SYNC_MODE_DEF | REG_SYNC_MODE_ROW_SWITCH);
ret |= regWrite(GC2145_I2C_ADDR,
REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_BAYER));
break;
default:
return -1;
}
return ret;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Camera nicla Video
Projects
None yet
Development

No branches or pull requests

2 participants