1 | initial version |
No wonder it is slow, if every time you need to remove a contour you need to find ALL contours and verify which should be removed, it will be really slow.
Probably, somewhere in your code you already calculated the contours, there is no sense that a function for such a simple operations needs to define ALL contours of the image. So, the arguments that this function take in should be the already calculated contours that you are probably using somewhere else in the code.
If this is in fact the only operation where you need to use findContours, then there is small space for optimization. Still, there are things that can be done:
Cheers.
2 | No.2 Revision |
No wonder it is slow, if every time you need to remove a contour you need to find ALL contours and verify which should be removed, it will be really slow.
Probably, somewhere in your code you already calculated the contours, there is no sense that a function for such a simple operations needs to define ALL contours of the image. So, the arguments that this function take in should be the already calculated contours that you are probably using somewhere else in the code.
If this is in fact the only operation where you need to use findContours, then there is small space for optimization. Still, there are things that can be done:
Replace the line drawContours(output, contours, i, color, -1, 8);
with
rectangle(output, cv::boundingRect(contours[i], color, -1, 8);
Cheers.
3 | No.3 Revision |
No wonder it is slow, if every time you need to remove a contour you need to find ALL contours and verify which should be removed, it will be really slow.
Probably, somewhere in your code you already calculated the contours, there is contours,it makes no sense that a function for such a simple operations operation needs to define find ALL contours of the image. So, the arguments that this function take in should be the already calculated contours that you are probably using somewhere else in the code.
If this is in fact the only operation where you need to use findContours, then there is small space for optimization. Still, there are things that can be done:
Replace the line drawContours(output, contours, i, color, -1, 8);
with
rectangle(output, cv::boundingRect(contours[i], color, -1, 8);
Cheers.
4 | No.4 Revision |
No wonder it is slow, if every time you need to remove a contour you need to find ALL contours and verify which should be removed, it will be really slow.
Probably, somewhere in your code you already calculated the contours,it makes no sense that a function for such a simple operation needs to find ALL contours of the image. So, the arguments that this function take in should be the already calculated contours that you are probably using somewhere else in the code.
If this is in fact the only operation where you need to use findContours, then there is small space for optimization. Still, there are things that can be done:
Replace the line drawContours(output, contours, i, color, -1, 8);
with
rectangle(output,
cv::boundingRect(contours[i], cv::boundingRect(contours[i]), color, -1, 8);
Cheers.