diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a9d6a60..d0db3a60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -451,7 +451,7 @@ if(ENABLE_OPENCV) if(NOT OpenCV_FOUND) set(ENABLE_OPENCV FALSE CACHE BOOL "Build with OpenCV algorithms (requires Protobuf 3)" FORCE) - # If we have version 4.5.1, all hope is lost + # If we have version 4.5.1, all hope is lost elseif(OpenCV_VERSION VERSION_EQUAL "4.5.1") message(WARNING [[Incompatible OpenCV version detected OpenCV version 4.5.1 contains header errors which make it unable to be used with OpenShot. OpenCV support wil be disabled. Upgrade to OpenCV 4.5.2+ or downgrade to 4.5.0 or earlier, to enable OpenCV. @@ -459,7 +459,35 @@ See https://github.com/opencv/opencv/issues/19260]]) set(ENABLE_OPENCV FALSE CACHE BOOL "Build with OpenCV algorithms (requires Protobuf 3)" FORCE) else() - add_subdirectory(protobuf_messages) + ### + ### Protocol Buffers + ### + find_package(Protobuf 3 REQUIRED) + + # Create a target for libprotobuf, if necessary (CMake < 3.9) + if(NOT TARGET protobuf::libprotobuf) + add_library(protobuf_TARGET INTERFACE) + target_include_directories(protobuf_TARGET + INTERFACE ${Protobuf_INCLUDE_DIRS}) + target_link_libraries(protobuf_TARGET INTERFACE ${Protobuf_LIBRARIES}) + add_library(protobuf::libprotobuf ALIAS protobuf_TARGET) + endif() + + # Create libopenshot_protobuf + set(PROTOBUF_SOURCES + "objdetectdata.proto" + "stabilizedata.proto" + "trackerdata.proto" + ) + PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${PROTOBUF_SOURCES}) + + target_sources(openshot PRIVATE ${ProtoSources} ${ProtoHeaders}) + target_link_libraries(openshot PRIVATE protobuf::libprotobuf) + + ### + ### OpenCV + ### + # Add OpenCV source files target_sources(openshot PRIVATE ${OPENSHOT_CV_SOURCES} @@ -471,7 +499,6 @@ See https://github.com/opencv/opencv/issues/19260]]) opencv_highgui opencv_dnn opencv_tracking - openshot_protobuf ) set(HAVE_OPENCV TRUE CACHE BOOL "Building with OpenCV effects" FORCE) mark_as_advanced(HAVE_OPENCV) @@ -504,7 +531,7 @@ endif() ### INSTALL HEADERS & LIBRARY ### -# Install primary library +# Install libraries install(TARGETS openshot COMPONENT runtime ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -518,6 +545,7 @@ install(DIRECTORY . FILES_MATCHING PATTERN "*.h" ) + # On Windows, we copy project output DLLs into the tests dir # so that the unit test executables can find them if(CMAKE_VERSION VERSION_GREATER 3.13 AND WIN32 AND BUILD_TESTING) @@ -532,6 +560,7 @@ if(CMAKE_VERSION VERSION_GREATER 3.13 AND WIN32 AND BUILD_TESTING) COMMENT "Copying libopenshot DLL to unit test directory" ) + # Also copy libopenshot-audio DLL get_target_property(AUDIO_LIB_PATH OpenShot::Audio LOCATION) add_custom_target(test-install-audio-dll ALL diff --git a/src/CVObjectDetection.cpp b/src/CVObjectDetection.cpp index 1ba302d0..f8e50005 100644 --- a/src/CVObjectDetection.cpp +++ b/src/CVObjectDetection.cpp @@ -16,6 +16,8 @@ #include #include "CVObjectDetection.h" +#include "objdetectdata.pb.h" + #include using namespace std; @@ -450,8 +452,8 @@ bool CVObjectDetection::_LoadObjDetectdData(){ 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 classIds; + std::vector confidences; std::vector> boxes; std::vector objectIds; diff --git a/src/CVObjectDetection.h b/src/CVObjectDetection.h index b82dd055..3982a33c 100644 --- a/src/CVObjectDetection.h +++ b/src/CVObjectDetection.h @@ -23,19 +23,23 @@ #include "Json.h" #include "ProcessingController.h" #include "Clip.h" -#include "protobuf_messages/objdetectdata.pb.h" #include "sort_filter/sort.hpp" +// Forward decl +namespace pb_objdetect { + class Frame; +} + namespace openshot { // Stores the detected object bounding boxes and its properties. struct CVDetectionData{ CVDetectionData(){} CVDetectionData( - std::vector _classIds, + std::vector _classIds, std::vector _confidences, - std::vector> _boxes, + std::vector> _boxes, size_t _frameId, std::vector _objectIds) { diff --git a/src/CVStabilization.cpp b/src/CVStabilization.cpp index e38b294f..9621c42a 100644 --- a/src/CVStabilization.cpp +++ b/src/CVStabilization.cpp @@ -16,6 +16,8 @@ #include #include "CVStabilization.h" + +#include "stabilizedata.pb.h" #include using namespace std; diff --git a/src/CVStabilization.h b/src/CVStabilization.h index fe3a39cd..6b017940 100644 --- a/src/CVStabilization.h +++ b/src/CVStabilization.h @@ -20,12 +20,21 @@ #include #undef uint64 #undef int64 -#include -#include "protobuf_messages/stabilizedata.pb.h" + +#include +#include +#include + #include "ProcessingController.h" + #include "Clip.h" #include "Json.h" +// Forward decl +namespace pb_stabilize { + class Frame; +} + // Store the relative transformation parameters between consecutive frames struct TransformParam { @@ -82,7 +91,7 @@ class CVStabilization { bool error = false; /// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes - ProcessingController *processingController; + ProcessingController *processingController; /// Track current frame features and find the relative transformation bool TrackFrameFeatures(cv::Mat frame, size_t frameNum); diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index 8df63825..a701ea1f 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -19,6 +19,7 @@ #include "OpenCVUtilities.h" #include "CVTracker.h" +#include "trackerdata.pb.h" using namespace openshot; using google::protobuf::util::TimeUtil; diff --git a/src/CVTracker.h b/src/CVTracker.h index 8d31d676..eff8b50a 100644 --- a/src/CVTracker.h +++ b/src/CVTracker.h @@ -30,10 +30,14 @@ #include "Json.h" #include "ProcessingController.h" -#include "protobuf_messages/trackerdata.pb.h" #include "sort_filter/sort.hpp" +// Forward decl +namespace pb_tracker { + class Frame; +} + namespace openshot { diff --git a/src/ProcessingController.h b/src/ProcessingController.h index 14bcb6ab..fbe3f017 100644 --- a/src/ProcessingController.h +++ b/src/ProcessingController.h @@ -14,10 +14,8 @@ #ifndef OPENSHOT_PROCESSINGCONTROLLER_H #define OPENSHOT_PROCESSINGCONTROLLER_H -#include -#include -#include - +#include +#include class ProcessingController{ private: @@ -33,7 +31,7 @@ class ProcessingController{ std::mutex mtxerror; public: - + ProcessingController(){ processingProgress = 0; stopProcessing = false; @@ -41,23 +39,23 @@ class ProcessingController{ } int GetFinished(){ - std::lock_guard lck (mtxFinished); + std::lock_guard lck (mtxFinished); bool f = processingFinished; return f; } void SetFinished(bool f){ - std::lock_guard lck (mtxFinished); + std::lock_guard lck (mtxFinished); processingFinished = f; } - + void SetProgress(uint p){ - std::lock_guard lck (mtxProgress); + std::lock_guard lck (mtxProgress); processingProgress = p; } int GetProgress(){ - std::lock_guard lck (mtxProgress); + std::lock_guard lck (mtxProgress); uint p = processingProgress; return p; } @@ -74,7 +72,7 @@ class ProcessingController{ } void SetError(bool err, std::string message){ - std::lock_guard lck (mtxerror); + std::lock_guard lck (mtxerror); error = err; error_message = message; } @@ -84,7 +82,7 @@ class ProcessingController{ bool e = error; return e; } - + std::string GetErrorMessage(){ std::lock_guard lck (mtxerror); std::string message = error_message; @@ -93,4 +91,4 @@ class ProcessingController{ }; -#endif \ No newline at end of file +#endif diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 6fa6985b..87751607 100644 --- a/src/TrackedObjectBBox.cpp +++ b/src/TrackedObjectBBox.cpp @@ -15,7 +15,7 @@ #include "Clip.h" -#include "protobuf_messages/trackerdata.pb.h" +#include "trackerdata.pb.h" #include using google::protobuf::util::TimeUtil; @@ -377,7 +377,7 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root) // Set the protobuf data path by the given JSON object if (!root["protobuf_data_path"].isNull()) protobufDataPath = root["protobuf_data_path"].asString(); - + // Set the id of the child clip if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != "" && root["child_clip_id"].asString() != Id()){ Clip* parentClip = (Clip *) ParentClip(); diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index 5bbc3ac2..849ba307 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -18,6 +18,7 @@ #include "effects/Tracker.h" #include "Exceptions.h" #include "Timeline.h" +#include "objdetectdata.pb.h" #include #include @@ -88,7 +89,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i DetectionData detections = detectionsData[frame_number]; for(int i = 0; i ObjectDetection::GetFrame(std::shared_ptr frame, i std::find(display_classes.begin(), display_classes.end(), classNames[detections.classIds.at(i)]) == display_classes.end()){ continue; } - + // Get the object id int objectId = detections.objectIds.at(i); @@ -109,7 +110,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i std::shared_ptr trackedObject = std::static_pointer_cast(trackedObject_it->second); // Check if the tracked object has data for this frame - if (trackedObject->Contains(frame_number) && + if (trackedObject->Contains(frame_number) && trackedObject->visible.GetValue(frame_number) == 1) { // Get the bounding-box of given frame @@ -122,8 +123,8 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i float bg_alpha = trackedObject->background_alpha.GetValue(frame_number); // Create a rotated rectangle object that holds the bounding box - // cv::RotatedRect box ( cv::Point2f( (int)(trackedBox.cx*fw), (int)(trackedBox.cy*fh) ), - // cv::Size2f( (int)(trackedBox.width*fw), (int)(trackedBox.height*fh) ), + // cv::RotatedRect box ( cv::Point2f( (int)(trackedBox.cx*fw), (int)(trackedBox.cy*fh) ), + // cv::Size2f( (int)(trackedBox.width*fw), (int)(trackedBox.height*fh) ), // (int) (trackedBox.angle) ); // DrawRectangleRGBA(cv_image, box, bg_rgba, bg_alpha, 1, true); @@ -138,7 +139,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i ); // If the Draw Box property is off, then make the box invisible - if (trackedObject->draw_box.GetValue(frame_number) == 0) + if (trackedObject->draw_box.GetValue(frame_number) == 0) { bg_alpha = 1.0; stroke_alpha = 1.0; @@ -148,16 +149,16 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i box, cv_image, detections.objectIds.at(i), bg_rgba, bg_alpha, 1, true, draw_text); drawPred(detections.classIds.at(i), detections.confidences.at(i), box, cv_image, detections.objectIds.at(i), stroke_rgba, stroke_alpha, stroke_width, false, draw_text); - - + + // Get the Detected Object's child clip if (trackedObject->ChildClipId() != ""){ - // Cast the parent timeline of this effect + // Cast the parent timeline of this effect Timeline* parentTimeline = (Timeline *) ParentTimeline(); if (parentTimeline){ // Get the Tracked Object's child clip Clip* childClip = parentTimeline->GetClip(trackedObject->ChildClipId()); - + if (childClip){ std::shared_ptr f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000")); // Get the image of the child clip for this frame @@ -174,7 +175,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i } } } - } + } } } @@ -189,7 +190,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i // Set a Qt painter to the frame image QPainter painter(&frameImage); // Draw the child clip image inside the bounding-box - painter.drawImage(boxRects[i], *childClipImages[i], QRectF(0, 0, frameImage.size().width(), frameImage.size().height())); + painter.drawImage(boxRects[i], *childClipImages[i], QRectF(0, 0, frameImage.size().width(), frameImage.size().height())); } // Set the frame image as the composed image frame->AddImage(std::make_shared(frameImage)); @@ -198,7 +199,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i return frame; } -void ObjectDetection::DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std::vector color, float alpha, +void ObjectDetection::DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std::vector color, float alpha, int thickness, bool is_background){ // Get the bouding box vertices cv::Point2f vertices2f[4]; @@ -227,7 +228,7 @@ void ObjectDetection::DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect bo cv::Mat overlayFrame; frame_image.copyTo(overlayFrame); - // Draw bounding box + // Draw bounding box for (int i = 0; i < 4; i++) { cv::line(overlayFrame, vertices2f[i], vertices2f[(i+1)%4], cv::Scalar(color[2],color[1],color[0]), @@ -239,7 +240,7 @@ void ObjectDetection::DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect bo } } -void ObjectDetection::drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& frame, int objectNumber, std::vector color, +void ObjectDetection::drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& frame, int objectNumber, std::vector color, float alpha, int thickness, bool is_background, bool display_text) { @@ -259,7 +260,7 @@ void ObjectDetection::drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& //Draw a rectangle displaying the bounding box cv::rectangle(overlayFrame, box, cv::Scalar(color[2],color[1],color[0]), thickness); - + if(display_text){ //Get the label for the class name and its confidence std::string label = cv::format("%.2f", conf); @@ -268,7 +269,7 @@ 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); @@ -276,7 +277,7 @@ void ObjectDetection::drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& double left = box.x; double top = std::max((int)box.y, labelSize.height); - cv::rectangle(overlayFrame, cv::Point(left, top - round(1.025*labelSize.height)), cv::Point(left + round(1.025*labelSize.width), top + baseLine), + cv::rectangle(overlayFrame, cv::Point(left, top - round(1.025*labelSize.height)), cv::Point(left + round(1.025*labelSize.width), top + baseLine), cv::Scalar(color[2],color[1],color[0]), cv::FILLED); putText(overlayFrame, label, cv::Point(left+1, top), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0,0,0),1); } @@ -296,7 +297,7 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ std::cerr << "Failed to parse protobuf message." << std::endl; return false; } - + // Make sure classNames, detectionsData and trackedObjects are empty classNames.clear(); detectionsData.clear(); @@ -341,7 +342,7 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ int classId = pBox.Get(i).classid(); // Get prediction confidence float confidence = pBox.Get(i).confidence(); - + // Get the object Id int objectId = pBox.Get(i).objectid(); @@ -352,17 +353,17 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ { // Add a new BBox to it trackedObject->second->AddBox(id, x+(w/2), y+(h/2), w, h, 0.0); - } + } else { // There is no tracked object with that id, so insert a new one TrackedObjectBBox trackedObj((int)classesColor[classId](0), (int)classesColor[classId](1), (int)classesColor[classId](2), (int)0); trackedObj.AddBox(id, x+(w/2), y+(h/2), w, h, 0.0); - + std::shared_ptr trackedObjPtr = std::make_shared(trackedObj); ClipBase* parentClip = this->ParentClip(); trackedObjPtr->ParentClip(parentClip); - + // Create a temp ID. This ID is necessary to initialize the object_id Json list // this Id will be replaced by the one created in the UI trackedObjPtr->Id(std::to_string(objectId)); @@ -391,7 +392,7 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ // Get the indexes and IDs of all visible objects in the given frame std::string ObjectDetection::GetVisibleObjects(int64_t frame_number) const{ - + // Initialize the JSON objects Json::Value root; root["visible_objects_index"] = Json::Value(Json::arrayValue); @@ -422,8 +423,8 @@ std::string ObjectDetection::GetVisibleObjects(int64_t frame_number) const{ // Get the tracked object JSON properties for this frame Json::Value trackedObjectJSON = trackedObject->second->PropertiesJSON(frame_number); - - if (trackedObjectJSON["visible"]["value"].asBool() && + + if (trackedObjectJSON["visible"]["value"].asBool() && trackedObject->second->ExactlyContains(frame_number)){ // Save the object's index and ID if it's visible in this frame root["visible_objects_index"].append(trackedObject->first); @@ -456,7 +457,7 @@ Json::Value ObjectDetection::JsonValue() const { Json::Value objects; for (auto const& trackedObject : trackedObjects){ Json::Value trackedObjectJSON = trackedObject.second->JsonValue(); - // add object json + // add object json objects[trackedObject.second->Id()] = trackedObjectJSON; } root["objects"] = objects; @@ -500,10 +501,10 @@ void ObjectDetection::SetJsonValue(const Json::Value root) { // Set the selected object index if (!root["selected_object_index"].isNull()) selectedObjectIndex = root["selected_object_index"].asInt(); - + if (!root["confidence_threshold"].isNull()) confidence_threshold = root["confidence_threshold"].asFloat(); - + if (!root["display_box_text"].isNull()) display_box_text.SetJsonValue(root["display_box_text"]); @@ -550,7 +551,7 @@ std::string ObjectDetection::PropertiesJSON(int64_t requested_frame) const { auto selectedObject = trackedObjects.at(selectedObjectIndex); if (selectedObject){ Json::Value trackedObjectJSON = selectedObject->PropertiesJSON(requested_frame); - // add object json + // add object json objects[selectedObject->Id()] = trackedObjectJSON; } } @@ -569,7 +570,7 @@ std::string ObjectDetection::PropertiesJSON(int64_t requested_frame) const { root["display_box_text"] = add_property_json("Draw Box Text", display_box_text.GetValue(requested_frame), "int", "", &display_box_text, 0, 1.0, false, requested_frame); root["display_box_text"]["choices"].append(add_property_choice_json("Off", 1, display_box_text.GetValue(requested_frame))); root["display_box_text"]["choices"].append(add_property_choice_json("On", 0, display_box_text.GetValue(requested_frame))); - + // Return formatted string return root.toStyledString(); } diff --git a/src/effects/ObjectDetection.h b/src/effects/ObjectDetection.h index fb49e983..25753172 100644 --- a/src/effects/ObjectDetection.h +++ b/src/effects/ObjectDetection.h @@ -14,16 +14,15 @@ #ifndef OPENSHOT_OBJECT_DETECTION_EFFECT_H #define OPENSHOT_OBJECT_DETECTION_EFFECT_H -#include "../EffectBase.h" +#include "EffectBase.h" -#include -#include #include + #include -#include "../Color.h" -#include "../Json.h" -#include "../KeyFrame.h" -#include "protobuf_messages/objdetectdata.pb.h" + +#include "Color.h" +#include "Json.h" +#include "KeyFrame.h" // Struct that stores the detected bounding boxes for all the clip frames struct DetectionData{ @@ -61,19 +60,19 @@ namespace openshot std::vector classNames; std::vector classesColor; - + /// Draw class name and confidence score on top of the bounding box Keyframe display_box_text; /// Minimum confidence value to display the detected objects - float confidence_threshold = 0.5; + float confidence_threshold = 0.5; /// Contain the user selected classes for visualization std::vector display_classes; std::string class_filter; /// Init effect settings void init_effect_details(); - /// Draw bounding box with class and score text - void drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& frame, int objectNumber, std::vector color, float alpha, + /// Draw bounding box with class and score text + void drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& frame, int objectNumber, std::vector color, float alpha, int thickness, bool is_background, bool draw_text); /// Draw rotated rectangle with alpha channel void DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std::vector color, float alpha, int thickness, bool is_background); diff --git a/src/effects/Stabilizer.cpp b/src/effects/Stabilizer.cpp index 9884e80c..f5cfb0e4 100644 --- a/src/effects/Stabilizer.cpp +++ b/src/effects/Stabilizer.cpp @@ -17,6 +17,8 @@ #include "effects/Stabilizer.h" #include "Exceptions.h" +#include "stabilizedata.pb.h" + #include using namespace std; diff --git a/src/effects/Stabilizer.h b/src/effects/Stabilizer.h index 63b00af3..1ecd3461 100644 --- a/src/effects/Stabilizer.h +++ b/src/effects/Stabilizer.h @@ -14,15 +14,13 @@ #ifndef OPENSHOT_STABILIZER_EFFECT_H #define OPENSHOT_STABILIZER_EFFECT_H -#include "../EffectBase.h" +#include "EffectBase.h" -#include -#include #include -#include "../Color.h" -#include "../Json.h" -#include "../KeyFrame.h" -#include "protobuf_messages/stabilizedata.pb.h" + +#include "Color.h" +#include "Json.h" +#include "KeyFrame.h" // Store the relative transformation parameters between consecutive frames struct EffectTransformParam diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index f4f82e0b..28097fed 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -19,6 +19,7 @@ #include "effects/Tracker.h" #include "Exceptions.h" #include "Timeline.h" +#include "trackerdata.pb.h" #include @@ -93,7 +94,7 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t f std::shared_ptr childClipImage = nullptr; // Check if frame isn't NULL - if(!frame_image.empty() && + if(!frame_image.empty() && trackedData->Contains(frame_number) && trackedData->visible.GetValue(frame_number) == 1) { @@ -105,7 +106,7 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t f BBox fd = trackedData->GetBox(frame_number); // Check if track data exists for the requested frame - if (trackedData->draw_box.GetValue(frame_number) == 1) + if (trackedData->draw_box.GetValue(frame_number) == 1) { std::vector stroke_rgba = trackedData->stroke.GetColorRGBA(frame_number); int stroke_width = trackedData->stroke_width.GetValue(frame_number); @@ -114,17 +115,17 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t f float bg_alpha = trackedData->background_alpha.GetValue(frame_number); // Create a rotated rectangle object that holds the bounding box - cv::RotatedRect box ( cv::Point2f( (int)(fd.cx*fw), (int)(fd.cy*fh) ), - cv::Size2f( (int)(fd.width*fw), (int)(fd.height*fh) ), + cv::RotatedRect box ( cv::Point2f( (int)(fd.cx*fw), (int)(fd.cy*fh) ), + cv::Size2f( (int)(fd.width*fw), (int)(fd.height*fh) ), (int) (fd.angle) ); DrawRectangleRGBA(frame_image, box, bg_rgba, bg_alpha, 1, true); DrawRectangleRGBA(frame_image, box, stroke_rgba, stroke_alpha, stroke_width, false); } - + // Get the image of the Tracked Object' child clip if (trackedData->ChildClipId() != ""){ - // Cast the parent timeline of this effect + // Cast the parent timeline of this effect Timeline* parentTimeline = (Timeline *) ParentTimeline(); if (parentTimeline){ // Get the Tracked Object's child clip @@ -143,7 +144,7 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t f } } } - + } // Set image with drawn box to frame @@ -196,7 +197,7 @@ void Tracker::DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std:: cv::Mat overlayFrame; frame_image.copyTo(overlayFrame); - // Draw bounding box + // Draw bounding box for (int i = 0; i < 4; i++) { cv::line(overlayFrame, vertices2f[i], vertices2f[(i+1)%4], cv::Scalar(color[2],color[1],color[0]), @@ -210,7 +211,7 @@ void Tracker::DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std:: // Get the indexes and IDs of all visible objects in the given frame std::string Tracker::GetVisibleObjects(int64_t frame_number) const{ - + // Initialize the JSON objects Json::Value root; root["visible_objects_index"] = Json::Value(Json::arrayValue); @@ -254,7 +255,7 @@ Json::Value Tracker::JsonValue() const { Json::Value objects; for (auto const& trackedObject : trackedObjects){ Json::Value trackedObjectJSON = trackedObject.second->JsonValue(); - // add object json + // add object json objects[trackedObject.second->Id()] = trackedObjectJSON; } root["objects"] = objects; @@ -295,13 +296,13 @@ void Tracker::SetJsonValue(const Json::Value root) { if (!root["BaseFPS"]["num"].isNull()) { BaseFPS.num = (int) root["BaseFPS"]["num"].asInt(); - } + } if (!root["BaseFPS"]["den"].isNull()) { BaseFPS.den = (int) root["BaseFPS"]["den"].asInt(); } } - + if (!root["TimeScale"].isNull()) TimeScale = (double) root["TimeScale"].asDouble(); @@ -324,7 +325,7 @@ void Tracker::SetJsonValue(const Json::Value root) { } } } - + // Set the tracked object's ids if (!root["objects_id"].isNull()){ for (auto const& trackedObject : trackedObjects){ @@ -339,7 +340,7 @@ void Tracker::SetJsonValue(const Json::Value root) { // Get all properties for a specific frame std::string Tracker::PropertiesJSON(int64_t requested_frame) const { - + // Generate JSON properties list Json::Value root; @@ -347,7 +348,7 @@ std::string Tracker::PropertiesJSON(int64_t requested_frame) const { Json::Value objects; for (auto const& trackedObject : trackedObjects){ Json::Value trackedObjectJSON = trackedObject.second->PropertiesJSON(requested_frame); - // add object json + // add object json objects[trackedObject.second->Id()] = trackedObjectJSON; } root["objects"] = objects; diff --git a/src/effects/Tracker.h b/src/effects/Tracker.h index 41f4aa5e..f087bd3c 100644 --- a/src/effects/Tracker.h +++ b/src/effects/Tracker.h @@ -18,14 +18,13 @@ #include #include -#include "../EffectBase.h" +#include "EffectBase.h" -#include "../Json.h" -#include "../KeyFrame.h" +#include "Clip.h" +#include "Json.h" +#include "KeyFrame.h" -#include "protobuf_messages/trackerdata.pb.h" -#include "../TrackedObjectBBox.h" -#include "../Clip.h" +#include "TrackedObjectBBox.h" namespace openshot { diff --git a/src/protobuf_messages/objdetectdata.proto b/src/objdetectdata.proto similarity index 100% rename from src/protobuf_messages/objdetectdata.proto rename to src/objdetectdata.proto diff --git a/src/protobuf_messages/CMakeLists.txt b/src/protobuf_messages/CMakeLists.txt deleted file mode 100644 index 2132fc12..00000000 --- a/src/protobuf_messages/CMakeLists.txt +++ /dev/null @@ -1,66 +0,0 @@ -####################### CMakeLists.txt (libopenshot) ######################### -# @brief CMake build file for libopenshot (used to generate makefiles) -# @author Jonathan Thomas -# @author FeRD (Frank Dana) -# -# @section LICENSE -# -# Copyright (c) 2008-2020 OpenShot Studios, LLC -# -# SPDX-License-Identifier: LGPL-3.0-or-later - -# Dependencies -find_package(Protobuf 3 REQUIRED) - -# Create a target for libprotobuf, if necessary (CMake < 3.9) -if(NOT TARGET protobuf::libprotobuf) - add_library(protobuf_TARGET INTERFACE) - target_include_directories(protobuf_TARGET - INTERFACE ${Protobuf_INCLUDE_DIRS}) - target_link_libraries(protobuf_TARGET INTERFACE ${Protobuf_LIBRARIES}) - add_library(protobuf::libprotobuf ALIAS protobuf_TARGET) -endif() - -file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.proto") -PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles}) -add_library(openshot_protobuf SHARED ${ProtoSources} ${ProtoHeaders}) - -set(ProtobufMessagePath ${CMAKE_CURRENT_BINARY_DIR} - CACHE INTERNAL "Path to generated protobuf header files.") - -target_link_libraries(openshot_protobuf protobuf::libprotobuf) - -# Set SONAME and other library properties -set_target_properties(openshot_protobuf PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_SO_VERSION} - INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" - ) - -# Install protobuf library and generated headers -install(TARGETS openshot_protobuf - COMPONENT runtime - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot - ) -install(FILES ${ProtoHeaders} - COMPONENT devel - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot/protobuf_messages -) - -# On Windows, we copy project output DLLs into the test dirs -# so that the unit test executables can find them -if(CMAKE_VERSION VERSION_GREATER 3.13 AND WIN32 AND BUILD_TESTING) - add_custom_command(TARGET openshot_protobuf POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy_if_different - "$" - "${PROJECT_BINARY_DIR}/tests/" - BYPRODUCTS - "${PROJECT_BINARY_DIR}/tests/libopenshot_protobuf.dll" - COMMENT - "Copying libopenshot_protobuf DLL to unit test directory" - ) -endif() diff --git a/src/protobuf_messages/stabilizedata.proto b/src/stabilizedata.proto similarity index 100% rename from src/protobuf_messages/stabilizedata.proto rename to src/stabilizedata.proto diff --git a/src/protobuf_messages/trackerdata.proto b/src/trackerdata.proto similarity index 100% rename from src/protobuf_messages/trackerdata.proto rename to src/trackerdata.proto