From 77aa418353440856de2bade89f48c9ef083a2b70 Mon Sep 17 00:00:00 2001 From: Brenno Date: Thu, 15 Apr 2021 21:52:02 -0300 Subject: [PATCH] Fixed FPS ToInt() conversion and changed initial frame number to 1 --- src/CVObjectDetection.cpp | 6 +++--- src/CVStabilization.cpp | 10 +++++----- src/CVTracker.cpp | 14 +++++++------- tests/CVObjectDetection.cpp | 4 ++-- tests/CVStabilizer.cpp | 4 ++-- tests/CVTracker.cpp | 10 +++++----- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/CVObjectDetection.cpp b/src/CVObjectDetection.cpp index 53533cbf..3fddb93f 100644 --- a/src/CVObjectDetection.cpp +++ b/src/CVObjectDetection.cpp @@ -78,10 +78,10 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, setProcessingDevice(); size_t frame_number; - if(!process_interval || end == 0 || end-start == 0){ + if(!process_interval || end <= 1 || end-start == 0){ // Get total number of frames in video - start = video.Start() * video.Reader()->info.fps.ToInt(); - end = video.End() * video.Reader()->info.fps.ToInt(); + start = (int)(video.Start() * video.Reader()->info.fps.ToFloat()) + 1; + end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1; } for (frame_number = start; frame_number <= end; frame_number++) diff --git a/src/CVStabilization.cpp b/src/CVStabilization.cpp index 3076ada8..75eff536 100644 --- a/src/CVStabilization.cpp +++ b/src/CVStabilization.cpp @@ -39,8 +39,8 @@ using google::protobuf::util::TimeUtil; CVStabilization::CVStabilization(std::string processInfoJson, ProcessingController &processingController) : processingController(&processingController){ SetJson(processInfoJson); - start = 0; - end = 0; + start = 1; + end = 1; } // Process clip and store necessary stabilization data @@ -60,10 +60,10 @@ void CVStabilization::stabilizeClip(openshot::Clip& video, size_t _start, size_t cv::Size readerDims(video.Reader()->info.width, video.Reader()->info.height); size_t frame_number; - if(!process_interval || end == 0 || end-start == 0){ + if(!process_interval || end <= 1 || end-start == 0){ // Get total number of frames in video - start = video.Start() * video.Reader()->info.fps.ToInt(); - end = video.End() * video.Reader()->info.fps.ToInt(); + start = (int)(video.Start() * video.Reader()->info.fps.ToFloat()) + 1; + end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1; } // Extract and track opticalflow features for each frame diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index ee29894a..f300c2d7 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -40,8 +40,8 @@ using google::protobuf::util::TimeUtil; CVTracker::CVTracker(std::string processInfoJson, ProcessingController &processingController) : processingController(&processingController), json_interval(false){ SetJson(processInfoJson); - start = 0; - end = 0; + start = 1; + end = 1; } // Set desirable tracker method @@ -73,15 +73,15 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo if(!json_interval){ start = _start; end = _end; - if(!process_interval || end <= 0 || end-start == 0){ + if(!process_interval || end <= 1 || end-start == 0){ // Get total number of frames in video - start = video.Start() * video.Reader()->info.fps.ToInt(); - end = video.End() * video.Reader()->info.fps.ToInt(); + start = (int)(video.Start() * video.Reader()->info.fps.ToFloat()) + 1; + end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1; } } else{ - start = start + video.Start() * video.Reader()->info.fps.ToInt(); - end = video.End() * video.Reader()->info.fps.ToInt(); + start = (int)(start + video.Start() * video.Reader()->info.fps.ToFloat()) + 1; + end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1; } if(error){ diff --git a/tests/CVObjectDetection.cpp b/tests/CVObjectDetection.cpp index ce948074..688581c5 100644 --- a/tests/CVObjectDetection.cpp +++ b/tests/CVObjectDetection.cpp @@ -62,7 +62,7 @@ TEST_CASE( "DetectObject_Video", "[libopenshot][opencv][objectdetection]" ) //TODO remove hardcoded path CVObjectDetection objectDetector(effectInfo, processingController); - objectDetector.detectObjectsClip(c1, 0, 20, true); + objectDetector.detectObjectsClip(c1, 1, 20, true); CVDetectionData dd = objectDetector.GetDetectionData(20); @@ -97,7 +97,7 @@ TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][objectdetection]" ) //TODO remove hardcoded path CVObjectDetection objectDetector_1(effectInfo ,processingController); - objectDetector_1.detectObjectsClip(c1, 0, 20, true); + objectDetector_1.detectObjectsClip(c1, 1, 20, true); CVDetectionData dd_1 = objectDetector_1.GetDetectionData(20); diff --git a/tests/CVStabilizer.cpp b/tests/CVStabilizer.cpp index ed3e5403..61b9f626 100644 --- a/tests/CVStabilizer.cpp +++ b/tests/CVStabilizer.cpp @@ -62,7 +62,7 @@ TEST_CASE( "Stabilize_Video", "[libopenshot][opencv][stabilizer]" ) CVStabilization stabilizer(json_data, stabilizer_pc); // Stabilize clip for frames 0-21 - stabilizer.stabilizeClip(c1, 0, 21, true); + stabilizer.stabilizeClip(c1, 1, 21, true); // Get stabilized data TransformParam tp = stabilizer.GetTransformParamData(20); @@ -106,7 +106,7 @@ TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][stabilizer]" ) CVStabilization stabilizer_1(json_data, stabilizer_pc); // Stabilize clip for frames 0-20 - stabilizer_1.stabilizeClip(c1, 0, 20+1, true); + stabilizer_1.stabilizeClip(c1, 1, 20+1, true); // Get stabilized data TransformParam tp_1 = stabilizer_1.GetTransformParamData(20); diff --git a/tests/CVTracker.cpp b/tests/CVTracker.cpp index 9548fc38..2bc87888 100644 --- a/tests/CVTracker.cpp +++ b/tests/CVTracker.cpp @@ -56,14 +56,14 @@ TEST_CASE( "Track_Video", "[libopenshot][opencv][tracker]" ) { "protobuf_data_path": "kcf_tracker.data", "tracker-type": "KCF", - "region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 0} + "region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 1} } )proto"; // Create tracker CVTracker kcfTracker(json_data, tracker_pc); // Track clip for frames 0-20 - kcfTracker.trackClip(c1, 0, 20, true); + kcfTracker.trackClip(c1, 1, 20, true); // Get tracked data FrameData fd = kcfTracker.GetTrackedData(20); float x = fd.x1; @@ -94,7 +94,7 @@ TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][tracker]" ) { "protobuf_data_path": "kcf_tracker.data", "tracker-type": "KCF", - "region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 0} + "region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 1} } )proto"; @@ -102,7 +102,7 @@ TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][tracker]" ) CVTracker kcfTracker_1(json_data, tracker_pc); // Track clip for frames 0-20 - kcfTracker_1.trackClip(c1, 0, 20, true); + kcfTracker_1.trackClip(c1, 1, 20, true); // Get tracked data FrameData fd_1 = kcfTracker_1.GetTrackedData(20); @@ -119,7 +119,7 @@ TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][tracker]" ) { "protobuf_data_path": "kcf_tracker.data", "tracker_type": "", - "region": {"x": -1, "y": -1, "width": -1, "height": -1, "first-frame": 0} + "region": {"x": -1, "y": -1, "width": -1, "height": -1, "first-frame": 1} } )proto"; // Create second tracker