diff --git a/src/CVObjectDetection.cpp b/src/CVObjectDetection.cpp index a4e92e0d..0ac0a0ba 100644 --- a/src/CVObjectDetection.cpp +++ b/src/CVObjectDetection.cpp @@ -30,6 +30,7 @@ #include "CVObjectDetection.h" +using namespace std; using namespace openshot; CVObjectDetection::CVObjectDetection(std::string processInfoJson, ProcessingController &processingController) @@ -58,9 +59,9 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, if(error){ return; } - + processingController->SetError(false, ""); - + // Load names of classes std::ifstream ifs(classesFile.c_str()); std::string line; @@ -90,7 +91,7 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, } std::shared_ptr f = video.GetFrame(frame_number); - + // Grab OpenCV Mat image cv::Mat cvimage = f->GetImageCV(); @@ -104,7 +105,7 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, } void CVObjectDetection::DetectObjects(const cv::Mat &frame, size_t frameId){ - // Get frame as OpenCV Mat + // Get frame as OpenCV Mat cv::Mat blob; // Create a 4D blob from the frame. @@ -112,10 +113,10 @@ void CVObjectDetection::DetectObjects(const cv::Mat &frame, size_t frameId){ inpWidth = inpHeight = 416; cv::dnn::blobFromImage(frame, blob, 1/255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0,0,0), true, false); - + //Sets the input to the network net.setInput(blob); - + // Runs the forward pass to get output of the output layers std::vector outs; net.forward(outs, getOutputsNames(net)); @@ -132,7 +133,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector std::vector classIds; std::vector confidences; std::vector boxes; - + for (size_t i = 0; i < outs.size(); ++i) { // Scan through all the bounding boxes output from the network and keep only the @@ -154,14 +155,14 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector int height = (int)(data[3] * frameDims.height); int left = centerX - width / 2; int top = centerY - height / 2; - + classIds.push_back(classIdPoint.x); confidences.push_back((float)confidence); boxes.push_back(cv::Rect(left, top, width, height)); } } } - + // Perform non maximum suppression to eliminate redundant overlapping boxes with // lower confidences std::vector indices; @@ -189,7 +190,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector for(uint j = i+1; j= confidences[j]){ @@ -213,7 +214,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector // Remove boxes based in IOU score for(uint i = 0; i= confidences[j]){ @@ -233,7 +234,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector } } } - + // Normalize boxes coordinates std::vector> normalized_boxes; for(auto box : boxes){ @@ -244,7 +245,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector normalized_box.height = (box.height)/(float)frameDims.height; normalized_boxes.push_back(normalized_box); } - + detectionsData[frameId] = CVDetectionData(classIds, confidences, normalized_boxes, frameId); } @@ -276,13 +277,13 @@ bool CVObjectDetection::iou(cv::Rect pred_box, cv::Rect sort_box){ std::vector CVObjectDetection::getOutputsNames(const cv::dnn::Net& net) { static std::vector names; - + //Get the indices of the output layers, i.e. the layers with unconnected outputs std::vector outLayers = net.getUnconnectedOutLayers(); - + //get the names of all the layers in the network std::vector layersNames = net.getLayerNames(); - + // Get the names of the output layers in names names.resize(outLayers.size()); for (size_t i = 0; i < outLayers.size(); ++i) @@ -293,10 +294,10 @@ std::vector CVObjectDetection::getOutputsNames(const cv::dnn::Net& n CVDetectionData CVObjectDetection::GetDetectionData(size_t frameId){ // Check if the stabilizer info for the requested frame exists if ( detectionsData.find(frameId) == detectionsData.end() ) { - + return CVDetectionData(); } else { - + return detectionsData[frameId]; } } @@ -386,13 +387,13 @@ void CVObjectDetection::SetJsonValue(const Json::Value root) { processingDevice = (root["processing-device"].asString()); } if (!root["model-config"].isNull()){ - modelConfiguration = (root["model-config"].asString()); + modelConfiguration = (root["model-config"].asString()); std::ifstream infile(modelConfiguration); if(!infile.good()){ processingController->SetError(true, "Incorrect path to model config file"); error = true; } - + } if (!root["model-weights"].isNull()){ modelWeights= (root["model-weights"].asString()); @@ -424,7 +425,7 @@ void CVObjectDetection::SetJsonValue(const Json::Value root) { // Load protobuf data file bool CVObjectDetection::_LoadObjDetectdData(){ // Create tracker message - libopenshotobjdetect::ObjDetect objMessage; + libopenshotobjdetect::ObjDetect objMessage; { // Read the existing tracker message. @@ -453,7 +454,7 @@ bool CVObjectDetection::_LoadObjDetectdData(){ // Load bounding box data const google::protobuf::RepeatedPtrField &pBox = pbFrameData.bounding_box(); - + // Construct data vectors related to detections in the current frame std::vector classIds; std::vector confidences; std::vector> boxes; @@ -475,8 +476,8 @@ bool CVObjectDetection::_LoadObjDetectdData(){ detectionsData[id] = CVDetectionData(classIds, confidences, boxes, id); } - // Show the time stamp from the last update in object detector data file - if (objMessage.has_last_updated()) + // Show the time stamp from the last update in object detector data file + if (objMessage.has_last_updated()) cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(objMessage.last_updated()) << endl; // Delete all global objects allocated by libprotobuf. diff --git a/src/CVObjectDetection.h b/src/CVObjectDetection.h index 30b19ce6..ad8d9158 100644 --- a/src/CVObjectDetection.h +++ b/src/CVObjectDetection.h @@ -67,13 +67,13 @@ namespace openshot /** * @brief This class runs trought a clip to detect objects and returns the bounding boxes and its properties. - * - * Object detection is performed using YoloV3 model with OpenCV DNN module + * + * Object detection is performed using YoloV3 model with OpenCV DNN module */ class CVObjectDetection{ private: - + cv::dnn::Net net; std::vector classNames; float confThreshold, nmsThreshold; @@ -97,7 +97,7 @@ namespace openshot ProcessingController *processingController; void setProcessingDevice(); - + // Detect onbects on a single frame void DetectObjects(const cv::Mat &frame, size_t frame_number); diff --git a/src/CVStabilization.cpp b/src/CVStabilization.cpp index 6e647f19..e115d0dd 100644 --- a/src/CVStabilization.cpp +++ b/src/CVStabilization.cpp @@ -30,10 +30,11 @@ #include "CVStabilization.h" +using namespace std; using namespace openshot; -// Set default smoothing window value to compute stabilization +// Set default smoothing window value to compute stabilization CVStabilization::CVStabilization(std::string processInfoJson, ProcessingController &processingController) : processingController(&processingController){ SetJson(processInfoJson); @@ -52,7 +53,7 @@ void CVStabilization::stabilizeClip(openshot::Clip& video, size_t _start, size_t avr_dx=0; avr_dy=0; avr_da=0; max_dx=0; max_dy=0; max_da=0; video.Open(); - // Save original video width and height + // Save original video width and height cv::Size readerDims(video.Reader()->info.width, video.Reader()->info.height); size_t frame_number; @@ -71,7 +72,7 @@ void CVStabilization::stabilizeClip(openshot::Clip& video, size_t _start, size_t } std::shared_ptr f = video.GetFrame(frame_number); - + // Grab OpenCV Mat image cv::Mat cvimage = f->GetImageCV(); // Resize frame to original video width and height if they differ @@ -174,7 +175,7 @@ bool CVStabilization::TrackFrameFeatures(cv::Mat frame, size_t frameNum){ return false; } - // Keep computing average and max transformation parameters + // Keep computing average and max transformation parameters avr_dx+=fabs(dx); avr_dy+=fabs(dy); avr_da+=fabs(da); @@ -184,7 +185,7 @@ bool CVStabilization::TrackFrameFeatures(cv::Mat frame, size_t frameNum){ max_dy = dy; if(fabs(da) > max_da) max_da = da; - + T.copyTo(last_T); prev_to_cur_transform.push_back(TransformParam(dx, dy, da)); @@ -204,8 +205,8 @@ std::vector CVStabilization::ComputeFramesTrajectory(){ double y = 0; vector trajectory; // trajectory at all frames - - // Compute global camera trajectory. First frame is the origin + + // Compute global camera trajectory. First frame is the origin for(size_t i=0; i < prev_to_cur_transform.size(); i++) { x += prev_to_cur_transform[i].dx; y += prev_to_cur_transform[i].dy; @@ -307,7 +308,7 @@ bool CVStabilization::SaveStabilizedData(){ // Add frame stabilization data into protobuf message void CVStabilization::AddFrameDataToProto(libopenshotstabilize::Frame* pbFrameData, CamTrajectory& trajData, TransformParam& transData, size_t frame_number){ - // Save frame number + // Save frame number pbFrameData->set_id(frame_number); // Save camera trajectory data @@ -325,10 +326,10 @@ TransformParam CVStabilization::GetTransformParamData(size_t frameId){ // Check if the stabilizer info for the requested frame exists if ( transformationData.find(frameId) == transformationData.end() ) { - + return TransformParam(); } else { - + return transformationData[frameId]; } } @@ -337,10 +338,10 @@ CamTrajectory CVStabilization::GetCamTrajectoryTrackedData(size_t frameId){ // Check if the stabilizer info for the requested frame exists if ( trajectoryData.find(frameId) == trajectoryData.end() ) { - + return CamTrajectory(); } else { - + return trajectoryData[frameId]; } } @@ -395,11 +396,11 @@ bool CVStabilization::_LoadStabilizedData(){ transformationData.clear(); trajectoryData.clear(); - // Iterate over all frames of the saved message and assign to the data maps + // Iterate over all frames of the saved message and assign to the data maps for (size_t i = 0; i < stabilizationMessage.frame_size(); i++) { const libopenshotstabilize::Frame& pbFrameData = stabilizationMessage.frame(i); - - // Load frame number + + // Load frame number size_t id = pbFrameData.id(); // Load camera trajectory data @@ -419,7 +420,7 @@ bool CVStabilization::_LoadStabilizedData(){ transformationData[id] = TransformParam(dx,dy,da); } - // Show the time stamp from the last update in stabilization data file + // Show the time stamp from the last update in stabilization data file if (stabilizationMessage.has_last_updated()) { cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(stabilizationMessage.last_updated()) << endl; } @@ -428,4 +429,4 @@ bool CVStabilization::_LoadStabilizedData(){ google::protobuf::ShutdownProtobufLibrary(); return true; -} \ No newline at end of file +} diff --git a/src/CVStabilization.h b/src/CVStabilization.h index 4c40b811..68dd40f9 100644 --- a/src/CVStabilization.h +++ b/src/CVStabilization.h @@ -45,7 +45,6 @@ #include "Clip.h" #include "Json.h" -using namespace std; using google::protobuf::util::TimeUtil; // Store the relative transformation parameters between consecutive frames @@ -82,22 +81,22 @@ struct CamTrajectory /** * @brief This class stabilizes a video frame using optical flow * - * The relative motion between two consecutive frames is computed to obtain the global camera trajectory. + * The relative motion between two consecutive frames is computed to obtain the global camera trajectory. * The camera trajectory is then smoothed to reduce jittering. */ -class CVStabilization { +class CVStabilization { private: int smoothingWindow; // In frames. The larger the more stable the video, but less reactive to sudden panning - + size_t start; size_t end; double avr_dx, avr_dy, avr_da, max_dx, max_dy, max_da; - + cv::Mat last_T; cv::Mat prev_grey; - std::vector prev_to_cur_transform; // Previous to current + std::vector prev_to_cur_transform; // Previous to current std::string protobuf_data_path; uint progress; @@ -108,7 +107,7 @@ class CVStabilization { // Track current frame features and find the relative transformation bool TrackFrameFeatures(cv::Mat frame, size_t frameNum); - + std::vector ComputeFramesTrajectory(); std::map SmoothTrajectory(std::vector &trajectory); @@ -120,12 +119,12 @@ class CVStabilization { std::map trajectoryData; // Save camera trajectory data std::map transformationData; // Save transormation data - // Set default smoothing window value to compute stabilization + // Set default smoothing window value to compute stabilization CVStabilization(std::string processInfoJson, ProcessingController &processingController); // Process clip and store necessary stabilization data void stabilizeClip(openshot::Clip& video, size_t _start=0, size_t _end=0, bool process_interval=false); - + /// Protobuf Save and Load methods // Save stabilization data to protobuf file bool SaveStabilizedData(); @@ -144,4 +143,4 @@ class CVStabilization { bool _LoadStabilizedData(); }; -#endif \ No newline at end of file +#endif diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index 1833c581..0066eca1 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -30,12 +30,13 @@ #include "CVTracker.h" +using namespace std; using namespace openshot; // Constructor CVTracker::CVTracker(std::string processInfoJson, ProcessingController &processingController) -: processingController(&processingController), json_interval(false){ +: processingController(&processingController), json_interval(false){ SetJson(processInfoJson); } @@ -78,11 +79,11 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo start = start + video.Start() * video.Reader()->info.fps.ToInt(); end = video.End() * video.Reader()->info.fps.ToInt(); } - + if(error){ return; - } - + } + processingController->SetError(false, ""); bool trackerInit = false; @@ -99,22 +100,22 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo size_t frame_number = frame; // Get current frame std::shared_ptr f = video.GetFrame(frame_number); - + // Grab OpenCV Mat image cv::Mat cvimage = f->GetImageCV(); // Pass the first frame to initialize the tracker if(!trackerInit){ - + // Initialize the tracker initTracker(cvimage, frame_number); trackerInit = true; } else{ - // Update the object tracker according to frame + // Update the object tracker according to frame trackerInit = trackFrame(cvimage, frame_number); - + // Draw box on image FrameData fd = GetTrackedData(frame_number); @@ -155,7 +156,7 @@ bool CVTracker::initTracker(cv::Mat &frame, size_t frameId){ return true; } -// Update the object tracker according to frame +// Update the object tracker according to frame bool CVTracker::trackFrame(cv::Mat &frame, size_t frameId){ // Update the tracking result bool ok = tracker->update(frame, bbox); @@ -170,7 +171,7 @@ bool CVTracker::trackFrame(cv::Mat &frame, size_t frameId){ std::vector bboxes = {bbox}; std::vector confidence = {1.0}; std::vector classId = {1}; - + sort.update(bboxes, frameId, sqrt(pow(frame.rows, 2) + pow(frame.cols, 2)), confidence, classId); for(auto TBox : sort.frameTrackingResult) @@ -236,15 +237,15 @@ void CVTracker::AddFrameDataToProto(libopenshottracker::Frame* pbFrameData, Fram box->set_y2(fData.y2); } -// Get tracker info for the desired frame +// Get tracker info for the desired frame FrameData CVTracker::GetTrackedData(size_t frameId){ // Check if the tracker info for the requested frame exists if ( trackedDataById.find(frameId) == trackedDataById.end() ) { - + return FrameData(); } else { - + return trackedDataById[frameId]; } @@ -269,7 +270,7 @@ void CVTracker::SetJson(const std::string value) { // Load Json::Value into this object void CVTracker::SetJsonValue(const Json::Value root) { - + // Set data from Json (if key is found) if (!root["protobuf_data_path"].isNull()){ protobuf_data_path = (root["protobuf_data_path"].asString()); @@ -277,7 +278,7 @@ void CVTracker::SetJsonValue(const Json::Value root) { if (!root["tracker-type"].isNull()){ trackerType = (root["tracker-type"].asString()); } - + if (!root["region"].isNull()){ double x = root["region"]["x"].asDouble(); double y = root["region"]["y"].asDouble(); @@ -343,7 +344,7 @@ bool CVTracker::_LoadTrackedData(){ trackedDataById[id] = FrameData(id, rotation, x1, y1, x2, y2); } - // Show the time stamp from the last update in tracker data file + // Show the time stamp from the last update in tracker data file if (trackerMessage.has_last_updated()) { cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(trackerMessage.last_updated()) << endl; } diff --git a/src/CVTracker.h b/src/CVTracker.h index d644e478..9aa9ef8f 100644 --- a/src/CVTracker.h +++ b/src/CVTracker.h @@ -51,12 +51,11 @@ #include "sort_filter/sort.hpp" -using namespace std; using google::protobuf::util::TimeUtil; namespace openshot { - + // Store the tracked object information for one frame struct FrameData{ size_t frame_id = -1; @@ -88,13 +87,13 @@ namespace openshot * @brief The tracker class will receive one bounding box provided by the user and then iterate over the clip frames * to return the object position in all the frames. */ - class CVTracker { + class CVTracker { private: - std::map trackedDataById; // Save tracked data + std::map trackedDataById; // Save tracked data std::string trackerType; // Name of the chosen tracker cv::Ptr tracker; // Pointer of the selected tracker - cv::Rect2d bbox; // Bounding box coords + cv::Rect2d bbox; // Bounding box coords SortTracker sort; std::string protobuf_data_path; // Path to protobuf data file @@ -103,34 +102,34 @@ namespace openshot /// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes ProcessingController *processingController; - + bool json_interval; size_t start; size_t end; bool error = false; - + // Initialize the tracker bool initTracker(cv::Mat &frame, size_t frameId); - - // Update the object tracker according to frame + + // Update the object tracker according to frame bool trackFrame(cv::Mat &frame, size_t frameId); public: // Constructor CVTracker(std::string processInfoJson, ProcessingController &processingController); - + // Set desirable tracker method cv::Ptr selectTracker(std::string trackerType); // Track object in the hole clip or in a given interval - // If start, end and process_interval are passed as argument, clip will be processed in [start,end) + // If start, end and process_interval are passed as argument, clip will be processed in [start,end) void trackClip(openshot::Clip& video, size_t _start=0, size_t _end=0, bool process_interval=false); // Get tracked data for a given frame FrameData GetTrackedData(size_t frameId); - + /// Protobuf Save and Load methods // Save protobuf file bool SaveTrackedData(); @@ -146,4 +145,4 @@ namespace openshot }; } -#endif \ No newline at end of file +#endif diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index 2b9745e5..d4e1e077 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -31,11 +31,12 @@ #include "effects/ObjectDetection.h" #include "effects/Tracker.h" +using namespace std; using namespace openshot; /// Blank constructor, useful when using Json to load the effect properties ObjectDetection::ObjectDetection(std::string clipObDetectDataPath) -{ +{ // Init effect properties init_effect_details(); @@ -113,14 +114,14 @@ void ObjectDetection::drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& CV_Assert(classId < (int)classNames.size()); label = classNames[classId] + ":" + label; } - + //Display the label at the top of the bounding box int baseLine; cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine); double left = box.x; double top = std::max((int)box.y, labelSize.height); - + cv::rectangle(frame, cv::Point(left, top - round(1.025*labelSize.height)), cv::Point(left + round(1.025*labelSize.width), top + baseLine), classesColor[classId], cv::FILLED); putText(frame, label, cv::Point(left+1, top), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0,0,0),1); std::cout<<"X1: "< &pBox = pbFrameData.bounding_box(); - + // Construct data vectors related to detections in the current frame std::vector classIds; std::vector confidences; @@ -193,8 +194,8 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ detectionsData[id] = DetectionData(classIds, confidences, boxes, id); } - // Show the time stamp from the last update in object detector data file - if (objMessage.has_last_updated()) + // Show the time stamp from the last update in object detector data file + if (objMessage.has_last_updated()) cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(objMessage.last_updated()) << endl; // Delete all global objects allocated by libprotobuf. @@ -203,7 +204,7 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ return true; } -// Get tracker info for the desired frame +// Get tracker info for the desired frame DetectionData ObjectDetection::GetTrackedData(size_t frameId){ // Check if the tracker info for the requested frame exists @@ -259,7 +260,7 @@ void ObjectDetection::SetJsonValue(const Json::Value root) { // Set data from Json (if key is found) if (!root["protobuf_data_path"].isNull()){ protobuf_data_path = (root["protobuf_data_path"].asString()); - + if(!LoadObjDetectdData(protobuf_data_path)){ std::cout<<"Invalid protobuf data path"; protobuf_data_path = ""; diff --git a/src/effects/ObjectDetection.h b/src/effects/ObjectDetection.h index f0d0f1bc..31518c86 100644 --- a/src/effects/ObjectDetection.h +++ b/src/effects/ObjectDetection.h @@ -68,7 +68,7 @@ namespace openshot std::string protobuf_data_path; std::map detectionsData; std::vector classNames; - + std::vector classesColor; /// Init effect settings @@ -94,14 +94,14 @@ namespace openshot /// @param frame The frame object that needs the effect applied to it /// @param frame_number The frame number (starting at 1) of the effect on the timeline. std::shared_ptr GetFrame(std::shared_ptr frame, int64_t frame_number) override; - + std::shared_ptr GetFrame(int64_t frame_number) override { return GetFrame(std::shared_ptr (new Frame()), frame_number); } - + // Load protobuf data file bool LoadObjDetectdData(std::string inputFilePath); DetectionData GetTrackedData(size_t frameId); - + /// Get and Set JSON methods std::string Json() const override; ///< Generate JSON string of this object void SetJson(const std::string value) override; ///< Load JSON string into this object diff --git a/src/effects/Stabilizer.cpp b/src/effects/Stabilizer.cpp index 40d66bc3..09d2e09f 100644 --- a/src/effects/Stabilizer.cpp +++ b/src/effects/Stabilizer.cpp @@ -30,11 +30,12 @@ #include "effects/Stabilizer.h" +using namespace std; using namespace openshot; /// Blank constructor, useful when using Json to load the effect properties Stabilizer::Stabilizer(std::string clipStabilizedDataPath):protobuf_data_path(clipStabilizedDataPath) -{ +{ // Init effect properties init_effect_details(); // Tries to load the stabilization data from protobuf @@ -80,7 +81,7 @@ std::shared_ptr Stabilizer::GetFrame(std::shared_ptr frame, int64_ if(transformationData.find(frame_number) != transformationData.end()){ float zoom_value = zoom.GetValue(frame_number); - + // Create empty rotation matrix cv::Mat T(2,3,CV_64F); @@ -98,8 +99,8 @@ std::shared_ptr Stabilizer::GetFrame(std::shared_ptr frame, int64_ cv::warpAffine(frame_image, frame_stabilized, T, frame_image.size()); // 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, zoom_value); - cv::warpAffine(frame_stabilized, frame_stabilized, T_scale, frame_stabilized.size()); + cv::Mat T_scale = cv::getRotationMatrix2D(cv::Point2f(frame_stabilized.cols/2, frame_stabilized.rows/2), 0, zoom_value); + cv::warpAffine(frame_stabilized, frame_stabilized, T_scale, frame_stabilized.size()); frame_image = frame_stabilized; } } @@ -126,13 +127,13 @@ bool Stabilizer::LoadStabilizedData(std::string inputFilePath){ transformationData.clear(); trajectoryData.clear(); - // Iterate over all frames of the saved message and assign to the data maps + // Iterate over all frames of the saved message and assign to the data maps for (size_t i = 0; i < stabilizationMessage.frame_size(); i++) { // Create stabilization message const libopenshotstabilize::Frame& pbFrameData = stabilizationMessage.frame(i); - - // Load frame number + + // Load frame number size_t id = pbFrameData.id(); // Load camera trajectory data @@ -152,7 +153,7 @@ bool Stabilizer::LoadStabilizedData(std::string inputFilePath){ transformationData[id] = EffectTransformParam(dx,dy,da); } - // Show the time stamp from the last update in stabilization data file + // Show the time stamp from the last update in stabilization data file if (stabilizationMessage.has_last_updated()) { cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(stabilizationMessage.last_updated()) << endl; } @@ -211,7 +212,7 @@ void Stabilizer::SetJsonValue(const Json::Value root) { // Set data from Json (if key is found) if (!root["protobuf_data_path"].isNull()){ protobuf_data_path = (root["protobuf_data_path"].asString()); - + if(!LoadStabilizedData(protobuf_data_path)){ std::cout<<"Invalid protobuf data path"; protobuf_data_path = ""; diff --git a/src/effects/Stabilizer.h b/src/effects/Stabilizer.h index 8cc6f8d7..724d5849 100644 --- a/src/effects/Stabilizer.h +++ b/src/effects/Stabilizer.h @@ -43,7 +43,6 @@ #include "../KeyFrame.h" #include "protobuf_messages/stabilizedata.pb.h" -using namespace std; using google::protobuf::util::TimeUtil; // Store the relative transformation parameters between consecutive frames @@ -79,11 +78,11 @@ struct EffectCamTrajectory namespace openshot { - + /** * @brief This class stabilizes video clip to remove undesired shaking and jitter. * - * Adding stabilization is useful to increase video quality overall, since it removes + * Adding stabilization is useful to increase video quality overall, since it removes * from subtle to harsh unexpected camera movements. */ class Stabilizer : public EffectBase @@ -97,7 +96,7 @@ namespace openshot public: std::string teste; std::map trajectoryData; // Save camera trajectory data - std::map transformationData; // Save transormation data + std::map transformationData; // Save transormation data /// Blank constructor, useful when using Json to load the effect properties Stabilizer(std::string clipTrackerDataPath); @@ -122,7 +121,7 @@ namespace openshot // Load protobuf data file bool LoadStabilizedData(std::string inputFilePath); - + /// Get and Set JSON methods std::string Json() const override; ///< Generate JSON string of this object void SetJson(const std::string value) override; ///< Load JSON string into this object diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index 78fd3e07..0dd7af67 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -30,11 +30,12 @@ #include "effects/Tracker.h" +using namespace std; using namespace openshot; /// Blank constructor, useful when using Json to load the effect properties Tracker::Tracker(std::string clipTrackerDataPath) -{ +{ // Init effect properties init_effect_details(); @@ -134,7 +135,7 @@ bool Tracker::LoadTrackedData(std::string inputFilePath){ trackedDataById[id] = EffectFrameData(id, rotation, x1, y1, x2, y2); } - // Show the time stamp from the last update in tracker data file + // Show the time stamp from the last update in tracker data file if (trackerMessage.has_last_updated()) { cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(trackerMessage.last_updated()) << endl; } @@ -145,7 +146,7 @@ bool Tracker::LoadTrackedData(std::string inputFilePath){ return true; } -// Get tracker info for the desired frame +// Get tracker info for the desired frame EffectFrameData Tracker::GetTrackedData(size_t frameId){ // Check if the tracker info for the requested frame exists @@ -201,7 +202,7 @@ void Tracker::SetJsonValue(const Json::Value root) { // Set data from Json (if key is found) if (!root["protobuf_data_path"].isNull()){ protobuf_data_path = (root["protobuf_data_path"].asString()); - + if(!LoadTrackedData(protobuf_data_path)){ std::cout<<"Invalid protobuf data path"; protobuf_data_path = ""; diff --git a/src/effects/Tracker.h b/src/effects/Tracker.h index a64ab824..854ffdfc 100644 --- a/src/effects/Tracker.h +++ b/src/effects/Tracker.h @@ -44,7 +44,6 @@ #include "../KeyFrame.h" #include "protobuf_messages/trackerdata.pb.h" -using namespace std; using google::protobuf::util::TimeUtil;