Skip to content

Commit

Permalink
Fixed FPS ToInt() conversion and changed initial frame number to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Apr 16, 2021
1 parent c27071b commit 77aa418
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/CVObjectDetection.cpp
Expand Up @@ -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++)
Expand Down
10 changes: 5 additions & 5 deletions src/CVStabilization.cpp
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/CVTracker.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions tests/CVObjectDetection.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/CVStabilizer.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/CVTracker.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -94,15 +94,15 @@ 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";


// Create first 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);
Expand All @@ -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
Expand Down

0 comments on commit 77aa418

Please sign in to comment.