Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Jul 2, 2020
1 parent a85e45b commit b7e5fb7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/CVStabilization.cpp
@@ -1,5 +1,9 @@
#include "../include/CVStabilization.h"

CVStabilization::CVStabilization(){

}

void CVStabilization::ProcessVideo(openshot::Clip &video){
// Make sure Clip is opened
video.Open();
Expand Down Expand Up @@ -29,7 +33,7 @@ void CVStabilization::ProcessVideo(openshot::Clip &video){

vector <TransformParam> new_prev_to_cur_transform = GenNewCamPosition(smoothed_trajectory);

ApplyNewTrajectoryToVideo(video, new_prev_to_cur_transform);
ApplyNewTrajectoryToClip(video, new_prev_to_cur_transform);
}

// Track current frame features and find the relative transformation
Expand Down Expand Up @@ -160,7 +164,7 @@ vector <TransformParam> CVStabilization::GenNewCamPosition(vector <CamTrajectory
return new_prev_to_cur_transform;
}

// Send smoothed camera transformation to be applyed on clip
// Send smoothed camera transformation to be applyed on clip
void CVStabilization::ApplyNewTrajectoryToClip(openshot::Clip &video, vector <TransformParam> &new_prev_to_cur_transform){

video.new_prev_to_cur_transform = new_prev_to_cur_transform;
Expand Down
12 changes: 9 additions & 3 deletions src/Clip.cpp
Expand Up @@ -386,11 +386,17 @@ void Clip::apply_stabilization(std::shared_ptr<openshot::Frame> f, int64_t frame
T.at<double>(0,2) = new_prev_to_cur_transform[frame_number].dx;
T.at<double>(1,2) = new_prev_to_cur_transform[frame_number].dy;

cv::Mat cur2;
cv::Mat frame_stabilized;

cv::warpAffine(cur, cur2, T, cur.size());
cv::warpAffine(cur, frame_stabilized, T, cur.size());

f->SetImageCV(cur2);
// Scale up the image to remove black borders
cv::Mat T_scale = cv::getRotationMatrix2D(cv::Point2f(frame_stabilized.cols/2, frame_stabilized.rows/2), 0, 1.04);
cv::warpAffine(frame_stabilized, frame_stabilized, T_scale, frame_stabilized.size());

f->SetImageCV(frame_stabilized);


}

// Get file extension
Expand Down
2 changes: 1 addition & 1 deletion src/examples/Example_opencv.cpp
Expand Up @@ -136,7 +136,7 @@ void displayStabilization(openshot::Clip &r9){
// Grab Mat image
cv::Mat cvimage = f->GetImageCV();

cv::imshow("Display Image1", cvimage);
cv::imshow("Display Image", cvimage);
// Press ESC on keyboard to exit
char c=(char)cv::waitKey(25);
if(c==27)
Expand Down

0 comments on commit b7e5fb7

Please sign in to comment.