Professional Documents
Culture Documents
Figure 1: Determining the size and movement of the FOV according to mirror dynamics
Figure 2: Determining the distance from mirror using the radius of the face detected
Constants and Variables
lcd_length: max num of column of the LCD screen given by the user
lcd_height: max num of row of the LCD screen given by the user
rearcamera_height = max row of the rear cameras in pixels (height of the combined
rear camera frames max row of camera left = max row of camera right)
face_radius = the radius of the face detected in pixels (will be used to determine the
distance from mirror/camera, see Figure 2).
rectangle_length & rectangle_height : the size of the rectangle calculated with respect to the face
detected (distance from camera). This is the area where the image is visualized in the LCD screen
after resizing to LCD ratio. Thus, the rectangle ratio should be equal to LCD ratio to keep original
ratio of the image cropped.
The size of the Rectangle (regarding the size of the face detected)
i. The ratio of the rectangle should be equal to LCD ratio to be able to keep the original ratio.
ii. The size of the rectangle gets bigger and smaller according to distance from mirror and mirror
size (see Figure 1),
ratio_triangle
𝐫𝐞𝐚𝐥_𝐝𝐢𝐬𝐭𝐚𝐧𝐜𝐞 =
face_radius
(distance from mirror) (see Figure 2)
mirror_length
𝐅𝐎𝐕_𝐜𝐨𝐧𝐬𝐭_𝐗 = (see Figure 1)
real_distance
mirror_height
𝐅𝐎𝐕_𝐜𝐨𝐧𝐬𝐭_𝐘 = (see Figure 1)
real_distance
iii. The maximum size of the rectangle should be tuned to the ratio between LCD resolution (LCD
ratio) and the resolution of the combined frames obtained from the rear cameras
lcd_length
𝐥𝐜𝐝_𝐫𝐚𝐭𝐢𝐨 =
lcd_height
rearcamera_length
𝐫𝐞𝐚𝐫𝐜𝐚𝐦𝐞𝐫𝐚_𝐫𝐚𝐭𝐢𝐨 =
rearcamera_height
1. Determining the maximum size of the rectangle while keeping the lcd ratio (i) :
a. if lcd_ratio = rearcamera_ratio then (the ideal case)
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐦𝐚𝐱_𝐥𝐞𝐧𝐠𝐭𝐡 = rearcamera_length
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐦𝐚𝐱_𝐡𝐞𝐢𝐠𝐡𝐭 = rearcamera_height
lcd_length
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐦𝐚𝐱_𝐥𝐞𝐧𝐠𝐭𝐡 = rear_camera_height ∗
lcd_height
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐦𝐚𝐱_𝐡𝐞𝐢𝐠𝐡𝐭 = rear_camera_height
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐦𝐚𝐱_𝐥𝐞𝐧𝐠𝐭𝐡 = rear_camera_length
lcd_height
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐦𝐚𝐱_𝐡𝐞𝐢𝐠𝐡𝐭 = rear_camera_length ∗
lcd_length
2. Making sure that the size of the rectangle reaches its maximum size at a given distance
min_distance_Z: The minimum distance from the face camera defined by the user: This
distance will be the distance where the rectangle reaches the maximum size determined by
the rectangle_max_length X rectangle_max_height
max_distance_Z: The maximum distance from the face camera defined by the user: This
distance will be the distance where the rectangle reaches the minumum size
Similarly,
rectangle_max _height
𝐫𝐞𝐜𝐭𝐚𝐧𝐠𝐥𝐞_𝐬𝐭𝐚𝐧𝐝𝐚𝐫𝐝_𝐡𝐞𝐢𝐠𝐡𝐭 =
max _FOV_const_X
ratio_triangle
𝐫𝐞𝐚𝐥_𝐝𝐢𝐬𝐭𝐚𝐧𝐜𝐞 =
face_radius
And the quantity of the rectangle movement is tuned to the distance from the mirror/camera (see Figure 1)
mirror_length
𝐅𝐎𝐕_𝐜𝐨𝐧𝐬𝐭_𝐗 =
real_distance
mirror_height
𝐅𝐎𝐕_𝐜𝐨𝐧𝐬𝐭_𝐘 =
real_distance
2. Making sure that the rectangle can reach the boundry of the rear camera frame
Such that,
Should satisy the condition that we are able to see the boundaries of the rear frame
considering the size of the minumum rectangle length and the length of the face
detected at this distance. Since the area remained for the face movement should be
able to move the rectangle in the area that remained in the rear camera frame.
For instance, considering x movement at the distance of the minumum rectangle size, if
the area remained for the face movement is 100 pixels and the area remained for the
rectangle movement is 200 pixels, the rectangle should move 2 pixels for every 1
pixels of the face movement and if the FOV_Const_X is 0.5 here, then the
FOVX_movement_regulator has to be 4 in order to satisfy the condition.
Therefore we calculate the rectangle_min_length and rectangle_min_height at the
max_distance_Z.
At max_distance_Z,
mirror_length
we obtain the minumum value of FOV_const_X (𝐦𝐢𝐧_𝐅𝐎𝐕_𝐜𝐨𝐧𝐬𝐭_𝐗 = max_distance_Z
)
therefore, the minumum rectangle length and the minumum rectangle height are as it follows:
𝑟𝑎𝑡𝑖𝑜_𝑡𝑟𝑖𝑎𝑛𝑔𝑙𝑒
𝐟𝐚𝐜𝐞_𝐰𝐢𝐝𝐭𝐡_𝐚𝐭_𝐦𝐢𝐧_𝒓𝒆𝒄𝒕𝒂𝒏𝒈𝒍𝒆_𝒍𝒆𝒏𝒈𝒕𝒉 =
𝑚𝑎𝑥_𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒_𝑍
The area remained for the x and y movement of the face is:
face_width_at_min_𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒_𝑙𝑒𝑛𝑔𝑡ℎ
𝒓𝒆𝒎𝒂𝒊𝒏𝒆𝒅_𝒙_𝒎𝒐𝒗𝒆𝒎𝒆𝒏𝒕_𝒇𝒂𝒄𝒆 = facecamera_middle_Col −
2
face_width_at_min_𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒_𝑙𝑒𝑛𝑔𝑡ℎ
𝒓𝒆𝒎𝒂𝒊𝒏𝒆𝒅_𝒚_𝒎𝒐𝒗𝒆𝒎𝒆𝒏𝒕_𝒇𝒂𝒄𝒆 = facecamera_middle_Row −
2
And the area remained for the x and y movement of the rectangle is:
rearcamera_length − min_𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒_𝑙𝑒𝑛𝑔𝑡ℎ
𝒓𝒆𝒎𝒂𝒊𝒏𝒆𝒅_𝒙_𝒎𝒐𝒗𝒆𝒎𝒆𝒏𝒕_𝒓𝒆𝒄𝒕𝒂𝒏𝒈𝒍𝒆 =
2
rearcamera_height − min_𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒_ℎ𝑒𝑖𝑔ℎ𝑡
𝒓𝒆𝒎𝒂𝒊𝒏𝒆𝒅_𝒚_𝒎𝒐𝒗𝒆𝒎𝒆𝒏𝒕_𝒓𝒆𝒄𝒕𝒂𝒏𝒈𝒍𝒆 =
2
𝑟𝑒𝑚𝑎𝑖𝑛𝑒𝑑_𝑥_𝑚𝑜𝑣𝑒𝑚𝑒𝑛𝑡_𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒
𝒎𝒖𝒔𝒕_𝒓𝒂𝒕𝒊𝒐_𝒙 =
𝑟𝑒𝑚𝑎𝑖𝑛𝑒𝑑_𝑥_𝑚𝑜𝑣𝑒𝑚𝑒𝑛𝑡_𝑓𝑎𝑐𝑒
𝑟𝑒𝑚𝑎𝑖𝑛𝑒𝑑_𝑦_𝑚𝑜𝑣𝑒𝑚𝑒𝑛𝑡_𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒
𝒎𝒖𝒔𝒕_𝒓𝒂𝒕𝒊𝒐_𝒚 =
𝑟𝑒𝑚𝑎𝑖𝑛𝑒𝑑_𝑦_𝑚𝑜𝑣𝑒𝑚𝑒𝑛𝑡_𝑓𝑎𝑐𝑒
Finally,
𝑚𝑢𝑠𝑡_𝑟𝑎𝑡𝑖𝑜_𝑥
FOVX_movement_regulator =
min_FOV_const_X
𝑚𝑢𝑠𝑡_𝑟𝑎𝑡𝑖𝑜_𝑦
FOVY_movement_regulator =
min_FOV_const_Y
3. Smoothing the rectangle movement
To smoothen the rectangle movement we use gaussian function for the x (DifX),y (DifY) and z movement
(DifZ = face_radius):
We let user define the gaussian size and the sigma (σ), where the gaussian function is:
𝒙𝟐
−𝟐 ∗ 𝝈
𝒇(𝒙) = 𝒆
Due to fact that we do not have the further frames, we use the current frame and the previous frames
depending on the size of the gaussian.
Such that,
If the gaussian size given is 11 and the σ is 2 then the distribution becomes:
[0.0088 0.0271 0.0651 0.1216 0.1770 0.2006 0.1770 0.1216 0.0651 0.0271 0.0088]
[DifXt-5 DifXt-4 DifXt-3 DifXt-2 DifXt-1 DifXt - - - - - ]
[DifYt-5 DifYt-4 DifYt-3 DifY t-2
DifY t-1
DifYt
- - - - - ]
[DifZt-5 DifZt-4 DifZt-3 DifZt-2 DifZt-1 DifZt - - - - - ]
Where DifXt, DifYt and DifZt are the current movements of the face, which are
multiplied by the middle gaussian element (0.2006) and we multiple the previous
movements by the rest of the gaussian elements respectively so that the influence
of the current movements have the higher effect on the movement.
Looking at the half gaussian array, one should see that the we only used the %60 of
the actual movements in the example given above.
At figure 3 it is clear that using half gaussian filter reduces the movements size.
However, after using gauss_regulator we obtain a similar function like full gauss
(see figure 4)
Figure 5: Half Gauss ΔDifX (size of movements between the DifX, DifXt- DifXt-1 )
Figure 6: Half Gauss Regulated ΔDifX
Figure 7 shows the output if we had used a full gaussian filter. On the other hand Figure 5 shows the half-
gaussian filter and Figure 6 shows the ΔDifX function after applying gauss_regulator to the
half-gaussian function, which is used in the application.
4. To stop vibrating of the rectangle movements (Ignoring the default face movements)
Although when the face is not moving there will be small movements which turn out to be undesirable
vibratings.
Hence, we define a threshold (movement_threshold) for ΔDifX, ΔdifY and ΔdifZ so that we keep
the rectangle movements stable, where
ΔDifXt = DifXt – DifXt-1
ΔDifYt = DifYt – DifYt-1
ΔDifXt = DifZt – DifZt-1
However, in order to see when the face starts vibrating even though the user is not moving, we use more
than 2 previous movements taking mean of them (avg_delta_DifX, avg_delta_DifY, avg_delta_DifZ)
For instance, if the gaussian size is defined 11, the size of the previous movements we keep will be 6.
Therefore, in this scenerio, we obtain the average of the 5 previous movements and the current
movement to see if there is vibrating.
*** Note that, using 19 gaussian size with σ = 3 we obtained desirable results.
*** When the movement_threshold = 2.5 we were able to stop vibratings without affecting the rectangle
movements negatively.