Problem with Video Object tracking with opencv



  • hello,

    I have a Problem with my source-code, the program should basicly track objects with a special colour (blue), it compiles without errors or so, but it is not running properly,

    #include<stdafx.h>
    #include <iostream>
    int main(int argc, char **argv[1])
    {
    CvCapture *capture = cvCaptureFromCAM(0);
    int frames = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);

    uchar *routdata, *goutdata, *target;

    //Create a Window
    cvNamedWindow("Video", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("Final_RG", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("Filtered_RG", CV_WINDOW_AUTOSIZE);

    //Bildskelett
    IplImage *image = 0;
    IplImage *routput = cvCreateImage( cvSize(640,480), 8, 3);
    IplImage *goutput = cvCreateImage( cvSize(640,480), 8, 3);
    IplImage *Final_RG = cvCreateImage( cvSize(640,480), 8, 3);
    IplImage *Filtered_RG = cvCreateImage( cvSize(640,480), 8, 3);

    int nFrames = 300;
    int j, k, m, n, p;

    // Pixelspeicher
    int rindex [500][2];
    int gindex [500][2];

    //Farberkennung
    int red = 000;
    int blue = 102;
    int Green= 255;

    //Video soll hier starten

    for (j = 0; j < nFrames; j++)
    {
    image = cvQueryFrame(capture);

    // für pixel benutzung
    int step = image->widthStep/sizeof(uchar);

    cvCopy(image, routput, NULL);
    cvCopy(image, goutput, NULL);

    // sonst ist das bild inverted
    routput->origin = image->origin;
    goutput->origin = image->origin;
    Final_RG->origin = image->origin;
    Filtered_RG->origin = image->origin;

    routdata = (uchar * ) routput->imageData;
    goutdata = (uchar * ) routput->imageData;

    k = 0, p = 0;
    for( m = 0; image->height; m++)
    {
    for( n = 0; image->width; n++)
    {
    if(routdata[m*step+n*3+2] > red && routdata[m*step+n*3+0] > blue)
    {
    😡 std::cout <<k<< std::endl;
    😡 rindex[k][0] = m;
    😡 rindex[k][1] = n;

    [b]I inserted an cout to figure out what "k" is doing. it is counting till 6000+[b]

    k = k + 1;
    }
    else
    {
    routdata[m*step+n*3+0] = 0;
    routdata[m*step+n*3+1] = 0;
    routdata[m*step+n*3+2] = 0;
    }

    if(routdata[m*step+n*3+2] > red && routdata[m*step+n*3+1] > blue)
    {
    gindex[p][0] = m;
    gindex[p][1] = n;

    p = p + 1;
    }
    else
    {
    goutdata[m*step+n*3+0] = 0;
    goutdata[m*step+n*3+1] = 0;
    goutdata[m*step+n*3+2] = 0;
    }
    }
    }
    cvAnd(routput, goutput, Final_RG, NULL);
    cvSmooth(Final_RG, Filtered_RG, CV_MEDIAN, 5, 5, 0, 0);
    target = (uchar 😉 Filtered_RG->imageData;

    int xmin = 400, xmax = 0;
    int ymin = 400, ymax = 0;
    for(m = 0; m < Filtered_RG->height; m++)
    {
    for(n = 0; n < Filtered_RG->width; n++)
    {
    if(target[m*step+n*3+2] > 100)
    {
    if(n < xmin)
    xmin = n;
    if(n > xmax)
    xmax = n;
    if(m < ymin)
    ymin = m;
    if(m > ymax)
    ymax = m;
    }
    }
    }

    cvRectangle(image, cvPoint(xmin, ymin), cvPoint(xmax, ymax), CV_RGB(0, 255, 0), 2, 8, 0);
    cvCircle(image, cvPoint((xmin + xmax)/2, (ymin+ymax)/2), 0, CV_RGB(255, 0, 0), 2, 8, 0);

    // show image
    cvShowImage("Video", image);
    cvShowImage("Final_RG", Final_RG);
    cvShowImage("Filtered_RG", Filtered_RG);

    cvWaitKey(0);
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("Video");
    cvDestroyWindow("Final_RG");
    cvDestroyWindow("Filtered_RG");

    return 0;
    }

    I guess that there is an unfriendly loop in my source code, but i can´t find out where and why,

    I´ll be very happy if someone could help me out.

    greetz



  • Dieser Thread wurde von Moderator/in pumuckl aus dem Forum C++ in das Forum Spiele-/Grafikprogrammierung verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.


Anmelden zum Antworten