Skip to content

Commit

Permalink
Protobuf messages now compile with Cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Jul 21, 2020
1 parent df328ef commit b2721c0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
10 changes: 3 additions & 7 deletions include/CVStabilization.h
Expand Up @@ -79,18 +79,18 @@ struct CamTrajectory
class CVStabilization {

private:

int smoothingWindow; // In frames. The larger the more stable the video, but less reactive to sudden panning

cv::Mat last_T;
cv::Mat cur, cur_grey;
cv::Mat prev, prev_grey;
std::vector <TransformParam> prev_to_cur_transform; // Previous to current
std::string protobuf_data_path;

bool smoothingWindowSet = false;

uint progress;

/// Will handle a Thread saflly comutication between ClipProcessingJobs and the processing effect classes
/// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes
ProcessingController *processingController;

// Track current frame features and find the relative transformation
Expand All @@ -104,16 +104,12 @@ class CVStabilization {

public:

int smoothingWindow; // In frames. The larger the more stable the video, but less reactive to sudden panning
std::map <size_t,CamTrajectory> trajectoryData; // Save camera trajectory data
std::map <size_t,TransformParam> transformationData; // Save transormation data

// Set default smoothing window value to compute stabilization
CVStabilization(std::string processInfoJson, ProcessingController &processingController);

// Set desirable smoothing window value to compute stabilization
void setSmoothingWindow(int _smoothingWindow);

// Process clip and store necessary stabilization data
void stabilizeClip(openshot::Clip& video, size_t start=0, size_t end=0, bool process_interval=false);

Expand Down
2 changes: 1 addition & 1 deletion include/CVTracker.h
Expand Up @@ -61,7 +61,7 @@ class CVTracker {

uint progress; // Pre-processing effect progress

/// Will handle a Thread saflly comutication between ClipProcessingJobs and the processing effect classes
/// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes
ProcessingController *processingController;

// Initialize the tracker
Expand Down
2 changes: 1 addition & 1 deletion include/ClipProcessingJobs.h
Expand Up @@ -59,7 +59,7 @@ class ClipProcessingJobs{

std::thread t;

/// Will handle a Thread saflly comutication between ClipProcessingJobs and the processing effect classes
/// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes
ProcessingController processingController;

// Apply object tracking to clip
Expand Down
2 changes: 1 addition & 1 deletion include/effects/Stabilizer.h
Expand Up @@ -41,7 +41,7 @@
#include "../Color.h"
#include "../Json.h"
#include "../KeyFrame.h"
#include "../stabilizedata.pb.h"
#include "stabilizedata.pb.h"

using namespace std;
using google::protobuf::util::TimeUtil;
Expand Down
2 changes: 1 addition & 1 deletion include/effects/Tracker.h
Expand Up @@ -42,7 +42,7 @@
#include "../Color.h"
#include "../Json.h"
#include "../KeyFrame.h"
#include "../trackerdata.pb.h"
#include "trackerdata.pb.h"

using namespace std;
using google::protobuf::util::TimeUtil;
Expand Down
28 changes: 26 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -97,6 +97,29 @@ if (OpenCV_FOUND)
endif()

include_directories(${PROTOBUF_INCLUDE_DIR})

set(PROTOBUF_MESSAGES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/protobuf_messages")

FILE(GLOB PROTO_MSGS "${PROTOBUF_MESSAGES_FOLDER}/*.proto")
foreach(PROTO_MSG ${PROTO_MSGS})
execute_process (
COMMAND bash -c "${PROTOBUF_PROTOC_EXECUTABLE} -I=${PROTOBUF_MESSAGES_FOLDER} --cpp_out=${PROTOBUF_MESSAGES_FOLDER} ${PROTO_MSG}"
)
endforeach()

FILE(GLOB PROTO_CCS "${PROTOBUF_MESSAGES_FOLDER}/*.pb.cc")
foreach(PROTO_CC ${PROTO_CCS})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${PROTO_CC} ${CMAKE_CURRENT_SOURCE_DIR})
file(REMOVE ${PROTO_CC})
endforeach()

FILE(GLOB PROTO_HS "${PROTOBUF_MESSAGES_FOLDER}/*.pb.h")
foreach(PROTO_H ${PROTO_HS})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${PROTO_H} ${CMAKE_CURRENT_SOURCE_DIR}/../include)
file(REMOVE ${PROTO_H})
endforeach()


endif()

################# LIBOPENSHOT-AUDIO ###################
Expand Down Expand Up @@ -195,8 +218,9 @@ set(OPENSHOT_CV_SOURCES

# Compiled Protobuf messages
set(PROTOBUF_MESSAGES
trackerdata.pb.cc
stabilizedata.pb.cc)
stabilizedata.pb.cc
trackerdata.pb.cc
)

# Video effects
set(EFFECTS_SOURCES
Expand Down
16 changes: 5 additions & 11 deletions src/CVStabilization.cpp
Expand Up @@ -32,16 +32,14 @@

// Set default smoothing window value to compute stabilization
CVStabilization::CVStabilization(std::string processInfoJson, ProcessingController &processingController)
: smoothingWindow(30), processingController(&processingController){
: processingController(&processingController){
SetJson(processInfoJson);
}

// Process clip and store necessary stabilization data
void CVStabilization::stabilizeClip(openshot::Clip& video, size_t start, size_t end, bool process_interval){
size_t frame_number;

smoothingWindowSet = true; // Certificate that smoothing window value won't change

size_t frame_number;
if(!process_interval || end == 0 || end-start <= 0){
// Get total number of frames in video
end = video.Reader()->info.video_length;
Expand Down Expand Up @@ -351,11 +349,7 @@ void CVStabilization::SetJsonValue(const Json::Value root) {
if (!root["protobuf_data_path"].isNull()){
protobuf_data_path = (root["protobuf_data_path"].asString());
}
}

// Set desirable smoothing window value to compute stabilization
void CVStabilization::setSmoothingWindow(int _smoothingWindow){
if(!smoothingWindowSet)
smoothingWindow = _smoothingWindow;
smoothingWindowSet = true;
if (!root["smoothing_window"].isNull()){
smoothingWindow = (root["smoothing_window"].asInt());
}
}
4 changes: 2 additions & 2 deletions src/CVTracker.cpp
Expand Up @@ -64,15 +64,15 @@ cv::Ptr<cv::Tracker> CVTracker::selectTracker(std::string trackerType){
void CVTracker::trackClip(openshot::Clip& video, size_t start, size_t end, bool process_interval){

bool trackerInit = false;
size_t frame;

size_t frame;
if(!process_interval || end == 0 || end-start <= 0){
// Get total number of frames in video
end = video.Reader()->info.video_length;
}

// Loop through video
for (frame = start; frame < end; frame++)
for (frame = start; frame <= end; frame++)
{

// Stop the feature tracker process
Expand Down

0 comments on commit b2721c0

Please sign in to comment.