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-79] Need robust alternative to Processing for viewing camera feed #675

Closed
aliphys opened this issue May 2, 2023 · 2 comments
Closed
Labels
bug Something isn't working Camera enhancement New feature or request GIGA nicla Portenta Video

Comments

@aliphys
Copy link
Contributor

aliphys commented May 2, 2023

Describe the problem

The Arduino + Processing sketch solution for streaming video from the Portenta Vision Shield, Nicla Vision and GIGA board is very unreliable. Problems include:

See @jacobhylen 's #673 (comment)

To reproduce

  1. Upload the CameraCaptureRawBytes.ino sketch.
  2. Using either Windows, Linux or macOSX run the CameraRawBytesVisualizer.pde Processing sketch
  3. If you are lucky enough, you will see a live feed of the camera. Using Windows will reduce your luck, due to how it handles I/O Portenta Vision Shield Camera demo not running #112 (comment).

Expected behaviour

Regardless of what Arduino board is connected, you should see a stable video feed.

Proposed Solutions

The current Arduino + Processing sketch is not fit for purpose. We need an alternative solution with the following four features:

  • Cross-platform
  • Resilient to errors
  • Simple to use, with minimal configuration by User
  • Light on CPU

Here are two different - yet complimentary - approaches to meet these needs

Approach 1: Barebones Arduino-Python script

The sketch will communicate at 9600 bps. This is very slow, and will have minimal demand on CPU resources ensuring that data is read in a timely manner from the serial port (arduino/arduino-ide#79). Of course, the resolution and frame per second will drop but as a test sketch this is fine to ensure maximum compatibility. The Serial.begin() method includes an option for defining a parity (based on the underlying mbed function), which should be utilised.

switch (config & SERIAL_PARITY_MASK) {
case SERIAL_PARITY_EVEN:
parity = mbed::SerialBase::Even;
break;
case SERIAL_PARITY_ODD:
parity = mbed::SerialBase::Odd;
break;
case SERIAL_PARITY_NONE:
parity = mbed::SerialBase::None;
break;
}

The packets from the Arduino board are then parsed by a Python script. This would make use of cross-compatible libraries for I/O.
The packet should also contain data specifying if the transmission is greyscale or RGB, so that the Python script can identify this. No OS specific routines should be avoided.

Approach 2: WebBLE Camera Dashboard

An alternative approach to send data from the camera to the PC (or any other compatible device) would be over WebBLE. We already have a successful implementation of this for the Nicla Sense ME (see @marqdevx 's tutorial here as well as @sebromero battery status indicator here). A single image would need to be split into smaller chunks, which are then reconstructed on the browser side. While support for WebBLE is limited mainly to Chrome, it is expected to grow. And it works across Windows, Linux and OSX without the need to defined a serial port. Device detection is intuitively done in the browser, where a human-readable name is assigned to the Arduino device.

(M)JPEG compression can allow for larger resolution/FPS together with some level of resilience to error. Native JPEG decompression algorithms is taken for granted in modern browsers. Note that WebBLE support is still experimental.

@aliphys aliphys added bug Something isn't working enhancement New feature or request Portenta Camera Video nicla GIGA labels May 2, 2023
@aliphys
Copy link
Contributor Author

aliphys commented May 12, 2023

Approach 3: WebSerial Dashboard

@facchinm mentioned WebSerial to transfer data from the Arduino Camera to the computer. WebSerial can be over USB or Bluetooth, so is communication-method agnostic. This overcomes the packet size limitations of WebBLE and can use native features in the browser to display the image data. A Github io page could host the page.

@aliphys
Copy link
Contributor Author

aliphys commented Jan 18, 2024

A robust alternative was developed by @sebromero in #822 which meets the requirements specified in this issue 🎉 :

  • Cross-platform -> Build upon WebSerial JS (Approach 3) and can run in Google Chrome in Windows, Linux and Mac.
  • Resilient to errors -> Instead of continuous data transfer (which is problematic in Windows, see: Portenta Vision Shield Camera demo not running #112 (comment)) defines sendChunk() and sendFrame() methods. Additionally, sendCameraConfig() sends the IMAGE_MODE based on the specified platform.
  • Simple to use, with minimal configuration by User -> Compiler directives are used to identify the platform. Manual configuration needs to be made by (un)commenting lines since single platforms may have different cameras. This is currently the best workaround, since automatic detection of the camera is not possible.
  • Light on CPU -> Runs stable on Mac and OK on Linux. Some stability issues on Windows, but more a limitation of the OS. Runs continuously on the Nicla Vision without crashing.

@aliphys aliphys closed this as completed Jan 18, 2024
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 enhancement New feature or request GIGA nicla Portenta Video
Projects
None yet
Development

No branches or pull requests

1 participant