# Performance Analysis of a Color-Code-Based Optical Camera Communication System
## 2 Proposed OCC System Architecture
### Image Processing Algorithm  
When the application is started, definitions are saved first. The Python-Global module is used to call these definitions at any time. Then the index of the camera used in the application is defined; otherwise, the application will not be able to select the camera itself. The capture function runs 5 ms after the application is compiled. OpenCV starts taking images in the capture function and first looks for the starting bitstream. In this study, the starting data were chosen as the color green in a special coordinate outside the 16 color channels in matrix form. The bit sequence of the green color is the same in red-green-blue (RGB) and blue-green-red (BGR) color spaces. If the starting data are not found, images are taken again at specified time intervals. For each image, a 44 \(\times\) 44-pixel square is drawn with image processing and added to the Canvas and displayed on the screen. Thus, the coded color channels sent by the transmitter can be included in the matrix. Since the coordinates of the 4 \(\times\) 4 color matrix are known in advance, only the colors belonging to the matrix are saved after the starting color (green color) is taken. If the camera fails to take an image, an error message is written to Canvas. After the recording process is completed, the function is called for decoding. In the function prepared for the decoding process, all recorded matrices are called one by one. Here, the color space is selected first. All image processing techniques for the test are applied here. Dimming, brightening, masking, noise reduction, blurring, sizing, etc. can be added to the algorithm if needed.  
For example, the basic principle of masking is to show the desired color values as white and the remaining colors as black. Figure 8 shows how the masking process works for red, green, and blue colors. Here, by specifying threshold values, masking was applied to the camera image in daylight. After the images below the threshold were made black, the red, green, and blue colors in the 4 \(\times\) 4 color channel were detected.  
Figure 8: Masking with image processing.  
Figure 7: Receiver circuit Python software: (a) Label (b) Canvas.  
In the masking technique, the image is first converted to the hue-saturation-value (HSV) color space. Here, lower and upper limits are set separately for hue, saturation, and value parameters. These lower and upper bounds represent the color's main value, saturation, and luminance values, respectively. The lower and upper bounds are set as 60 and 75 for color value, 0 and 255 for saturation, and 0 and 255 for brightness, respectively, in the code given in Figure 9 to mask the green color. The code detects the color within these limits, accepts the rest as 0, and outputs a black color. After the masking technique, the original masked color is accessed by the bitwise_and operation.  
After applying image processing techniques, the image is resized to 308 \(\times\) 308 pixels. In the resized image, data are read from the midpoint of each color channel. In OpenCV, when the upper left corner of the image is selected as the origin, the first color channel is located at coordinate (22,22) and the second color channel is located at coordinate (110,22). According to the values read sequentially from the channels in the image, bits are stored in the list named data and each 8-bit data is converted into meaningful data according to the ASCII table. If the data cannot be read, x and y values are stored in the list named error. Thus, the error is detected in which image and at which coordinate. In this study, we investigated the effect of HSV and RGB color space in the decoding phase. For this reason, the daytime values of HSV and RGB color spaces were recorded in the test phase. Here, two separate functions were written for RGB and HSV color space and both decoding processes were applied to the received data.