Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit c649fbe

Browse files
committed
Fix zooming box calculation in detect_filter_video_tick function
1 parent 8659156 commit c649fbe

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/detect-filter.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -646,17 +646,16 @@ void detect_filter_video_tick(void *data, float seconds)
646646
float frameAspectRatio = (float)frame.cols / (float)frame.rows;
647647
// calculate an aspect ratio box around the object using its height
648648
float boxHeight = boundingBox.height;
649-
float boxWidth = boxHeight * frameAspectRatio;
650649
// calculate the zooming box size
651650
// when the zoom factor is 1, the zooming box is the same size as the bounding box
652651
// when the zoom factor is 10, the zooming box is the same size of the image
653-
float dh = frame.rows - boxHeight;
652+
float dh = (float)frame.rows - boxHeight;
654653
float buffer = dh * ((tf->zoomFactor - 1) / 9);
655654
float zh = boxHeight + buffer;
656655
float zw = zh * frameAspectRatio;
657656
// calculate the top left corner of the zooming box
658-
float zx = boundingBox.x - (zw - boundingBox.width) / 2;
659-
float zy = boundingBox.y - (zh - boundingBox.height) / 2;
657+
float zx = boundingBox.x - (zw - boundingBox.width) / 2.0f;
658+
float zy = boundingBox.y - (zh - boundingBox.height) / 2.0f;
660659

661660
if (tf->trackingRect.width == 0) {
662661
// initialize the trackingRect
@@ -685,13 +684,15 @@ void detect_filter_video_tick(void *data, float seconds)
685684
obs_data_set_int(crop_pad_settings, "top",
686685
(int)tf->trackingRect.y);
687686
// right = image width - (zx + zw)
688-
obs_data_set_int(crop_pad_settings, "right",
689-
(int)(frame.cols - (tf->trackingRect.x +
690-
tf->trackingRect.width)));
687+
obs_data_set_int(
688+
crop_pad_settings, "right",
689+
(int)((float)frame.cols -
690+
(tf->trackingRect.x + tf->trackingRect.width)));
691691
// bottom = image height - (zy + zh)
692-
obs_data_set_int(crop_pad_settings, "bottom",
693-
(int)(frame.rows - (tf->trackingRect.y +
694-
tf->trackingRect.height)));
692+
obs_data_set_int(
693+
crop_pad_settings, "bottom",
694+
(int)((float)frame.rows -
695+
(tf->trackingRect.y + tf->trackingRect.height)));
695696
// apply the settings
696697
obs_source_update(tf->trackingFilter, crop_pad_settings);
697698
obs_data_release(crop_pad_settings);

0 commit comments

Comments
 (0)