Search code examples
copencvvideo-capturesamba

cvCreateFileCapture strange error


i'm trying to create a simple Opencv program in C that creates a file capture from a .avi, and it plays it in a window highlighting faces. I'm running a self-compiled version of Opencv (i already tried the same with a jpeg image and it works).

Building goes well, no errors, no warning, but when i launch it this the console output this:

Unknown parameter encountered: "server role" Ignoring unknown parameter "server role"

And the program simply stops

Previously it was complaining for a missing /home/#user/.smb/smb.conf file, so i tried installing samba ( even though i've still no idea what does samba have to do in all this )

here is my code:

main(){

    printf("Ciao!");

    cvNamedWindow("window", CV_WINDOW_AUTOSIZE);

    cvWaitKey(0);

    printf("ok");

    CvCapture* capture = cvCreateFileCapture("monsters.avi");


    CvHaarClassifierCascade* cascade = load_object_detector("haarcascade_frontalface_alt.xml");

    CvMemStorage* storage = cvCreateMemStorage(0);

    //List of the faces
    CvSeq* faces;

    while (0<10) {
        CvArr* image = cvQueryFrame(capture);


        double scale = 1;

        faces = cvHaarDetectObjects(image,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(1,1), cvSize(300,300));

        int i;

        for(i = 0; i < faces->total; i++ )
            {

                CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i );
                cvRectangle( image,
                            cvPoint(face_rect.x*scale,face_rect.y*scale),
                            cvPoint((face_rect.x+face_rect.width)*scale,(face_rect.y+face_rect.height)*scale),
                            CV_RGB(255,0,0) , 3, 8, 0);
            }

        cvReleaseMemStorage( &storage );

        cvShowImage("window", image);
    }

    cvWaitKey(0);

    printf("Ciao!");

}


I thank you for your answer, i switched to C++ for my trials. Now i did this:

int main(){
namedWindow("Video", CV_WINDOW_FREERATIO);

VideoCapture cap("sintel.mp4");
 if(!cap.isOpened())  // check if we succeeded
        return -1;

Mat edges;
for(;;){


    Mat frame;
    cap>>frame;
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);

    imshow("Video", edges);
    //cvWaitKey(0);

}


return(0);
}

Now it succesfully load the video and query a frame, evry time i press a key it obviously query another frame and everything works fine, but if i comment the waitkey() the program simply hangs for a bit and crashes if i try to close the window, i'm starting to think there is a problem with codecs or something like that...


Solution

  • Now it works fine, i changed cvWaitKey() with this

       if(waitKey(30) >= 0) break;
    

    I don't understand exactly why but now everything works as it should :)