Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use a different method to calculate a blob area from contourArea, using the countNonZero function. I want to see if there is significant approximation introduced by contourArea function, and also be able to calculate area of contour with auto-intersection.

cv::findContours(drawingIn, contoursIn, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);


double max=0;
double currentarea=0;
int currentareaCounted = 0;
int maxAreaCounted = 0;

for (unsigned int i=0;i<contoursIn.size();i++)
{
    currentarea=cv::contourArea(contoursIn[i]);
    cv::Mat drawingMatCount = cv::Mat::zeros(ROI_INTERACTION,ROI_INTERACTION, CV_8UC1);
    cv::drawContours(drawingMatCount, contoursIn, i, 255, -1, 8);
    currentareaCounted = cv::countNonZero(drawingMatCount);

    if (currentarea>max)
        max=currentarea;      
    if (currentareaCounted>maxAreaCounted)
        maxAreaCounted=currentareaCounted;

}

Is there something that could be improved? This code works, but my doubt is about declaring a new matrix every iteration. Could this lead to some performance issue?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.