|
| 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) |
0 commit comments