Skip to content
Open
Changes from 1 commit
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
39 changes: 30 additions & 9 deletions src/modules/opencv/filter_opencv_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,36 +468,37 @@ 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;
roi.copyTo(blurredRoi);
bool do_blur = true;
Comment thread
doruphin marked this conversation as resolved.

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 +507,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, 1);
Comment thread
doruphin marked this conversation as resolved.
Outdated
blurredRoi.copyTo(roi, mask);
}
break;
default:
blurredRoi.copyTo(roi);
break;
}
}
}

// Paint overlay shape
Expand Down