0
votes

I write program to capture human picture , but when I run this program it show an error when program is run about 10 sec. Can some one help me what wrong with these program?

Sorry if my code look so complicate because this is my first OpenCV program then I try to write various thing in this code.

  #include <iostream>
    #include <Windows.h>

    #include <opencv/cv.h>
    #include <opencv/cxcore.h>
    #include <opencv/highgui.h>
    #include <iostream>
    #include <fstream> 

    using namespace std;
    using namespace cv;

    boolean thread_running = false;
    LPDWORD threadId;
    Mat img,check_end,cimage;
    HOGDescriptor hog;
    HANDLE setThread = NULL;
    Rect r,check;
    vector<Rect> found,found_filtered,temp;
    int picNo = 1;
    int timeCount = 0;
    IplImage crop;
    boolean dup;

    DWORD WINAPI thread(LPVOID lpParam)
    {       
       thread_running=true;
      found_filtered.clear();
      crop = img;
       hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);


       thread_running=false;
       return 0;
         }

          void draw_bounding_box(Mat img) {
                            size_t i, j;
            for (i=0; i<found.size(); i++)
            {
                 r = found[i];
                for (j=0; j<found.size(); j++)
                    if (j!=i && (r & found[j])==r)
                        break;
                if (j==found.size())
                    found_filtered.push_back(r);
            }
            for (i=0; i<found_filtered.size(); i++)
            {
            r = found_filtered[i];
            //cvRound = Converts floating-point number to integer
            r.x      += cvRound(r.width*0.1);
            r.width   = cvRound(r.width*0.8);
            r.y      += cvRound(r.height*0.06);
            r.height  = cvRound(r.height*0.9);
            //rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 0);

            }


     }

    int main (int argc, const char * argv[])
    {

    CvCapture *pCapture =cvCreateFileCapture("MOV00109.avi");
    if ( pCapture == NULL )
        {
            cout << "ERROR: Failed to open camera" << endl;
            return EXIT_FAILURE;
        }

    cvSetCaptureProperty( pCapture, CV_CAP_PROP_FRAME_WIDTH, 640 );
    cvSetCaptureProperty( pCapture, CV_CAP_PROP_FRAME_HEIGHT, 480 );

    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); 

    namedWindow("video capture", CV_WINDOW_AUTOSIZE);
    check_end = cvQueryFrame( pCapture );

    while (true)
    {   

       img = cvQueryFrame( pCapture );


        if(!thread_running) {

            CreateThread(NULL,0,thread,&img,0,threadId);
        }


        draw_bounding_box(img);

        imshow("video capture",img);
        if(timeCount >= 3 && 0 < found_filtered.size())
         { for (int i=0; i<found_filtered.size(); i++) 
            { r = found_filtered[i];
              dup = false;
              for (int j=0; j<temp.size(); j++)
                {  check = temp[j];
                   if( check.x == r.x && check.y == r.y)
                   {  dup = true;   
                       break;
                   }
                }
              if(!dup)
                { 
                  cvSetImageROI(&crop,r);
                  char filename[100];
                  sprintf(filename,"C%d.jpg",picNo++);
                  cvSaveImage( filename,&crop);
                  cvResetImageROI(&crop);
                }
            }

           timeCount = 0;
          }
       else 
           timeCount++;
       temp = found_filtered; 
       if(waitKey(100)>0 ) break; 

        }
        return 0;
     }

then it error

 debug assertion failed
   ....
   ...
   file:c:\........\vc\include\vector
   Line 932
   Expression: vector subscript out of range

and program show error at these

  void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
   {
    /* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
    (_Reserved);
    _debugger_hook_dummy = 0;
   }
1
please, avoid mixing c++ api and c api calls at all means. receipe for desaster. stick to the c++ api (cv::Mat) and throw out all cv* functions - berak

1 Answers

0
votes

the image you get from the camera capture is pointing to driver memory.

you'll have to clone() it before passing it to another thread.