Ask Your Question

Revision history [back]

OpenCV 3.0.0 and OpenCL benchmark:

I am trying to understand the potential of OpenCL module of OpenCV 3.0.0.

This is related to a previous question of mine, where I understood that there might not exist many answers about this topic just yet. So I decided to ask you guys to help me benchmarking a piece of code.

I wrote an easy to compile simple code snippet that uses a webcam stream and finds Sobel edges and then blurs image some dozens of times. I'm blurring the image multiple times to create a strain on the processor, but feel free to change that part of the code, what is important is the comparison between OpenCL and non-OpenCL versions.

CODE:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main()
{

    cout << "Have OpenCL?: " << cv::ocl::haveOpenCL() << endl;

//  SWITCH OPENCL ON/OFF BY CHANGING THE INPUT OF THE FUNCTION BELLOW
    cv::ocl::setUseOpenCL(true);

    int nBlurs = 50;

    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    double timerSec = 0;
    unsigned short frameCounter = 0;

    while (cv::waitKey(1))
    {
        std::clock_t start;
        double time;

        start = std::clock();

        cv::UMat frame;
        cv::UMat frameGray;

        cam.read(frame);
        cv::cvtColor(frame, frameGray, cv::COLOR_BGR2GRAY);

        cv::UMat frameSobelx;
        cv::UMat frameSobely;

        cv::Sobel(frameGray, frameSobelx, frameGray.depth(), 1, 0, 3);
        cv::Sobel(frameGray, frameSobely, frameGray.depth(), 0, 1, 3);

        cv::UMat frameSobel;
        cv::bitwise_or(frameSobelx, frameSobely, frameSobel);

        cv::UMat blurredSobel;
        for (int n = 0; n < nBlurs; n++)
            cv::blur(frameSobel, blurredSobel, cv::Size(3,3));

        cv::imshow("Sobel blurred Frame", blurredSobel);

        frameCounter++;

        time = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;

        timerSec += time;

        if (timerSec >= 1)
        {
            timerSec = 0;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }

    }

    return 0;
}

My System

Processor: Intel Core 2 duo 3GHZ

Grahics Card: Nvidia GeForce GT 220

OS: Linux Gentoo

My Results

With OpenCL: 15 FPS, 150% CPU usage and 88% GPU usage

Without OpenCL: 27 FPS, 98% CPU usage and 5% GPU usage

This result is extremely strange.. how come that with OpenCL the GPU is working at 88% capacity and the CPU is at 150%? And, on top of that? It is slower than the non-GPU version?

I'm trying to figure out if this is a hardware problem. Could anyone please compile and make this test?

OPENCL image description

NO-OPENCL image description

Best regards!

OpenCV 3.0.0 and OpenCL benchmark:benchmark: Sobel edge detection

I am trying to understand the potential of OpenCL module of OpenCV 3.0.0.

This is related to a previous question of mine, where I understood that there might not exist many answers about this topic just yet. So I decided to ask you guys to help me benchmarking a piece of code.

I wrote an easy to compile simple code snippet that uses a webcam stream and finds Sobel edges and then blurs image some dozens of times. I'm blurring the image multiple times to create a strain on the processor, but feel free to change that part of the code, what is important is the comparison between OpenCL and non-OpenCL versions.

CODE:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main()
{

    cout << "Have OpenCL?: " << cv::ocl::haveOpenCL() << endl;

//  SWITCH OPENCL ON/OFF BY CHANGING THE INPUT OF THE FUNCTION BELLOW
    cv::ocl::setUseOpenCL(true);

    int nBlurs = 50;

    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    double timerSec = 0;
    unsigned short frameCounter = 0;

    while (cv::waitKey(1))
    {
        std::clock_t start;
        double time;

        start = std::clock();

        cv::UMat frame;
        cv::UMat frameGray;

        cam.read(frame);
        cv::cvtColor(frame, frameGray, cv::COLOR_BGR2GRAY);

        cv::UMat frameSobelx;
        cv::UMat frameSobely;

        cv::Sobel(frameGray, frameSobelx, frameGray.depth(), 1, 0, 3);
        cv::Sobel(frameGray, frameSobely, frameGray.depth(), 0, 1, 3);

        cv::UMat frameSobel;
        cv::bitwise_or(frameSobelx, frameSobely, frameSobel);

        cv::UMat blurredSobel;
        for (int n = 0; n < nBlurs; n++)
            cv::blur(frameSobel, blurredSobel, cv::Size(3,3));

        cv::imshow("Sobel blurred Frame", blurredSobel);

        frameCounter++;

        time = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;

        timerSec += time;

        if (timerSec >= 1)
        {
            timerSec = 0;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }

    }

    return 0;
}

