Skip to content

Commit

Permalink
Fix zooming box calculation in detect_filter_video_tick function
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Mar 28, 2024
1 parent 8659156 commit c649fbe
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/detect-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,17 +646,16 @@ void detect_filter_video_tick(void *data, float seconds)
float frameAspectRatio = (float)frame.cols / (float)frame.rows;
// calculate an aspect ratio box around the object using its height
float boxHeight = boundingBox.height;
float boxWidth = boxHeight * frameAspectRatio;
// calculate the zooming box size
// when the zoom factor is 1, the zooming box is the same size as the bounding box
// when the zoom factor is 10, the zooming box is the same size of the image
float dh = frame.rows - boxHeight;
float dh = (float)frame.rows - boxHeight;
float buffer = dh * ((tf->zoomFactor - 1) / 9);
float zh = boxHeight + buffer;
float zw = zh * frameAspectRatio;
// calculate the top left corner of the zooming box
float zx = boundingBox.x - (zw - boundingBox.width) / 2;
float zy = boundingBox.y - (zh - boundingBox.height) / 2;
float zx = boundingBox.x - (zw - boundingBox.width) / 2.0f;
float zy = boundingBox.y - (zh - boundingBox.height) / 2.0f;

if (tf->trackingRect.width == 0) {
// initialize the trackingRect
Expand Down Expand Up @@ -685,13 +684,15 @@ void detect_filter_video_tick(void *data, float seconds)
obs_data_set_int(crop_pad_settings, "top",
(int)tf->trackingRect.y);
// right = image width - (zx + zw)
obs_data_set_int(crop_pad_settings, "right",
(int)(frame.cols - (tf->trackingRect.x +
tf->trackingRect.width)));
obs_data_set_int(
crop_pad_settings, "right",
(int)((float)frame.cols -
(tf->trackingRect.x + tf->trackingRect.width)));
// bottom = image height - (zy + zh)
obs_data_set_int(crop_pad_settings, "bottom",
(int)(frame.rows - (tf->trackingRect.y +
tf->trackingRect.height)));
obs_data_set_int(
crop_pad_settings, "bottom",
(int)((float)frame.rows -
(tf->trackingRect.y + tf->trackingRect.height)));
// apply the settings
obs_source_update(tf->trackingFilter, crop_pad_settings);
obs_data_release(crop_pad_settings);
Expand Down

0 comments on commit c649fbe

Please sign in to comment.