Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions src/modules/opencv/filter_opencv_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,36 +468,36 @@ static int filter_get_image(mlt_frame frame,
}

if (blur > 0 && data->boundingBox.width > 1 && data->boundingBox.height > 1) {
cv::Mat roi = cvFrame(data->boundingBox);
cv::Mat blurredRoi;
bool do_blur = true;

switch (mlt_properties_get_int(filter_properties, "blur_type")) {
case 1:
// Gaussian Blur
cv::GaussianBlur(cvFrame(data->boundingBox),
cvFrame(data->boundingBox),
cv::Size(0, 0),
blur);
cv::GaussianBlur(roi, blurredRoi, cv::Size(0, 0), blur);
break;
case 2:
// Pixelate
{
cv::Mat roi = cvFrame(data->boundingBox);
cv::Mat res;
cv::resize(roi,
res,
cv::Size(MAX(2, data->boundingBox.width / blur),
MAX(2, data->boundingBox.height / blur)),
cv::INTER_NEAREST);
cv::resize(res,
roi,
blurredRoi,
cv::Size(data->boundingBox.width, data->boundingBox.height),
0,
0,
cv::INTER_NEAREST);
cvFrame(data->boundingBox) = roi;
}
break;
case 3:
// Opaque fill, handled in shape_width option
shape_width = -1;
do_blur = false;
break;
case 0:
// Median Blur
Expand All @@ -506,12 +506,32 @@ static int filter_get_image(mlt_frame frame,
// median blur param must be odd and, minimum 3
++blur;
}
cv::medianBlur(cvFrame(data->boundingBox), cvFrame(data->boundingBox), blur);
cv::medianBlur(roi, blurredRoi, blur);
break;
default:
// Do nothing
do_blur = false;
break;
}

if (do_blur) {
switch (mlt_properties_get_int(filter_properties, "shape")) {
case 1:
// Ellipse
{
cv::Mat mask = cv::Mat::zeros(roi.size(), CV_8UC1);
cv::RotatedRect bounding = cv::RotatedRect(cv::Point2f(data->boundingBox.width / 2.0f,
data->boundingBox.height / 2.0f),
cv::Size2f(data->boundingBox.width, data->boundingBox.height),
0);
cv::ellipse(mask, bounding, cv::Scalar(255), -1, cv::LINE_4);
blurredRoi.copyTo(roi, mask);
}
break;
default:
blurredRoi.copyTo(roi);
break;
}
}
}

// Paint overlay shape
Expand Down Expand Up @@ -546,7 +566,7 @@ static int filter_get_image(mlt_frame frame,
bounding,
cv::Scalar(shape_color.r, shape_color.g, shape_color.b),
shape_width,
1);
cv::LINE_4);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the cv library, the 1 before defaulted to a 4, so this just uses the nicer enum

From opencv-4.5.5/modules/imgproc/src/drawing.cpp:263

if( connectivity == 0 )
        connectivity = 8;
    else if( connectivity == 1 )
        connectivity = 4;

}
break;
case 0:
Expand Down