Skip to content

Commit

Permalink
Fixed codacy review warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Jan 19, 2021
1 parent f6de533 commit d481e5a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/CVObjectDetection.cpp
Expand Up @@ -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(){
Expand Down Expand Up @@ -69,17 +71,14 @@ 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;
net = cv::dnn::readNetFromDarknet(modelConfiguration, modelWeights);
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();
Expand Down
6 changes: 4 additions & 2 deletions src/CVStabilization.cpp
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -230,7 +232,7 @@ std::map<size_t,CamTrajectory> CVStabilization::SmoothTrajectory(std::vector <Ca
int count = 0;

for(int j=-smoothingWindow; j <= smoothingWindow; j++) {
if(i+j >= 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;
Expand Down
4 changes: 3 additions & 1 deletion src/CVTracker.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +73,7 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo
if(!json_interval){
start = _start; end = _end;

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();
Expand Down
6 changes: 2 additions & 4 deletions src/sort_filter/Hungarian.cpp
Expand Up @@ -192,10 +192,8 @@ 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
Expand Down
6 changes: 3 additions & 3 deletions src/sort_filter/sort.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -154,11 +155,10 @@ void SortTracker::update(vector<cv::Rect> 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;
Expand Down
2 changes: 2 additions & 0 deletions src/sort_filter/sort.hpp
Expand Up @@ -22,6 +22,8 @@ typedef struct TrackingBox
int classId = 0;
int id = 0;
cv::Rect_<float> box = cv::Rect_<float>(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
Expand Down
4 changes: 2 additions & 2 deletions tests/CVTracker_Tests.cpp
Expand Up @@ -75,7 +75,7 @@ SUITE(CVTracker_Tests)
float y = fd.y1;
float width = fd.x2 - x;
float height = fd.y2 - y;
std::cout<<"\n\n Error: "<< processingController.GetErrorMessage() <<"\n";

// Compare if tracked data is equal to pre-tested ones
CHECK_EQUAL(259, (int)(x * 640));
CHECK_EQUAL(131, (int)(y * 360));
Expand Down Expand Up @@ -140,7 +140,7 @@ SUITE(CVTracker_Tests)
float y_2 = fd_2.y1;
float width_2 = fd_2.x2 - x_2;
float height_2 = fd_2.y2 - y_2;
std::cout<<"\n\n Error: "<< processingController.GetErrorMessage() <<"\n";

// Compare first tracker data with second tracker data
CHECK_EQUAL((int)(x_1 * 640), (int)(x_2 * 640));
CHECK_EQUAL((int)(y_1 * 360), (int)(y_2 * 360));
Expand Down

0 comments on commit d481e5a

Please sign in to comment.