Camera Module – Color Detector

Color Picker 400
Description

This module process live video stream and detects colors as per the selected settings:

  1. Camera Preview
  2. Grid Size
  3. Number of Color Bits
  4. Color Mode 
  5. Color Detection Method
  6. Flash Control
Available in

Camera Module

The Camera module allows you to use your mobile camera for different activities like recording videos, capturing images, color detection, and face detection. Depending on the type of activities you want to do with your mobile camera the module is further divided into four modules each capable of executing a specific activity.

Camera Module

These modules are:

  1. Camera and Videos
  2. Color Detector
  3. Line Follower (Coming Soon)
  4. Face Detector (Coming Soon)

Color Detector module

This module process live video stream and detects colors as per the selected settings.

Color Picker 1x1

There are various settings available.

Camera Preview

To visualize whether the Smartphone’s camera is positioned correctly, use this feature for toggling between the video stream and colors detected. You can toggle between them with the help of preview icon present above flash icon on your screen.

Color Picker 1x1 Photo

Grid Size

The video stream will be divided into the grid and each grid cell will result in one color.  Available grid size:

  1. 1×1 (single cell)
  2. 3×3 (9 cells)
  3. 5×5 (25 cells).

Number of color bits

To easily handle the total number of distinct colors resulted after processing, you can select the resolution by setting the bit size. For e.g., in grayscale mode, set bit size of 1 to classify colors as white or black, and in colored mode, set bit size of 3 to classify a color between 8 colors (because red, green and blue can either be present or not, then there are 8 possible combinations). The bit size defines the number of color levels in which any image color will be classified.

The image below shows a 3×3 grid setting with 15-bit color settings.

Color Picker 5x5

Color Mode

Colored or Grayscale. In the colored mode, each cell will result in three values for Red, Green, and Blue. In the grayscale mode, one value of gray level will be transmitted for Red, Green and Blue components. Value range (8-bit value for each color): max 255 and min 0.

Below image shows a 3×3 grid in grayscale color mode.

Color Picker 3x3

Color detection method

Dominant or Average. In the dominant method, color detection will find the most dominant color present in each cell. It helps in projects where there is continuous change between colors. In the average method, it averages the color of each pixel in the cell.

Flash on/off

As per the availability of light, you can choose flash to be on or off. Note: avoid reflecting surfaces in flash on mode.

You can control settings of the grid, color mode, the number of bits for color detection and color calculation mode from the user interface present in the module and also from commands sent through hardware.

Arduino IDE Functions

Header

To include the Camera and Video module in the Arduino program, you have to include the following header:

#define CUSTOM_SETTINGS
#define INCLUDE_CAMERA_MODULE

After defining the above mention headers, you have to include the dabble library:

#include <Dabble.h>

You can download the zip of Arduino Library for

  1. evive, Uno, Mega, and Nano – Dabble-Arduino 
  2. ESP32 – Dabble-ESP32

depending on the board you are using.

Enabling Bluetooth Communication

To enable Bluetooth communication, you have to initialize serial communication using the following code:

  1. For evive and Arduino Mega, Uno and Nano
    Dabble.begin(Baud_Rate);

    Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.

  2. For ESP32
    Dabble.begin("Bluetooth_Name");

    In place of Bluetooth_Name  enter name that you want to keep for Bluetooth of ESP32. Default name given in the library is “MyEsp32”. 

Refreshing the data

To refresh the data that the device has got from the mobile app, you have to use the following line of code:

Dabble.processInput();

Functions

