Ask Your Question

Revision history [back]

cv::FindContours() spiking CPU usage to the limit

While developing some stuff that uses blob analysis , I realized my application was dropping frames. After evaluating what might be the cause, I singled out the findContours call as the culprit.

I created this small code snippet to understand what was going on,

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
int main()
{
    while ((char) cv::waitKey(30) != 'q')
    {
        cv::Size size = cv::Size(640, 480);

        cv::Mat testFindContours = cv::Mat::zeros(size, CV_8UC1);

        std::vector<std::vector<cv::Point> > contours;
        std::vector<cv::Vec4i> hierarchyObj;

        cv::findContours(testFindContours, contours, hierarchyObj, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

        cv::imshow("Black window", testFindContours);
    }

    return 0;
}

Weirdly enough, just by using findContours on a 640x480 completely black image, my CPU spikes to ~300% usage (more than one CPU cores at full speed).

VGA

The number on the most right-hand side is the CPU usage % (from "top" in linux)

Even more weird, is when I reduced the Size to 320x240, now the CPU usage stayes below 2%

QVGA

I started playing a bit with the size, and I have the impression that there is a specific size at which the CPU spikes up to 300%, but I didn't go far enough to check which size that is exactly, so I am not completely sure about this.

What am I missing here? Is it normal that findContours even consumes anything on a completely black image? Might this be a bug?

The CPU I am doing these tests in is a intel core i7 3.4 ghz.

Best regards.

cv::FindContours() spiking CPU usage to the limit

While developing some stuff that uses blob analysis , I realized my application was dropping frames. After evaluating what might be the cause, I singled out the findContours call as the culprit.

I created this small code snippet to understand what was going on,

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
int main()
{
    while ((char) cv::waitKey(30) != 'q')
    {
        cv::Size size = cv::Size(640, 480);

        cv::Mat testFindContours = cv::Mat::zeros(size, CV_8UC1);

        std::vector<std::vector<cv::Point> > contours;
        std::vector<cv::Vec4i> hierarchyObj;

        cv::findContours(testFindContours, contours, hierarchyObj, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

        cv::imshow("Black window", testFindContours);
    }

    return 0;
}

Weirdly enough, just by using findContours on a 640x480 completely black image, my CPU spikes to ~300% usage (more than one CPU cores at full speed).

VGA

The number on the most right-hand side is the CPU usage % (from "top" in linux)

Even more weird, weirder, is when I reduced the Size to 320x240, now the CPU usage stayes below 2%

QVGA

I started playing a bit with the size, and I have the impression that there is a specific size at which the CPU spikes up to 300%, but I didn't go far enough to check which size that is exactly, so I am not completely sure about this.

What am I missing here? Is it normal that findContours even consumes anything on a completely black image? Might this be a bug?

The CPU I am doing these tests in is a intel core i7 3.4 ghz.

Best regards.

cv::FindContours() spiking CPU usage to the limit

While developing some stuff that uses blob analysis , I realized my application was dropping frames. After evaluating what might be the cause, I singled out the findContours call as the culprit.

I created this small code snippet to understand what was going on,

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
int main()
{
    while ((char) cv::waitKey(30) != 'q')
    {
        cv::Size size = cv::Size(640, 480);

        cv::Mat testFindContours = cv::Mat::zeros(size, CV_8UC1);

        std::vector<std::vector<cv::Point> > contours;
        std::vector<cv::Vec4i> hierarchyObj;

        cv::findContours(testFindContours, contours, hierarchyObj, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

        cv::imshow("Black window", testFindContours);
    }

    return 0;
}

Weirdly enough, just by using findContours on a 640x480 completely black image, my CPU spikes to ~300% usage (more than one CPU cores at full speed).

VGA

The number on the most right-hand side is the CPU usage % (from "top" in linux)

Even weirder, is when I reduced the Size to 320x240, now the CPU usage stayes below 2%

QVGA

I started playing a bit with the size, and I have the impression that there is a specific size at which the CPU spikes up to 300%, but I didn't go far enough to check which size that is exactly, so I am not completely sure about this.

What am I missing here? Is it normal that findContours even consumes anything on a completely black image? Might this be a bug?

The CPU I am doing these tests in is a intel core i7 3.4 ghz.. I'm compiling this code in Debug configuration.

Best regards.

cv::FindContours() spiking CPU usage to the limit

While developing some stuff that uses blob analysis , I realized my application was dropping frames. After evaluating what might be the cause, I singled out the findContours call as the culprit.

I created this small code snippet to understand what was going on,

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
int main()
{
    while ((char) cv::waitKey(30) != 'q')
    {
        cv::Size size = cv::Size(640, 480);

        cv::Mat testFindContours = cv::Mat::zeros(size, CV_8UC1);

        std::vector<std::vector<cv::Point> > contours;
        std::vector<cv::Vec4i> hierarchyObj;

        cv::findContours(testFindContours, contours, hierarchyObj, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

        cv::imshow("Black window", testFindContours);
    }

    return 0;
}

Weirdly enough, just by using findContours on a 640x480 completely black image, my CPU spikes to ~300% usage (more than one CPU cores at full speed).

VGA

The number on the most right-hand side is the CPU usage % (from "top" in linux)

Even weirder, is when I reduced the Size to 320x240, now the CPU usage stayes below 2%

QVGA

I started playing a bit with the size, and I have the impression that there is a specific size at which the CPU spikes up to 300%, but I didn't go far enough to check which size that is exactly, so I am not completely sure about this.

What am I missing here? Is it normal that findContours even consumes anything on a completely black image? Might this be a bug?

The CPU I am doing these tests in is a intel core i7 3.4 ghz. and opencv version 3.2.0 I'm compiling this code in Debug configuration.

Best regards.

cv::FindContours() spiking CPU usage to the limit

While developing some stuff that uses blob analysis , I realized my application was dropping frames. After evaluating what might be the cause, I singled out the findContours call as the culprit.

I created this small code snippet to understand what was going on,

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
int main()
{
    while ((char) cv::waitKey(30) != 'q')
    {
        cv::Size size = cv::Size(640, 480);

        cv::Mat testFindContours = cv::Mat::zeros(size, CV_8UC1);

        std::vector<std::vector<cv::Point> > contours;
        std::vector<cv::Vec4i> hierarchyObj;

        cv::findContours(testFindContours, contours, hierarchyObj, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

        cv::imshow("Black window", testFindContours);
    }

    return 0;
}

Weirdly enough, just by using findContours on a 640x480 completely black image, my CPU spikes to ~300% usage (more than one CPU cores at full speed).

VGA

The number on the most right-hand side is the CPU usage % (from "top" in linux)

Even weirder, is when I reduced the Size to 320x240, now the CPU usage stayes below 2%

QVGA

I started playing a bit with the size, and I have the impression that there is a specific size at which the CPU spikes up to 300%, but I didn't go far enough to check which size that is exactly, so I am not completely sure about this.

What am I missing here? Is it normal that findContours even consumes anything on a completely black image? Might this be a bug?

The CPU I am doing these tests in is a intel core i7 3.4 ghz and opencv version 3.2.0 . I'm compiling this code in Debug configuration.

Best regards.