Fixing a RGB to BGR color issue with the Outline effect, and adding in unit tests for the Outline effect.

This commit is contained in:
Jonathan Thomas
2025-03-12 16:52:15 -05:00
parent 8708302939
commit 5cd91a9c97
4 changed files with 74 additions and 11 deletions

View File

@@ -119,10 +119,10 @@ cv::Mat Outline::QImageToBGRACvMat(std::shared_ptr<QImage>& qimage) {
}
std::shared_ptr<QImage> Outline::BGRACvMatToQImage(cv::Mat img) {
cv::Mat final_img;
cv::cvtColor(img, final_img, cv::COLOR_RGBA2BGRA);
QImage qimage(final_img.data, final_img.cols, final_img.rows, final_img.step, QImage::Format_ARGB32);
std::shared_ptr<QImage> imgIn = std::make_shared<QImage>(qimage.convertToFormat(QImage::Format_RGBA8888_Premultiplied));
// Directly wrap the cv::Mat data in a QImage
QImage qimage(img.data, img.cols, img.rows, img.step, QImage::Format_ARGB32);
std::shared_ptr<QImage> imgIn = std::make_shared<QImage>(
qimage.convertToFormat(QImage::Format_RGBA8888_Premultiplied));
return imgIn;
}

View File

@@ -27,10 +27,10 @@ namespace openshot
{
/**
* @brief This class add the outline around image with transparent background and can be animated
* @brief This class add an outline around image with transparent background and can be animated
* with openshot::Keyframe curves over time.
*
* Since outline effect is pretty useful in many cases, this effect is added to libopenshot.
* Outlines can be added around any image or text, and animated over time.
*/
class Outline : public EffectBase
{
@@ -47,9 +47,9 @@ namespace openshot
public:
Keyframe width; ///< Width of the outline
Keyframe blue; ///< Blue of the outline
Keyframe green; ///< Green of the outline
Keyframe red; ///< Red channel of the outline
Keyframe green; ///< Green of the outline
Keyframe blue; ///< Blue of the outline
Keyframe alpha; ///< Alpha of the outline
/// Blank constructor, useful when using Json to load the effect properties
@@ -58,11 +58,11 @@ namespace openshot
/// Default constructor, which require width, red, green, blue, alpha
///
/// @param width the width of the outline (between 0 and 1000, rounded to int)
/// @param blue the blue channel of the outline (between 0 and 255, rounded to int)
/// @param green the green channel of the outline (between 0 and 255, rounded to int)
/// @param red the red channel of the outline (between 0 and 255, rounded to int)
/// @param green the green channel of the outline (between 0 and 255, rounded to int)
/// @param blue the blue channel of the outline (between 0 and 255, rounded to int)
/// @param alpha the alpha channel of the outline (between 0 and 255, rounded to int)
Outline(Keyframe width, Keyframe blue, Keyframe green, Keyframe red, Keyframe alpha);
Outline(Keyframe width, Keyframe red, Keyframe green, Keyframe blue, Keyframe alpha);
/// @brief This method is required for all derived classes of ClipBase, and returns a
/// new openshot::Frame object. All Clip keyframes and effects are resolved into

View File

@@ -58,6 +58,7 @@ if($CACHE{HAVE_OPENCV})
list(APPEND OPENSHOT_TESTS
CVTracker
CVStabilizer
CVOutline
# CVObjectDetection
)
endif()

62
tests/CVOutline.cpp Normal file
View File

@@ -0,0 +1,62 @@
/**
* @file
* @brief Unit tests for OpenCV Outline effect
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
// Copyright (c) 2008-2025 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <sstream>
#include <memory>
#include <cmath>
#include "openshot_catch.h"
#include "Clip.h"
#include "effects/Outline.h"
using namespace openshot;
TEST_CASE( "Outline_Tests", "[libopenshot][opencv][outline]" )
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "1F0CF.svg";
// Open clip
openshot::Clip c(path.str());
c.Open();
auto f = c.GetFrame(1);
// Create effect constructor (default values)
openshot::Outline e1{};
// Get frame from effect
auto f1 = e1.GetFrame(f, 1);
std::shared_ptr<QImage> i1 = f1->GetImage();
// Check effect colors
QColor pix1 = i1->pixelColor(3, 32);
QColor compare1{0, 0, 0, 0};
CHECK(pix1 == compare1);
// Test another effect constructor
openshot::Outline e2(Keyframe(3.0), Keyframe(255.0),
Keyframe(0.0), Keyframe(0.0), Keyframe(128.0));
// Get frame from effect
auto f2 = e2.GetFrame(f, 1);
std::shared_ptr<QImage> i2 = f2->GetImage();
// Check effect colors
QColor pix2 = i2->pixelColor(3, 32);
QColor compare2{0, 0, 255, 128};
CHECK(pix2 == compare2);
// Close clip
c.Close();
}