From f8198d668f00b17f777a4bc73c129c2bf438f3ad Mon Sep 17 00:00:00 2001 From: Brenno Date: Tue, 19 Jan 2021 15:28:33 -0300 Subject: [PATCH] Fixed codacy review warnings --- src/CVObjectDetection.cpp | 7 +++---- src/CVStabilization.cpp | 6 ++++-- src/CVTracker.cpp | 2 ++ src/sort_filter/Hungarian.cpp | 5 ++--- src/sort_filter/sort.cpp | 6 +++--- src/sort_filter/sort.hpp | 2 ++ 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/CVObjectDetection.cpp b/src/CVObjectDetection.cpp index ca0e92aef..c391197a2 100644 --- a/src/CVObjectDetection.cpp +++ b/src/CVObjectDetection.cpp @@ -38,6 +38,8 @@ using google::protobuf::util::TimeUtil; CVObjectDetection::CVObjectDetection(std::string processInfoJson, ProcessingController &processingController) : processingController(&processingController), processingDevice("CPU"){ SetJson(processInfoJson); + confThreshold = 0.5; + nmsThreshold = 0.1; } void CVObjectDetection::setProcessingDevice(){ @@ -69,9 +71,6 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, std::string line; while (std::getline(ifs, line)) classNames.push_back(line); - confThreshold = 0.5; - nmsThreshold = 0.1; - // Load the network if(classesFile == "" || modelConfiguration == "" || modelWeights == "") return; @@ -79,7 +78,7 @@ 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 == 0 || 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(); diff --git a/src/CVStabilization.cpp b/src/CVStabilization.cpp index b2f944b92..864f9b583 100644 --- a/src/CVStabilization.cpp +++ b/src/CVStabilization.cpp @@ -39,6 +39,8 @@ using google::protobuf::util::TimeUtil; CVStabilization::CVStabilization(std::string processInfoJson, ProcessingController &processingController) : processingController(&processingController){ SetJson(processInfoJson); + start = 0; + end = 0; } // Process clip and store necessary stabilization data @@ -58,7 +60,7 @@ 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 == 0 || 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(); @@ -230,7 +232,7 @@ std::map CVStabilization::SmoothTrajectory(std::vector = 0 && i+j < trajectory.size()) { + if(i+j < trajectory.size()) { sum_x += trajectory[i+j].x; sum_y += trajectory[i+j].y; sum_a += trajectory[i+j].a; diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index 757420252..fda0fbf14 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -40,6 +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; } // Set desirable tracker method diff --git a/src/sort_filter/Hungarian.cpp b/src/sort_filter/Hungarian.cpp index 61b9c36b1..eac72263d 100644 --- a/src/sort_filter/Hungarian.cpp +++ b/src/sort_filter/Hungarian.cpp @@ -192,10 +192,9 @@ void HungarianAlgorithm::buildassignmentvector( int nOfRows, int nOfColumns) { - int row, col; - for (row = 0; row < nOfRows; row++) - for (col = 0; col < nOfColumns; col++) + for (int row = 0; row < nOfRows; row++) + for (int col = 0; col < nOfColumns; col++) if (starMatrix[row + nOfRows * col]) { #ifdef ONE_INDEXING diff --git a/src/sort_filter/sort.cpp b/src/sort_filter/sort.cpp index 299bfb1a0..03225e179 100644 --- a/src/sort_filter/sort.cpp +++ b/src/sort_filter/sort.cpp @@ -7,6 +7,7 @@ SortTracker::SortTracker(int max_age, int min_hits) { _min_hits = min_hits; _max_age = max_age; + alive_tracker = true; } // Computes IOU between two bounding boxes @@ -154,11 +155,10 @@ void SortTracker::update(vector detections_cv, int frame_count, double matchedPairs.push_back(cv::Point(i, assignment[i])); } - int detIdx, trkIdx; for (unsigned int i = 0; i < matchedPairs.size(); i++) { - trkIdx = matchedPairs[i].x; - detIdx = matchedPairs[i].y; + int trkIdx = matchedPairs[i].x; + int detIdx = matchedPairs[i].y; trackers[trkIdx].update(detections[detIdx].box); trackers[trkIdx].classId = detections[detIdx].classId; trackers[trkIdx].confidence = detections[detIdx].confidence; diff --git a/src/sort_filter/sort.hpp b/src/sort_filter/sort.hpp index 4eab6dcda..295b9d567 100644 --- a/src/sort_filter/sort.hpp +++ b/src/sort_filter/sort.hpp @@ -22,6 +22,8 @@ typedef struct TrackingBox int classId = 0; int id = 0; cv::Rect_ box = cv::Rect_(0.0, 0.0, 0.0, 0.0); + TrackingBox() {} + TrackingBox(int _frame, float _confidence, int _classId, int _id) : frame(_frame), confidence(_confidence), classId(_classId), id(_id) {} } TrackingBox; class SortTracker