From 111883e23e8456ac1c6396bf87a0585b7b87a33e Mon Sep 17 00:00:00 2001 From: Brenno Date: Thu, 5 Nov 2020 12:23:08 -0300 Subject: [PATCH] Applied code review suggestions --- .gitignore | 1 - src/CMakeLists.txt | 4 ++-- tests/CMakeLists.txt | 40 ++++++++++++++++++++------------------- tests/CVTracker_Tests.cpp | 36 ++++++++++++++++++++++++++++++++--- tests/Frame_Tests.cpp | 2 +- 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 09a42bc3..5d00d580 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ tags *~ -.vscode/ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b338ef6..6c1d03f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -400,8 +400,8 @@ endif() find_package( OpenCV 4 ) if (OpenCV_FOUND) message("\nCOMPILING WITH OPENCV\n") - set(CMAKE_SWIG_FLAGS "-DUSE_OPENCV=1") - add_definitions( -DUSE_OPENCV=1 ) + list(APPEND CMAKE_SWIG_FLAGS -DUSE_OPENCV=1) + target_compile_definitions(openshot PUBLIC USE_OPENCV=1) else() message("\nOPENCV NOT FOUND, SOME FUNCTIONALITIES WILL BE DISABLED\n") endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 419b9750..ad1d3b9b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -95,32 +95,34 @@ set(OPENSHOT_TEST_FILES Timeline_Tests.cpp) ########## SET OPENCV RELATED TEST FILES ############### -set(OPENSHOT_CV_TEST_FILES - CVTracker_Tests.cpp - CVStabilizer_Tests.cpp - # CVObjectDetection_Tests.cpp +if(OpenCV_FOUND) + set(OPENSHOT_CV_TEST_FILES + CVTracker_Tests.cpp + CVStabilizer_Tests.cpp + # CVObjectDetection_Tests.cpp + ) + set(OPENSHOT_CV_LIBRARIES + ${OpenCV_LIBS} + ${PROTOBUF_LIBRARY} ) +endif() ################ TESTER EXECUTABLE ################# # Create unit test executable (openshot-test) message (STATUS "Tests enabled, test executable will be built as tests/openshot-test") -if (OpenCV_FOUND) - add_executable(openshot-test - tests.cpp - ${OPENSHOT_TEST_FILES} - ${OPENSHOT_CV_TEST_FILES}) - - # Link libraries to the new executable - target_link_libraries(openshot-test openshot ${UnitTest++_LIBRARIES} ${OpenCV_LIBS} ${PROTOBUF_LIBRARY}) -else() - add_executable(openshot-test - tests.cpp - ${OPENSHOT_TEST_FILES} ) +add_executable(openshot-test + tests.cpp + ${OPENSHOT_TEST_FILES} + ${OPENSHOT_CV_TEST_FILES} + ) - # Link libraries to the new executable - target_link_libraries(openshot-test openshot ${UnitTest++_LIBRARIES}) -endif() +# Link libraries to the new executable +target_link_libraries(openshot-test + openshot + ${UnitTest++_LIBRARIES} + ${OPENSHOT_CV_LIBRARIES} + ) ##### RUNNING TESTS (make os_test / make test) ##### # Hook up the 'make os_test' target to the 'openshot-test' executable diff --git a/tests/CVTracker_Tests.cpp b/tests/CVTracker_Tests.cpp index c6620208..3ec36b01 100644 --- a/tests/CVTracker_Tests.cpp +++ b/tests/CVTracker_Tests.cpp @@ -54,8 +54,18 @@ SUITE(CVTracker_Tests) openshot::Clip c1(path.str()); c1.Open(); + std::string proto_data = R"proto( + { + "protobuf_data_path": "", + "tracker-type": "KCF", + "region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 0} + } )proto"; + // Create tracker - CVTracker kcfTracker("{\"protobuf_data_path\": \"\", \"tracker-type\": \"KCF\", \"region\": {\"x\": 294, \"y\": 102, \"width\": 180, \"height\": 166, \"first-frame\": 0}}", processingController); + //CVTracker kcfTracker("{\"protobuf_data_path\": \"\", \"tracker_type\": \"KCF\", \"bbox\": {\"x\": 294, \"y\": 102, \"w\": 180, \"h\": 166}, \"first_frame\": 0}", processingController); + CVTracker kcfTracker(proto_data, processingController); + + // Track clip for frames 0-20 kcfTracker.trackClip(c1, 0, 20, true); // Get tracked data @@ -84,8 +94,18 @@ SUITE(CVTracker_Tests) openshot::Clip c1(path.str()); c1.Open(); + std::string proto_data = R"proto( + { + "protobuf_data_path": "kcf_tracker.data", + "tracker_type": "KCF", + "bbox": {"x": 294, "y": 102, "w": 180, "h": 166}, + "first_frame": 0 + } )proto"; + // Create first tracker - CVTracker kcfTracker_1("{\"protobuf_data_path\": \"kcf_tracker.data\", \"tracker-type\": \"KCF\", \"region\": {\"x\": 294, \"y\": 102, \"width\": 180, \"height\": 166, \"first-frame\": 0}}", processingController); + //CVTracker kcfTracker_1("{\"protobuf_data_path\": \"kcf_tracker.data\", \"tracker_type\": \"KCF\", \"bbox\": {\"x\": 294, \"y\": 102, \"w\": 180, \"h\": 166}, \"first_frame\": 0}", processingController); + CVTracker kcfTracker_1(proto_data, processingController); + // Track clip for frames 0-20 kcfTracker_1.trackClip(c1, 0, 20, true); @@ -101,8 +121,18 @@ SUITE(CVTracker_Tests) // Save tracked data kcfTracker_1.SaveTrackedData(); + std::string proto_data_1 = R"proto( + { + "protobuf_data_path": "kcf_tracker.data", + "tracker_type": "", + "bbox": {"x": -1, "y": -1, "w": -1, "h": -1}, + "first_frame": 0 + } )proto"; + // Create second tracker - CVTracker kcfTracker_2("{\"protobuf_data_path\": \"kcf_tracker.data\", \"tracker-type\": \"\", \"region\": {\"x\": -1, \"y\": -1, \"width\": -1, \"height\": -1, \"first-frame\": 0}}", processingController); + //CVTracker kcfTracker_2("{\"protobuf_data_path\": \"kcf_tracker.data\", \"tracker_type\": \"\", \"bbox\": {\"x\": -1, \"y\": -1, \"w\": -1, \"h\": -1}, \"first_frame\": 0}", processingController); + CVTracker kcfTracker_2(proto_data_1, processingController); + // Load tracked data from first tracker protobuf data kcfTracker_2._LoadTrackedData(); diff --git a/tests/Frame_Tests.cpp b/tests/Frame_Tests.cpp index c61d7f84..e5562523 100644 --- a/tests/Frame_Tests.cpp +++ b/tests/Frame_Tests.cpp @@ -157,7 +157,7 @@ TEST(Convert_Image) c1.Open(); // Get first frame - std::shared_ptr f1 = c1.GetFrame(1); + auto f1 = c1.GetFrame(1); // Get first Mat image cv::Mat cvimage = f1->GetImageCV();