(opencv)调试断言失败,矢量下标超出范围



我写程序是为了捕捉人体图像,但当我运行这个程序时,当程序运行大约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:........vcincludevector
   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;
   }

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

在将它传递给另一个线程之前,您必须先克隆()它。

最新更新