My System

Processor: Intel Core 2 duo 3GHZ

Grahics Card: Nvidia GeForce GT 220

OS: Linux Gentoo

My Results

With OpenCL: 15 FPS, 150% CPU usage and 88% GPU usage

Without OpenCL: 27 FPS, 98% CPU usage and 5% GPU usage

This result is extremely strange.. how come that with OpenCL the GPU is working at 88% capacity and the CPU is at 150%? And, on top of that? It is slower than the non-GPU version?

I'm trying to figure out if this is a hardware problem. Could anyone please compile and make this test?

OPENCL image description

NO-OPENCL image description

Best regards!

OpenCV 3.0.0 and OpenCL benchmark: Sobel edge detection

I am trying to understand the potential of OpenCL module of OpenCV 3.0.0.

This is related to a previous question of mine, where I understood that there might not exist many answers about this topic just yet. So I decided to ask you guys to help me benchmarking a piece of code.

I wrote an easy to compile simple code snippet that uses a webcam stream and finds Sobel edges and then blurs image some dozens of times. I'm blurring the image multiple times to create a strain on the processor, but feel free to change that part of the code, what is important is the comparison between OpenCL and non-OpenCL versions.

EDIT: Edited code to correct mistake in FPS calculation CODE:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main()
{
     cout << "Have OpenCL?: " << cv::ocl::haveOpenCL() << endl;

// /*  SWITCH OPENCL ON/OFF BY CHANGING THE INPUT OF THE FUNCTION BELLOW
IN LINE BELLOW */
    cv::ocl::setUseOpenCL(true);
 /*                                      */
    int nBlurs = 50;

    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    double timerSec = 0;
    unsigned short long frameCounter = 0;

    std::time_t timeBegin = std::time(0);
    int tick = 0;

    while (cv::waitKey(1))
(1)
    {
        std::clock_t start;
        double time;

        start = std::clock();

        cv::UMat frame;
        cv::UMat frameGray;

        cam.read(frame);
        cv::cvtColor(frame, frameGray, cv::COLOR_BGR2GRAY);

        cv::UMat frameSobelx;
        cv::UMat frameSobely;

        cv::Sobel(frameGray, frameSobelx, frameGray.depth(), 1, 0, 3);
        cv::Sobel(frameGray, frameSobely, frameGray.depth(), 0, 1, 3);

        cv::UMat frameSobel;
        cv::bitwise_or(frameSobelx, frameSobely, frameSobel);

        cv::UMat blurredSobel;
         for (int n = 0; n < nBlurs; n++)
            cv::blur(frameSobel, blurredSobel, cv::Size(3,3));

        cv::imshow("Sobel blurred Frame", blurredSobel);
        cv::waitKey(1);

        frameCounter++;

        time std::time_t timeNow = ( std::clock() std::time(0) - start ) / (double) CLOCKS_PER_SEC;

        timerSec += time;
timeBegin;

        if (timerSec (timeNow - tick >= 1)
        {
            timerSec = 0;
tick++;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }
     }

    return 0;
}

My System

Processor: Intel Core 2 duo 3GHZ

Grahics Card: Nvidia GeForce GT 220

OS: Linux Gentoo

My Results

With OpenCL: 15 21 FPS, 150% CPU usage and 88% GPU usage

Without OpenCL: 27 26 FPS, 98% CPU usage and 5% GPU usage

This result is extremely strange.. how come that with OpenCL the GPU is working at 88% capacity and the CPU is at 150%? And, on top of that? It is slower than the non-GPU version?

I'm trying to figure out if this is a hardware problem. Could anyone please compile and make this test?

OPENCL image description

NO-OPENCL image description

Best regards!

OpenCV 3.0.0 and OpenCL benchmark: Sobel edge detection

I am trying to understand the potential of OpenCL module of OpenCV 3.0.0.

This is related to a previous question of mine, where I understood that there might not exist many answers about this topic just yet. So I decided to ask you guys to help me benchmarking a piece of code.

I wrote an easy to compile simple code snippet that uses a webcam stream and finds Sobel edges and then blurs image some dozens of times. I'm blurring the image multiple times to create a strain on the processor, but feel free to change that part of the code, what is important is the comparison between OpenCL and non-OpenCL versions.

EDIT: Edited code to correct mistake in FPS calculation calculation

CODE:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main()
{
    cout << "Have OpenCL?: " << cv::ocl::haveOpenCL() << endl;

/*  SWITCH OPENCL ON/OFF IN LINE BELLOW */
    cv::ocl::setUseOpenCL(true);
/*                                      */
    int nBlurs = 50;

    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    long frameCounter = 0;

    std::time_t timeBegin = std::time(0);
    int tick = 0;

    while (1)
    {
        cv::UMat frame;
        cv::UMat frameGray;

        cam.read(frame);
        cv::cvtColor(frame, frameGray, cv::COLOR_BGR2GRAY);

        cv::UMat frameSobelx;
        cv::UMat frameSobely;

        cv::Sobel(frameGray, frameSobelx, frameGray.depth(), 1, 0, 3);
        cv::Sobel(frameGray, frameSobely, frameGray.depth(), 0, 1, 3);

        cv::UMat frameSobel;
        cv::bitwise_or(frameSobelx, frameSobely, frameSobel);

        cv::UMat blurredSobel;

        for (int n = 0; n < nBlurs; n++)
            cv::blur(frameSobel, blurredSobel, cv::Size(3,3));

        cv::imshow("Sobel blurred Frame", blurredSobel);
        cv::waitKey(1);

        frameCounter++;

        std::time_t timeNow = std::time(0) - timeBegin;

        if (timeNow - tick >= 1)
        {
            tick++;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }
    }

    return 0;
}

My System

Processor: Intel Core 2 duo 3GHZ

Grahics Card: Nvidia GeForce GT 220

OS: Linux Gentoo

My Results

With OpenCL: 21 FPS, 150% CPU usage and 88% GPU usage

Without OpenCL: 26 FPS, 98% CPU usage and 5% GPU usage

This result is extremely strange.. how come that with OpenCL the GPU is working at 88% capacity and the CPU is at 150%? And, on top of that? It is slower than the non-GPU version?

I'm trying to figure out if this is a hardware problem. Could anyone please compile and make this test?

OPENCL image description

NO-OPENCL image description

Best regards!

OpenCV 3.0.0 and OpenCL benchmark: Sobel edge detection

I am trying to understand the potential of OpenCL module of OpenCV 3.0.0.

This is related to a previous question of mine, where I understood that there might not exist many answers about this topic just yet. So I decided to ask you guys to help me benchmarking a piece of code.

I wrote an easy to compile simple code snippet that uses a webcam stream and finds Sobel edges and then blurs image some dozens of times. I'm blurring the image multiple times to create a strain on the processor, but feel free to change that part of the code, what is important is the comparison between OpenCL and non-OpenCL versions.

EDIT: Edited code to correct mistake in FPS calculation

CODE:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main()
{
    cout << "Have OpenCL?: " << cv::ocl::haveOpenCL() << endl;

/*  SWITCH OPENCL ON/OFF IN LINE BELLOW */
    cv::ocl::setUseOpenCL(true);
/*                                      */
    int nBlurs = 50;

    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    long frameCounter = 0;

    std::time_t timeBegin = std::time(0);
    int tick = 0;

    cv::UMat frame;
    cv::UMat frameGray;
    cv::UMat frameSobelx;
    cv::UMat frameSobely;

    cv::UMat frameSobel;
    cv::UMat blurredSobel;

    while (1)
    {
        cv::UMat frame;
        cv::UMat frameGray;

        cam.read(frame);
        cv::cvtColor(frame, frameGray, cv::COLOR_BGR2GRAY);

        cv::UMat frameSobelx;
        cv::UMat frameSobely;

        cv::Sobel(frameGray, frameSobelx, frameGray.depth(), 1, 0, 3);
        cv::Sobel(frameGray, frameSobely, frameGray.depth(), 0, 1, 3);

        cv::UMat frameSobel;
        cv::bitwise_or(frameSobelx, frameSobely, frameSobel);

        cv::UMat blurredSobel;

        for (int n = 0; n < nBlurs; n++)
            cv::blur(frameSobel, blurredSobel, cv::Size(3,3));

        cv::imshow("Sobel blurred Frame", blurredSobel);
        cv::waitKey(1);

        frameCounter++;

        std::time_t timeNow = std::time(0) - timeBegin;

        if (timeNow - tick >= 1)
        {
            tick++;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }
    }

    return 0;
}

My System

Processor: Intel Core 2 duo 3GHZ

Grahics Card: Nvidia GeForce GT 220

OS: Linux Gentoo

My Results

With OpenCL: 21 FPS, 150% CPU usage and 88% GPU usage

Without OpenCL: 26 FPS, 98% CPU usage and 5% GPU usage

This result is extremely strange.. how come that with OpenCL the GPU is working at 88% capacity and the CPU is at 150%? And, on top of that? It is slower than the non-GPU version?

I'm trying to figure out if this is a hardware problem. Could anyone please compile and make this test?

OPENCL image description

NO-OPENCL image description

Best regards!

OpenCV 3.0.0 and OpenCL benchmark: Sobel edge detection

I am trying to understand the potential of OpenCL module of OpenCV 3.0.0.

This is related to a previous question of mine, where I understood that there might not exist many answers about this topic just yet. So I decided to ask you guys to help me benchmarking a piece of code.

I wrote an easy to compile simple code snippet that uses a webcam stream and finds Sobel edges and then blurs image some dozens of times. I'm blurring the image multiple times to create a strain on the processor, but feel free to change that part of the code, what is important is the comparison between OpenCL and non-OpenCL versions.

EDIT: Edited code to correct mistake in FPS calculation

CODE:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main()
{
    cout << "Have OpenCL?: " << cv::ocl::haveOpenCL() << endl;

/*  SWITCH OPENCL ON/OFF IN LINE BELLOW */
    cv::ocl::setUseOpenCL(true);
/*                                      */
    int nBlurs = 50;

    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    long frameCounter = 0;

    std::time_t timeBegin = std::time(0);
    int tick = 0;

    cv::UMat frame;
    cv::UMat frameGray;
    cv::UMat frameSobelx;
    cv::UMat frameSobely;

    cv::UMat frameSobel;
    cv::UMat blurredSobel;

    while (1)
    {
        cam.read(frame);
        cv::cvtColor(frame, frameGray, cv::COLOR_BGR2GRAY);

        cv::Sobel(frameGray, frameSobelx, frameGray.depth(), 1, 0, 3);
        cv::Sobel(frameGray, frameSobely, frameGray.depth(), 0, 1, 3);

        cv::bitwise_or(frameSobelx, frameSobely, frameSobel);

        for (int n = 0; n < nBlurs; n++)
            cv::blur(frameSobel, blurredSobel, cv::Size(3,3));

        cv::imshow("Sobel blurred Frame", blurredSobel);
        cv::waitKey(1);

        frameCounter++;

        std::time_t timeNow = std::time(0) - timeBegin;

        if (timeNow - tick >= 1)
        {
            tick++;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }
    }

    return 0;
}

My System

Processor: Intel Core 2 duo 3GHZ

Grahics Card: Nvidia GeForce GT 220

OS: Linux Gentoo

My Results

With OpenCL: 21 FPS, 150% 180% CPU usage and 88% GPU usage

Without OpenCL: 26 FPS, 98% CPU usage and 5% GPU usage

This result is extremely strange.. how come that with OpenCL the GPU is working at 88% capacity and the CPU is at 150%? And, on top of that? It is slower than the non-GPU version?

I'm trying to figure out if this is a hardware problem. Could anyone please compile and make this test?

OPENCL image description

NO-OPENCL image description

Best regards!