0

我编写程序来捕捉人像,但是当我运行这个程序时,它在程序运行大约 10 秒时显示错误。有人可以帮助我这些程序有什么问题吗?

抱歉,如果我的代码看起来如此复杂,因为这是我的第一个 OpenCV 程序,那么我尝试在这段代码中编写各种东西。

  #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;
     }

然后它错误

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

和程序在这些地方显示错误

  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;
   }
4

1 回答 1

0

您从相机捕获的图像指向驱动程序内存

在将其传递给另一个线程之前,您必须对其进行 clone()。

于 2013-08-11T07:44:06.877 回答