New answers tagged

0

I'm confused by this line of code: src.copyTo( dst, detected_edges); What you are doing is writing into dst, at the location of the detected edges, the pixel value of the original input image src. By definition, the location of the edge is somewhere half-way the transition between two more or less uniformly colored regions. Half-way you should see a color ...


8

First, get rid of all the unneeded whitespace. Use consistent amount between functions (Python's official style-guide, PEP8, recommends two). PEP8 also recommends using spaces in lists, after the commas, and lower_case for all variables and functions (your T in threshold_slow violates this). Don't use magic numbers in your code. Give them readable names and ...


8

In terms of making more robust, a fairly obvious improvement would be to ensure that argv[1] exists before using it (that's what argc is for). If there's no argument, or the file can't be read, emit a useful error message to std::cerr and return EXIT_FAILURE - negative return values from main() can vary by platform. Why do we declare CannyThreshold with ...


6

Prefer <cstdio> to <stdio.h> and <cmath> to <math.h> in C++ code. You will probably never need the C compatibility headers unless you're writing headers that must also be included in C code. The compatibility headers are less useful in C++ code, because they declare everything in the global namespace rather than neatly in std. ...


11

Bug if (intersects) { isSingle = false; break; } This looks like a bug. The variable isSingle is already false. Setting it to false here does nothing. Code Review: You use std::vector but don't include its header. std::vector <Rect> overlaps; You should fix that. References and Const correctness. This ...


1

This is the improvement I ended up making for anyone interested. Old code: std::vector<std::vector<cv::Point> > contours; int blobX; //Need to be int cannnot be Point2f int blobY; findContours( frame, contours, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0) ); // Get the moments mu.reserve(contours.size()); for( int i = 0; i < ...


2

It seem like you can definitely merge the two loops together. Also you should avoid iterating using i, instead, use iterators, or the range-based for loop (since C++11). // if you needed this vector mu.reserve(contours.size()); // Get the mass centers: std::vector<cv::Point2f> mc( contours.size() ); for( auto& c : contours ) { auto m = moments(...


Top 50 recent answers are included