Following are the function available for the Color Detector module:

  1. setColorScheme(schemeName) – In this function you pass the color scheme name as argument. Here there are certain constants(macros) define that can be passed as an argument to set different color scheme. These constants are as follows:
    1. RGB_3bit – to set RGB color scheme with 3-bit resolution. 3-bit resolution means any color detected by the color detector module will be classified into 2^3 (eight color levels)
    2. RGB_15bit – to set RGB color scheme with 15 bit resolution. 15-bit resolution means any color detected by the color detector module will be classified into 2^15 color levels.
    3. RGB_24bit – to set RGB color scheme with 24 bit resolution. 24-bit resolution means any color detected by the color detector module will be classified into 2^24 color levels.
    4. GRAYSCALE_1bit – to set GRAYSCALE color scheme with 1-bit resolution. 1-bit resolution means an object will be classified as black or white.
    5. GRAYSCALE_4bit – to set GRAYSCALE color scheme with 4-bit resolution. 4-bit resolution means an object color will be classified into 2^4 grey levels ranging from black to white.
    6. GRAYSCALE_8bit – to set GRAYSCALE color scheme with 8-bit resolution. 8-bit resolution means an object color will be classified into 2^8 grey levels ranging from black to white.
  2. setGridSize(GridSize) – This function helps in setting the grid to a size that you want your camera screen to be divided. Replace GridSize with macros like GRID_1x1, GRID_3x3, and GRID_5x5 to get a grid of 1×1, 3×3 or 5×5 respectively.
  3. setCalculationMode(colorCalculationMode) – This function sets the color calculation mode. It will be Average or Dominant as stated above. Corresponding to this macros are DOMINANT and AVERAGE.
  4. sendSettings(&functionName) –  This function is used to call a function which helps in the initialization of the camera settings for color detector module. That function is passed by reference as an argument in the sendSettings function
  5. getRedColor() – returns red level value in RGB or GRAYSCALE mode for 1×1 grid
  6. getGreenColor() – returns green level value in RGB or GRAYSCALE mode for 1×1 grid
  7. getBlueColor() – returns blue level value in RGB or GRAYSCALE mode for 1×1 grid
  8. getRedColor(row,cols) –  returns red level value in RGB or GRAYSCALE mode for cell determined by parameter row and cols for the grid of size 3×3 and 5×5.
  9. getGreenColor(row,cols) – returns green level value in RGB or GRAYSCALE mode for cell determined by parameter row and cols for the grid of size 3×3 and 5×5.
  10. getBlueColor(row,cols)– returns blue level value in RGB or GRAYSCALE mode for cell determined by parameter row and cols for the grid of size 3×3 and 5×5.
  11. getGrayScaleColor(row,cols) – returns a gray level color value for the module when color mode is selected as grayscale. In colored mode, this function returns -1.
  12. checkColor(colorArray, colorName) – It returns 0 or 1 depending on the fact that if the colorArray passed is same same colorName passed in function. This function runs on a small algorithm that is able to identify if color is red, blue, green, yellow or violet.

PictoBlox (Scratch) Blocks

There are 2 blocks in Dabble Extension of PictoBlox:

  • set grid size (), calculation mode () & color scheme ()”  is a stacked block used for setting grid size, color calculation mode and color mode settings. The block consists of three drop downs. Drop down of grid size has three grid settings options mainly 1×1, 3×3 and 5×5 as stated above.   Similarly, drop down of color calculation mode has options of Dominant and Average.

          And drop down of color scheme has various color modes like 24-bit RGB, 15 -bit RGB, 3-bit RGB, 8-bit Grayscale, 4-bit Grayscale, 1-bit Grayscale.                                            

     

  • get () color value for cell row () col () ”  is a reporter block it gives the value of selected color component for the selected cell. There is one drop-down for selecting the color component and two drop downs of rows and cells for selecting a cell. You can get Red, Green, Blue or Black (GrayScale) component for cell selected by the row and col drop downs having 1 to 5 values. You should select cell value as per the currently active grid in the app. For example, if a 3×3 grid is active then there are three rows and three columns. Hence the maximum row and col value selected should be 3. If row and col value exceed 3, then the block returns -1 signifying invalid cell address.

 

evive Notes Icon
Note: When you are using this module with Arduino Uno, Mega, and Nano,  you have to set the Bluetooth baud rate to the baud rate of the Bluetooth module to have proper communication between the board and the module. To set the baud rate you have to use set bluetooth baud rate to () block.

set bluetooth baud rate to

Examples

Click here to view Arduino IDE Example for Camera Module – Color Detector

Follow the steps:

  • Copy code as per your board in Arduino IDE and upload it.
  • Connect with Dabble app via Bluetooth.

You can also find this code in Arduino IDE by navigating to “File>>Examples>>Dabble>>” and select “PredictColor” example as per your board.

evive

Mega, Uno, and Nano

Click here to view PictoBlox (Scratch) Example for Camera Module – Color Detector

In the script given below, color of an RGB led is changed as per  the color detected by Color Detector module. 

Projects

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart