22 init_effect_details();
27 width(width), color(color)
30 init_effect_details();
34 void Outline::init_effect_details()
49 std::shared_ptr<openshot::Frame>
Outline::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
57 if (widthValue <= 0.0 || alphaValue <= 0) {
63 std::shared_ptr<QImage> frame_image = frame->GetImage();
65 float sigmaValue = widthValue / 3.0;
66 if (sigmaValue <= 0.0)
68 cv::Mat cv_image = QImageToBGRACvMat(frame_image);
71 std::vector<cv::Mat> channels(4);
72 cv::split(cv_image, channels);
73 cv::Mat alpha_mask = channels[3].clone();
77 cv::GaussianBlur(alpha_mask, outline_mask, cv::Size(0, 0), sigmaValue, sigmaValue, cv::BorderTypes::BORDER_DEFAULT);
78 cv::threshold(outline_mask, outline_mask, 0, 255, cv::ThresholdTypes::THRESH_BINARY);
82 cv::Canny(outline_mask, edge_mask, 250, 255);
85 cv::Mat blurred_edge_mask;
86 cv::GaussianBlur(edge_mask, blurred_edge_mask, cv::Size(0, 0), 0.8, 0.8, cv::BorderTypes::BORDER_DEFAULT);
87 cv::bitwise_or(outline_mask, blurred_edge_mask, outline_mask);
92 cv::Mat solid_color_mat(cv::Size(cv_image.cols, cv_image.rows), CV_8UC4, cv::Scalar(redValue, greenValue, blueValue, alphaValue));
95 solid_color_mat.copyTo(final_image, outline_mask);
96 cv_image.copyTo(final_image, alpha_mask);
98 std::shared_ptr<QImage> new_frame_image = BGRACvMatToQImage(final_image);
101 *frame_image = *new_frame_image;
105 cv::Mat Outline::QImageToBGRACvMat(std::shared_ptr<QImage>& qimage) {
106 cv::Mat cv_img(qimage->height(), qimage->width(), CV_8UC4, (uchar*)qimage->constBits(), qimage->bytesPerLine());
110 std::shared_ptr<QImage> Outline::BGRACvMatToQImage(cv::Mat img) {
112 cv::cvtColor(img, final_img, cv::COLOR_RGBA2BGRA);
113 QImage qimage(final_img.data, final_img.cols, final_img.rows, final_img.step, QImage::Format_ARGB32);
114 std::shared_ptr<QImage> imgIn = std::make_shared<QImage>(qimage.convertToFormat(QImage::Format_RGBA8888_Premultiplied));
148 catch (
const std::exception& e)
151 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
162 if (!root[
"width"].isNull())
164 if (!root[
"color"].isNull())
183 return root.toStyledString();