Skip to content

Commit 8bc4db0

Browse files
committed
Duplicate *_Tests.cpp history in cppunittest/ history.
1 parent b232919 commit 8bc4db0

21 files changed

+4601
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* @file
3+
* @brief Unit tests for openshot::Frame
4+
* @author Jonathan Thomas <[email protected]>
5+
* @author FeRD (Frank Dana) <[email protected]>
6+
*
7+
* @ref License
8+
*/
9+
10+
/* LICENSE
11+
*
12+
* Copyright (c) 2008-2019 OpenShot Studios, LLC
13+
* <http://www.openshotstudios.com/>. This file is part of
14+
* OpenShot Library (libopenshot), an open-source project dedicated to
15+
* delivering high quality video editing and animation solutions to the
16+
* world. For more information visit <http://www.openshot.org/>.
17+
*
18+
* OpenShot Library (libopenshot) is free software: you can redistribute it
19+
* and/or modify it under the terms of the GNU Lesser General Public License
20+
* as published by the Free Software Foundation, either version 3 of the
21+
* License, or (at your option) any later version.
22+
*
23+
* OpenShot Library (libopenshot) is distributed in the hope that it will be
24+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
* GNU Lesser General Public License for more details.
27+
*
28+
* You should have received a copy of the GNU Lesser General Public License
29+
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
30+
*/
31+
32+
#include <sstream>
33+
#include <memory>
34+
35+
#include "UnitTest++.h"
36+
// Prevent name clashes with juce::UnitTest
37+
#define DONT_SET_USING_JUCE_NAMESPACE 1
38+
#include "Clip.h"
39+
#include "CVObjectDetection.h"
40+
#include "ProcessingController.h"
41+
#include "Json.h"
42+
43+
using namespace openshot;
44+
45+
std::string effectInfo =(" {\"protobuf_data_path\": \"objdetector.data\", "
46+
" \"processing_device\": \"GPU\", "
47+
" \"model_configuration\": \"~/yolo/yolov3.cfg\", "
48+
" \"model_weights\": \"~/yolo/yolov3.weights\", "
49+
" \"classes_file\": \"~/yolo/obj.names\"} ");
50+
51+
SUITE(CVObjectDetection_Tests)
52+
{
53+
54+
// Just for the stabilizer constructor, it won't be used
55+
ProcessingController processingController;
56+
57+
TEST(DetectObject_Video)
58+
{
59+
// Create a video clip
60+
std::stringstream path;
61+
path << TEST_MEDIA_PATH << "run.mp4";
62+
63+
// Open clip
64+
openshot::Clip c1(path.str());
65+
c1.Open();
66+
67+
//TODO remove hardcoded path
68+
CVObjectDetection objectDetector(effectInfo, processingController);
69+
70+
objectDetector.detectObjectsClip(c1, 0, 20, true);
71+
72+
CVDetectionData dd = objectDetector.GetDetectionData(20);
73+
74+
float x1 = dd.boxes.at(20).x;
75+
float y1 = dd.boxes.at(20).y;
76+
float x2 = x1 + dd.boxes.at(20).width;
77+
float y2 = y1 + dd.boxes.at(20).height;
78+
float confidence = dd.confidences.at(20);
79+
int classId = dd.classIds.at(20);
80+
81+
CHECK_EQUAL((int) (x1 * 720), 106);
82+
CHECK_EQUAL((int) (y1 * 400), 21);
83+
CHECK_EQUAL((int) (x2 * 720), 628);
84+
CHECK_EQUAL((int) (y2 * 400), 429);
85+
CHECK_EQUAL((int) (confidence * 1000), 554);
86+
CHECK_EQUAL(classId, 0);
87+
88+
}
89+
90+
91+
TEST(SaveLoad_Protobuf)
92+
{
93+
94+
// Create a video clip
95+
std::stringstream path;
96+
path << TEST_MEDIA_PATH << "run.mp4";
97+
98+
// Open clip
99+
openshot::Clip c1(path.str());
100+
c1.Open();
101+
102+
//TODO remove hardcoded path
103+
CVObjectDetection objectDetector_1(effectInfo ,processingController);
104+
105+
objectDetector_1.detectObjectsClip(c1, 0, 20, true);
106+
107+
CVDetectionData dd_1 = objectDetector_1.GetDetectionData(20);
108+
109+
float x1_1 = dd_1.boxes.at(20).x;
110+
float y1_1 = dd_1.boxes.at(20).y;
111+
float x2_1 = x1_1 + dd_1.boxes.at(20).width;
112+
float y2_1 = y1_1 + dd_1.boxes.at(20).height;
113+
float confidence_1 = dd_1.confidences.at(20);
114+
int classId_1 = dd_1.classIds.at(20);
115+
116+
objectDetector_1.SaveObjDetectedData();
117+
118+
CVObjectDetection objectDetector_2(effectInfo, processingController);
119+
120+
objectDetector_2._LoadObjDetectdData();
121+
122+
CVDetectionData dd_2 = objectDetector_2.GetDetectionData(20);
123+
124+
float x1_2 = dd_2.boxes.at(20).x;
125+
float y1_2 = dd_2.boxes.at(20).y;
126+
float x2_2 = x1_2 + dd_2.boxes.at(20).width;
127+
float y2_2 = y1_2 + dd_2.boxes.at(20).height;
128+
float confidence_2 = dd_2.confidences.at(20);
129+
int classId_2 = dd_2.classIds.at(20);
130+
131+
CHECK_EQUAL((int) (x1_1 * 720), (int) (x1_2 * 720));
132+
CHECK_EQUAL((int) (y1_1 * 400), (int) (y1_2 * 400));
133+
CHECK_EQUAL((int) (x2_1 * 720), (int) (x2_2 * 720));
134+
CHECK_EQUAL((int) (y2_1 * 400), (int) (y2_2 * 400));
135+
CHECK_EQUAL((int) (confidence_1 * 1000), (int) (confidence_2 * 1000));
136+
CHECK_EQUAL(classId_1, classId_2);
137+
138+
}
139+
140+
} // SUITE(Frame_Tests)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/**
2+
* @file
3+
* @brief Unit tests for openshot::Frame
4+
* @author Jonathan Thomas <[email protected]>
5+
* @author FeRD (Frank Dana) <[email protected]>
6+
*
7+
* @ref License
8+
*/
9+
10+
/* LICENSE
11+
*
12+
* Copyright (c) 2008-2019 OpenShot Studios, LLC
13+
* <http://www.openshotstudios.com/>. This file is part of
14+
* OpenShot Library (libopenshot), an open-source project dedicated to
15+
* delivering high quality video editing and animation solutions to the
16+
* world. For more information visit <http://www.openshot.org/>.
17+
*
18+
* OpenShot Library (libopenshot) is free software: you can redistribute it
19+
* and/or modify it under the terms of the GNU Lesser General Public License
20+
* as published by the Free Software Foundation, either version 3 of the
21+
* License, or (at your option) any later version.
22+
*
23+
* OpenShot Library (libopenshot) is distributed in the hope that it will be
24+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
* GNU Lesser General Public License for more details.
27+
*
28+
* You should have received a copy of the GNU Lesser General Public License
29+
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
30+
*/
31+
32+
#include <sstream>
33+
#include <memory>
34+
35+
#include "UnitTest++.h"
36+
// Prevent name clashes with juce::UnitTest
37+
#define DONT_SET_USING_JUCE_NAMESPACE 1
38+
#include "Clip.h"
39+
#include "CVStabilization.h" // for TransformParam, CamTrajectory, CVStabilization
40+
#include "ProcessingController.h"
41+
42+
using namespace openshot;
43+
44+
SUITE(CVStabilizer_Tests)
45+
{
46+
47+
// Just for the stabilizer constructor, it won't be used
48+
ProcessingController processingController;
49+
50+
TEST(Stabilize_Video)
51+
{
52+
// Create a video clip
53+
std::stringstream path;
54+
path << TEST_MEDIA_PATH << "test.avi";
55+
56+
// Open clip
57+
openshot::Clip c1(path.str());
58+
c1.Open();
59+
60+
std::string json_data = R"proto(
61+
{
62+
"protobuf_data_path": "stabilizer.data",
63+
"smoothing-window": 30
64+
} )proto";
65+
66+
// Create stabilizer
67+
CVStabilization stabilizer(json_data, processingController);
68+
69+
// Stabilize clip for frames 0-21
70+
stabilizer.stabilizeClip(c1, 0, 21, true);
71+
72+
// Get stabilized data
73+
TransformParam tp = stabilizer.GetTransformParamData(20);
74+
CamTrajectory ct = stabilizer.GetCamTrajectoryTrackedData(20);
75+
76+
// // Compare if stabilized data is equal to pre-tested ones
77+
int dx = tp.dx*1000;
78+
int dy = tp.dy*1000;
79+
int da = tp.da*1000;
80+
int x = ct.x*1000;
81+
int y = ct.y*1000;
82+
int a = ct.a*1000;
83+
84+
CHECK_EQUAL((int) (58), dx);
85+
CHECK_EQUAL((int) (-88), dy);
86+
CHECK_EQUAL((int) (7), da);
87+
CHECK_EQUAL((int) (0), x);
88+
CHECK_EQUAL((int) (-1), y);
89+
CHECK_EQUAL((int) (0), a);
90+
}
91+
92+
93+
TEST(SaveLoad_Protobuf)
94+
{
95+
96+
// Create a video clip
97+
std::stringstream path;
98+
path << TEST_MEDIA_PATH << "test.avi";
99+
100+
// Open clip
101+
openshot::Clip c1(path.str());
102+
c1.Open();
103+
104+
std::string json_data = R"proto(
105+
{
106+
"protobuf_data_path": "stabilizer.data",
107+
"smoothing-window": 30
108+
} )proto";
109+
110+
// Create first stabilizer
111+
CVStabilization stabilizer_1(json_data, processingController);
112+
113+
// Stabilize clip for frames 0-20
114+
stabilizer_1.stabilizeClip(c1, 0, 20+1, true);
115+
116+
// Get stabilized data
117+
TransformParam tp_1 = stabilizer_1.GetTransformParamData(20);
118+
CamTrajectory ct_1 = stabilizer_1.GetCamTrajectoryTrackedData(20);
119+
120+
// Save stabilized data
121+
stabilizer_1.SaveStabilizedData();
122+
123+
// Create second stabilizer
124+
CVStabilization stabilizer_2(json_data, processingController);
125+
126+
// Load stabilized data from first stabilizer protobuf data
127+
stabilizer_2._LoadStabilizedData();
128+
129+
// Get stabilized data
130+
TransformParam tp_2 = stabilizer_2.GetTransformParamData(20);
131+
CamTrajectory ct_2 = stabilizer_2.GetCamTrajectoryTrackedData(20);
132+
133+
// Compare first stabilizer data with second stabilizer data
134+
CHECK_EQUAL((int) (tp_1.dx * 10000), (int) (tp_2.dx *10000));
135+
CHECK_EQUAL((int) (tp_1.dy * 10000), (int) (tp_2.dy * 10000));
136+
CHECK_EQUAL((int) (tp_1.da * 10000), (int) (tp_2.da * 10000));
137+
CHECK_EQUAL((int) (ct_1.x * 10000), (int) (ct_2.x * 10000));
138+
CHECK_EQUAL((int) (ct_1.y * 10000), (int) (ct_2.y * 10000));
139+
CHECK_EQUAL((int) (ct_1.a * 10000), (int) (ct_2.a * 10000));
140+
}
141+
142+
} // SUITE(Frame_Tests)

0 commit comments

Comments
 (0)