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

时间:2013-08-11 01:51:36

标签: opencv vector

我编写程序来捕获人类图片,但是当我运行这个程序时,它会在程序运行大约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;
   }

1 个答案:

答案 0 :(得分:0)

您从相机拍摄中获得的图像为pointing to driver memory

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