The 8 megapixel sensor above has a resolution of 3,264 x 2,448 pixels, with 327,184 pixels in an area just 1mm x 1mm in size.

[code (using MATLAB)](https://uk.mathworks.com/matlabcentral/fileexchange/18440-color-detection-using-hsv-color-space-training-and-testing?)
Formulae: (Source)

S = 1- (min/max)
max-min = S*max
White:
S: very low <0.01 ( 0.004-0.005 ) * 255 ⇒ <2
V: high [0.43, 0.48] ( 0.44 ~ 0.45 ) * 255 ⇒ 112 ~ 115
Black:
S: low/medium
V: very low <0.05
(has gap / can enter or not)
Algorithm:
FPGA should receive a trigger from ESP telling it to start the procedure.
Initialise:
x1=x_max
y2=y_max
x3=0
Look at area below YY_TH (y≥YY_TH):
First: check intersection
IF no intersection: y2 > YY_TH (x_il=0, x_ir = x_max)
RHS:
if (x1>XX_TH) ⇒ can enter
else ⇒ cannot enter
LHS:
if (x3<XX_TH) ⇒ can enter
else ⇒ cannot enter
IF have intersection(s): y2 = YY_TH
RHS:
if (x1<x2 && x3=x2) ⇒ can enter
else ⇒ cannot enter
LHS:
if (x3>x2 && x1=x2) ⇒ can enter
else ⇒ cannot enter