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.
These modules are:
- Camera and Videos
- Color Detector
- Line Follower (Coming Soon)
- Face Detector (Coming Soon)
Color Detector module
This module process live video stream and detects colors as per the selected settings.
There are various settings available.
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.
The video stream will be divided into the grid and each grid cell will result in one color. Available grid size:
- 1×1 (single cell)
- 3×3 (9 cells)
- 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.
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 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.
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
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:
You can download the zip of Arduino Library for
depending on the board you are using.
Enabling Bluetooth Communication
To enable Bluetooth communication, you have to initialize serial communication using the following code:
- For evive and Arduino Mega, Uno and Nano
- For ESP32
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:
Following are the function available for the Color Detector module:
- 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:
- 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)
- 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.
- 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.
- GRAYSCALE_1bit – to set GRAYSCALE color scheme with 1-bit resolution. 1-bit resolution means an object will be classified as black or white.
- 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.
- 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.
- 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.
- 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.
- 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
- getRedColor() – returns red level value in RGB or GRAYSCALE mode for 1×1 grid
- getGreenColor() – returns green level value in RGB or GRAYSCALE mode for 1×1 grid
- getBlueColor() – returns blue level value in RGB or GRAYSCALE mode for 1×1 grid
- 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.
- 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.
- 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.
- 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.
- 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.
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.
Mega, Uno, and Nano
This project will show you how to make a Smartphone-controlled robot that plays different sounds on detecting different colors.
This project will show you how to make a line follower robot using a Smartphone.