Ask Your Question
0

How to accelerate my camera control?

asked 2014-02-05 07:20:53 -0600

tiho_bg gravatar image

updated 2014-02-05 07:44:22 -0600

I am working with opencv 2.48 and visual studio 2010. When I add into my code Gaussian filtering and canny edge detection, the time of the image capturing was increased. How can I accelerate this process. If I have to add more functions for image processing and object tracking I thing that the speed for image capturing will be decreased more? I am using uEye camera 1490-M-GL.

Here is my code:

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(){
    VideoCapture cap(0);
    cap.open(0);
    if (false)
    {
        return -1;
    }

    cap.set(CV_CAP_PROP_FRAME_WIDTH, 3840);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 2748);
    cap.set(CV_CAP_PROP_FPS, 30.00);
    cap.set(CV_CAP_PROP_POS_MSEC, 300);

    int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
    int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
    double fps = cap.get(CV_CAP_PROP_FPS);

    namedWindow("wind1", 0);
    namedWindow("wind50", 0);
        IplImage* videoFrame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);

        cout << "W" << width << "FPS" << fps << endl;

        Mat gray;
        int counter = 0;

        while(1)
        {
       Mat frame; 
       cap.read(frame);

       imshow("wind1", frame);

       if (!frame.data) break;

       cvtColor(frame, gray, COLOR_BGR2GRAY);
       GaussianBlur(gray, gray, Size(7,7), 1.5, 1.5);
           Canny(gray, gray, 0, 30, 3);

       imshow("wind50", gray);
       }
       return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-05 07:57:31 -0600

Basically it is normal that adding more functionality, and thus requiring more computational time, will increase the time between each framegrab and thus reduce the FPS.

I suggest trying the following:

  1. Start by compiling in release and not in debug. It removes tons of overhead and unneccesary checks once you know the function is working correctly.
  2. Try using GPU enabled counterparts of the functions. You will need to build openCV with CUDA or OpenCL support for that, but it works expecially well for larger images due to block processing.
  3. You are limiting your capture speed to 30 FPS, which I think is pretty low for an industrial cam.Most of them go easily to 60 FPS. Make sure it is enabled at the highest speed possible.
  4. Just don't expect that a combo of object tracking and detection will run at like 30 FPS. We have complete PhD studies about these problems, which all reach about 25FPS with tons of optimalisations.
  5. Last but not least, if you have a multicore system, this might be the good time to consider using threads and pushing threads to different cores to reduce the calculation time. However this is a step further and does require a good knowledge on parallelization.
edit flag offensive delete link more

Comments

Thank you for the information. I would like to ask is it possible to use IPP library with opencv 2.48 for speeding up the object tracking and image processing or opencl and cuda are the best solution?

tiho_bg gravatar imagetiho_bg ( 2014-02-05 11:22:46 -0600 )edit

it is indeed possible, however I have no idea which functions are internally updated for IPP use. You can rebuild opencv with the WITH_IPP property selected. However, this will require you to have a licensed IPP version installed.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-06 03:57:46 -0600 )edit

Question Tools

Stats

Asked: 2014-02-05 07:20:53 -0600

Seen: 657 times

Last updated: Feb 05 '14