2020-06-28 16:54:11 -03:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Unit tests for openshot::Frame
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
|
|
|
|
*
|
|
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
|
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "UnitTest++.h"
|
|
|
|
|
// Prevent name clashes with juce::UnitTest
|
|
|
|
|
#define DONT_SET_USING_JUCE_NAMESPACE 1
|
|
|
|
|
#include "../include/OpenShot.h"
|
2020-07-16 21:10:02 -03:00
|
|
|
#include "../include/ProcessingController.h"
|
2020-06-28 16:54:11 -03:00
|
|
|
#include <QImage>
|
|
|
|
|
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
|
|
|
|
SUITE(CVTracker_Tests)
|
|
|
|
|
{
|
|
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Just for the tracker constructor, it won't be used
|
|
|
|
|
ProcessingController processingController;
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
TEST(Track_Video)
|
2020-06-28 16:54:11 -03:00
|
|
|
{
|
2020-07-16 21:10:02 -03:00
|
|
|
// Create a video clip
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << TEST_MEDIA_PATH << "test.avi";
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Open clip
|
|
|
|
|
openshot::Clip c1(path.str());
|
|
|
|
|
c1.Open();
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Create tracker
|
|
|
|
|
CVTracker kcfTracker("{\"protobuf_data_path\": \"\", \"tracker_type\": \"KCF\", \"bbox\": {\"x\": 294, \"y\": 102, \"w\": 180, \"h\": 166}}", processingController);
|
|
|
|
|
|
|
|
|
|
// Track clip for frames 0-20
|
2020-07-26 16:19:55 -03:00
|
|
|
kcfTracker.trackClip(c1, 0, 20, true);
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Get tracked data
|
|
|
|
|
FrameData fd = kcfTracker.GetTrackedData(20);
|
|
|
|
|
|
2020-07-30 21:39:20 -03:00
|
|
|
float x = fd.x1;
|
|
|
|
|
float y = fd.y1;
|
|
|
|
|
float width = fd.x2 - x;
|
|
|
|
|
float height = fd.y2 - y;
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Compare if tracked data is equal to pre-tested ones
|
2020-07-30 21:39:20 -03:00
|
|
|
CHECK_EQUAL(259, (int)(x * 640));
|
|
|
|
|
CHECK_EQUAL(131, (int)(y * 360));
|
|
|
|
|
CHECK_EQUAL(180, (int)(width * 640));
|
|
|
|
|
CHECK_EQUAL(166, (int)(height * 360));
|
2020-07-16 21:10:02 -03:00
|
|
|
}
|
2020-06-28 16:54:11 -03:00
|
|
|
|
|
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
TEST(SaveLoad_Protobuf)
|
2020-06-28 16:54:11 -03:00
|
|
|
{
|
|
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Create a video clip
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << TEST_MEDIA_PATH << "test.avi";
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Open clip
|
|
|
|
|
openshot::Clip c1(path.str());
|
|
|
|
|
c1.Open();
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Create first tracker
|
|
|
|
|
CVTracker kcfTracker_1("{\"protobuf_data_path\": \"kcf_tracker.data\", \"tracker_type\": \"KCF\", \"bbox\": {\"x\": 294, \"y\": 102, \"w\": 180, \"h\": 166}}", processingController);
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Track clip for frames 0-20
|
2020-07-26 16:19:55 -03:00
|
|
|
kcfTracker_1.trackClip(c1, 0, 20, true);
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Get tracked data
|
|
|
|
|
FrameData fd_1 = kcfTracker_1.GetTrackedData(20);
|
|
|
|
|
|
2020-07-30 21:39:20 -03:00
|
|
|
float x_1 = fd_1.x1;
|
|
|
|
|
float y_1 = fd_1.y1;
|
|
|
|
|
float width_1 = fd_1.x2 - x_1;
|
|
|
|
|
float height_1 = fd_1.y2 - y_1;
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Save tracked data
|
|
|
|
|
kcfTracker_1.SaveTrackedData();
|
|
|
|
|
|
|
|
|
|
// Create second tracker
|
|
|
|
|
CVTracker kcfTracker_2("{\"protobuf_data_path\": \"kcf_tracker.data\", \"tracker_type\": \"\", \"bbox\": {\"x\": -1, \"y\": -1, \"w\": -1, \"h\": -1}}", processingController);
|
|
|
|
|
|
|
|
|
|
// Load tracked data from first tracker protobuf data
|
2020-07-30 21:39:20 -03:00
|
|
|
kcfTracker_2._LoadTrackedData();
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Get tracked data
|
|
|
|
|
FrameData fd_2 = kcfTracker_2.GetTrackedData(20);
|
|
|
|
|
|
2020-07-30 21:39:20 -03:00
|
|
|
float x_2 = fd_2.x1;
|
|
|
|
|
float y_2 = fd_2.y1;
|
|
|
|
|
float width_2 = fd_2.x2 - x_2;
|
|
|
|
|
float height_2 = fd_2.y2 - y_2;
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Compare first tracker data with second tracker data
|
2020-07-30 21:39:20 -03:00
|
|
|
CHECK_EQUAL((int)(x_1 * 640), (int)(x_2 * 640));
|
|
|
|
|
CHECK_EQUAL((int)(y_1 * 360), (int)(y_2 * 360));
|
|
|
|
|
CHECK_EQUAL((int)(width_1 * 640), (int)(width_2 * 640));
|
|
|
|
|
CHECK_EQUAL((int)(height_1 * 360), (int)(height_2 * 360));
|
2020-07-16 21:10:02 -03:00
|
|
|
}
|
2020-06-28 16:54:11 -03:00
|
|
|
|
|
|
|
|
} // SUITE(Frame_Tests)
|