Object tracking lag problem

asked 2015-09-15 15:29:54 -0500

Eisen gravatar image

updated 2015-09-15 16:53:10 -0500

Hi, I am using this code for track 4 colored objects.I get video from 8 ps3 eye camera.When i comment // my trackFilteredObject line there is no lag.But when using this code i have lot latency.I cant understand why happening because my normal cpu usage ~%15 ram usage 6.3GB/15GB (%40) when run this code cpu usage ~20-23 ram usage 6.4GB . I think its not about cpu-ram performance.What am i doing wrong ?

Video: https://www.youtube.com/watch?v=_BKtJ... (You can see lag in first 10 sec.After 10 sen i comment tracking codes.)

Note:Kamerasayisi mean cameracount My Track Function:

void trackFilteredObject(Object theObject,Mat threshold,Mat HSV, Mat &cameraFeed){
    //max number of objects to be detected in frame
    const int FRAME_WIDTH = 5120;
const int FRAME_HEIGHT = 480;

    const int MAX_NUM_OBJECTS=50;
//minimum and maximum object area
const int MIN_OBJECT_AREA = 10*10;
    vector <Object> objects;

    Mat temp;
    //these two vectors needed for output of findContours
    vector< vector<Point> > contours;
    vector<Vec4i> hierarchy;
    //find contours of filtered image using openCV findContours function
    findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
    //use moments method to find our filtered object
    double refArea = 0;
    bool objectFound = false;
    if (hierarchy.size() > 0) {
        int numObjects = hierarchy.size();
        //if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter
            for (int index = 0; index >= 0; index = hierarchy[index][0]) {

                Moments moment = moments((cv::Mat)contours[index]);
                double area = moment.m00;

        //if the area is less than 20 px by 20px then it is probably just noise
        //if the area is the same as the 3/2 of the image size, probably just a bad filter
        //we only want the object with the largest area so we safe a reference area each
                //iteration and compare it to the area in the next iteration.

                    Object object;



                    objectFound = true;

                }else objectFound = false;
            //let user know you found an object
            if(objectFound ==true){
                //draw object location on screen

        }else putText(cameraFeed,"TOO MUCH NOISE! ADJUST FILTER",Point(0,50),1,2,Scalar(0,0,255),2);

My Main Code:

    void Run()

        int w, h;

        _fps = 30;
        IplImage *pCapImage[kameraSayisi];
        IplImage *pDisplayImage;
        PBYTE pCapBuffer = NULL;
        // Create camera instance
        for(int i = 0; i < kameraSayisi; i++)
            _cam[i] = CLEyeCreateCamera(_cameraGUID[i], _mode, _resolution, _fps);
            if(_cam[i] == NULL) return;
            // Get camera frame dimensions
            CLEyeCameraGetFrameDimensions(_cam[i], w, h);
            // Create the OpenCV images
            pCapImage[i] = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1);

            // Set some camera parameters
            CLEyeSetCameraParameter(_cam[i], CLEYE_GAIN, 0);
            CLEyeSetCameraParameter(_cam[i], CLEYE_EXPOSURE, 511);

            // Start capturing

        pDisplayImage = cvCreateImage(cvSize(w*kameraSayisi / 2, h * kameraSayisi/4 ), IPL_DEPTH_8U  ,1);

        if(_cam == NULL)        return;

  int iLastX = -1; 
 int iLastY = -1;

  //Capture a temporary image from the camera
    bool trackObjects = true;
    bool useMorphOps = true ...
edit retag flag offensive close merge delete


could you give ( RESIZED !! ) sample image showing objects that you want to detect

sturkmen gravatar imagesturkmen ( 2015-09-15 16:05:00 -0500 )edit

colored ping pong balls from 2 meter distance like ps3 move balls.

Eisen gravatar imageEisen ( 2015-09-15 16:22:45 -0500 )edit

are you satisfied with the code except lagging? let me think how to optimize it.

sturkmen gravatar imagesturkmen ( 2015-09-15 16:39:27 -0500 )edit

Pls check this. https://www.youtube.com/watch?v=_BKtJ... -- First 10 sec with trackFilteredObject(yellow,threshold,HSV,imgOriginal); functions. After 10 sec. i comment this lines.

Eisen gravatar imageEisen ( 2015-09-15 16:46:16 -0500 )edit