none
project using Visual Studio 2008(C++) and OpenCV execution problem

    问题

  • I'm a Computer engg. student and developing an university project in VC 2008+ OpenCV.
    I'd code compiled in VC without any error but while executing it shows following error message box.

    Code is:-

    // blobtrack.cpp : implementation file

    #include "stdafx.h"
    #include "modeless.h"
    #include "AdderDlg.h"
    #include <cvaux.h>
    //#include <cv.h>
    #include <highgui.h>
    #include "modeldlg.h"


    #ifdef _DEBUG
    #undef THIS_FILE
    static char BASED_CODE THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CAdderDialog dialog

    static CvFGDetector* cvCreateFGDetector0()
    {
           return cvCreateFGDetectorBase(CV_BG_MODEL_FGD,NULL);
    }

    typedef struct DefModule_FGDetector
    {
        CvFGDetector* (*create)();
        const char* nickname;
        const char* description;
    } DefModule_FGDetector;
    //Array of FG detectors
    DefModule_FGDetector FGDetector_Modules[]={{cvCreateFGDetector0,"FG_0","Foreground Object Detection from Videos Containing Complex Background. ACM MM2003."}};

    /* List of BLOB DETECTION modules: */
    typedef struct DefModule_BlobDetector
    {
        CvBlobDetector* (*create)();
        const char* nickname;
        const char* description;
    } DefModule_BlobDetector;
    //Array of Blob detectors
    DefModule_BlobDetector BlobDetector_Modules[]={{cvCreateBlobDetectorCC,"BD_CC","Detect new blob by tracking CC of FG mask"}};
    /* List of BLOB TRACKING modules: */
    typedef struct DefModule_BlobTracker
    {
        CvBlobTracker* (*create)();
        const char* nickname;
        const char* description;
    } DefModule_BlobTracker;
    //Array of Blob trackers
    DefModule_BlobTracker BlobTracker_Modules[]={{cvCreateBlobTrackerCCMSPF,"CCMSPF","connected component tracking and MSPF resolver for collision"}};
    /* List of BLOB TRAJECTORY GENERATION modules: */
    typedef struct DefModule_BlobTrackGen
    {
        CvBlobTrackGen* (*create)();
        const char* nickname;
        const char* description;
    } DefModule_BlobTrackGen;
    //Array of Blob track generators
    DefModule_BlobTrackGen BlobTrackGen_Modules[]={{cvCreateModuleBlobTrackGenYML,"YML","Generate track record in YML format as synthetic video data"}};
    /* List of BLOB TRAJECTORY POST PROCESSING modules: */
    typedef struct DefModule_BlobTrackPostProc
    {
        CvBlobTrackPostProc* (*create)();
        const char* nickname;
        const char* description;
    } DefModule_BlobTrackPostProc;
    //Array of Blob post porocessing modules
    DefModule_BlobTrackPostProc BlobTrackPostProc_Modules[]={{cvCreateModuleBlobTrackPostProcKalman,"Kalman","Kalman filtering of blob position and size"}};

    /* List of BLOB TRAJECTORY ANALYSIS modules: */
    CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisDetector();

    typedef struct DefModule_BlobTrackAnalysis
    {
        CvBlobTrackAnalysis* (*create)();
        const char* nickname;
        const char* description;
    } DefModule_BlobTrackAnalysis;

    DefModule_BlobTrackAnalysis BlobTrackAnalysis_Modules[]={{cvCreateModuleBlobTrackAnalysisHistPVS,"HistPVS","Histogram of 5D feature vector analysis (x,y,vx,vy,state)"}};

    //=============================
    //    global count variables
    static int total=0;
    static int cars=0;
    static int sv=0;
    static int lv=0;
    // classification
    /* function responsible to classify
     * the blob as per blobSize
     */
    // --
    int classification(CvPoint p,CvSize s)// point p2 of Blob & size of image
    {
        if((((s.height-3)<=p.y )&&((s.height-1)>=p.y ))&& (s.width-119)<p.x)// triggering classification
        {
            return 1;
        }
        return 0;
    }
    // create ROI
    // --
    IplImage* createROI(IplImage* src)
    {
        IplImage* res, * roi;
        res = cvCreateImage(cvGetSize(src), 8, 3);
        roi = cvCreateImage(cvGetSize(src), 8, 1);
     
        /* prepare the 'ROI' image */
        cvZero(roi);
     
        CvPoint pt1,pt2;
        pt1.x=cvGetSize(src).width-120;
        pt1.y=cvGetSize(src).height-80;
        pt2.x=cvGetSize(src).width;
        pt2.y=cvGetSize(src).height;
        cvRectangle(roi,pt1,pt2,CV_RGB(255,255, 255),1, 8, 0);
         /* extract subimage */
        cvAnd(src, src, res, roi);
         /*
         * do the main processing with subimage here.
         * in this example, we simply invert the subimage
         */
        cvNot(res, res);
     
        /* 'restore' subimage */
        IplImage* roi_C3 = cvCreateImage(cvGetSize(src), 8, 3);
        cvMerge(roi, roi, roi, NULL, roi_C3);
        cvAnd(res, roi_C3, res, NULL);
     
        /* merge subimage with original image */
        cvNot(roi, roi);
        cvAdd(src, res, res, roi);
          return res;
    }     

    /*================= END MODULES DECRIPTION ===================================*/
    /* Run pipeline on all frames: */
    static int RunBlobTrackingAuto( CvCapture* pCap, CvBlobTrackerAuto* pTracker)
    {
        int                     key;

        /* Main loop: */
        while( pCap)
        {   /* Main loop: */
            IplImage*   pImg  = NULL;
            IplImage*   pMask = NULL;
            
            key=cvWaitKey(24);
            pImg = cvQueryFrame(pCap);
            
            if(pImg == NULL)
                    break;
                    
            /* Process: */
            pTracker->Process(pImg, pMask);

            /* Draw debug info: */
            // RGB frames
            if(pImg)
            {   /* Draw all information about test sequence: */
                char        str[1024],str2[1024];
                int         line_type = CV_AA;   // Change it to 8 to see non-antialiased graphics.
                CvFont      font;
                cvInitFont( &font,CV_FONT_HERSHEY_COMPLEX_SMALL, 0.3,0.4, 0, 1, line_type );
                int         i;
                //IplImage*   pI = cvCloneImage(pImg);
                // prepare ROI
                IplImage*   pI = createROI(pImg);

                for(i=pTracker->GetBlobNum(); i>0; i--)
                {
                    CvSize  TextSize;
                    CvBlob* pB = pTracker->GetBlob(i-1);
                    CvPoint p = cvPoint(cvRound(pB->x),cvRound(pB->y));
                    CvSize  s = cvSize(MAX(1,cvRound(CV_BLOB_RX(pB))), MAX(1,cvRound(CV_BLOB_RY(pB))));
                    //printf("%d  %d\n",s.width,s.height);
                    int c = cvRound(255*pTracker->GetState(CV_BLOB_ID(pB)));
                        int w,h;
                        CvPoint pt1,pt2;
                        w=s.width;
                        h=s.height;
                        pt1.x=p.x-w;
                        pt1.y=p.y-h;
                        pt2.x=p.x+w;
                        pt2.y=p.y+h;
                        cvRectangle(pI,pt2,pt1,CV_RGB(c,255-c,0),1,8,0);
                    p.x >>= 8;
                    p.y >>= 8;
                    s.width >>= 8;
                    s.height >>= 8;
                    // preparing for classification
                    if(classification(pt2,cvGetSize(pI))==1) //int  classification(Point p2,CvSize s)
                    {
                        sprintf_s(str,"%dX%d=%03d",h,w,CV_BLOB_ID(pB));
                        if(h>=10 && h<=22)  // for car classification
                        {
                                 cars++;
                                 total++;
                            printf("\nCar ID=%d",CV_BLOB_ID(pB));
                        }
                        else
                            if(h>=23 && h<=35)// for SV classification
                            {
                                     total++;
                                     sv++;
                                printf("\nSV ID=%d",CV_BLOB_ID(pB));
                            }
                            else
                                if(h>=36)// for LV classification
                                {
                                         total++;
                                         lv++;
                                    printf("\nLV ID=%d",CV_BLOB_ID(pB));
                                }
                        sprintf_s(str2,"%4d %4d %4d  %4d",cars,sv,lv,total);
                        system("cls");
                        printf("Log  >>\n");
                        printf("Cars   SV   LV  Total\n");
                        printf("%4d %4d %4d %5d",cars,sv,lv,total);
                    }
                    else
                    {
                        sprintf_s(str,"%dX%d=%03d",h,w,CV_BLOB_ID(pB));
                    }
                    cvPutText(pI, "<<  Log  >>", cvPoint(2,35), &font,  CV_RGB(0,0,0));
                    cvPutText(pI, "Cars   SV   LV  Total", cvPoint(2,45), &font,  CV_RGB(0,0,0));
                    cvPutText(pI, str2, cvPoint(2,55), &font,  CV_RGB(0,0,0));
                    cvGetTextSize( str, &font, &TextSize, NULL );
                    p.y -= s.height;
                    cvPutText( pI, str, pt2, &font, CV_RGB(0,255,255));
                    {
                        const char* pS = pTracker->GetStateDesc(CV_BLOB_ID(pB));

                        if(pS)
                        {
                            char* pStr = _strdup(pS);
                            char* pStrFree = pStr;

                            while (pStr && strlen(pStr) > 0)
                            {
                                char* str_next = strchr(pStr,'\n');

                                if(str_next)
                                {
                                    str_next[0] = 0;
                                    str_next++;
                                }

                                p.y += TextSize.height+1;
                                cvPutText( pI, pStr, p, &font, CV_RGB(0,255,255));
                                pStr = str_next;
                            }
                            free(pStrFree);
                        }
                    }

                }   /* Next blob. */;
                cvNamedWindow( "Tracking", 0);
                cvShowImage( "Tracking",pI );

                cvReleaseImage(&pI);
            }   /* Draw all information about test sequence. */
        }   /*  Main loop. */
        return 0;
    }   /* RunBlobTrackingAuto */
    CAdderDialog::CAdderDialog(CWnd* pParent): CDialog(CAdderDialog::IDD, pParent)
    {
        //{{AFX_DATA_INIT(CAdderDialog)
            // NOTE: the ClassWizard will add member initialization here
        //}}AFX_DATA_INIT
        ASSERT(pParent != NULL);

        m_pParent = pParent;
        m_nID = CAdderDialog::IDD;
    }

    void CAdderDialog::DoDataExchange(CDataExchange* pDX)
    {
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CAdderDialog)
            // NOTE: the ClassWizard will add DDX and DDV calls here
        //}}AFX_DATA_MAP
    }


    BEGIN_MESSAGE_MAP(CAdderDialog, CDialog)
        //{{AFX_MSG_MAP(CAdderDialog)
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()


    /////////////////////////////////////////////////////////////////////////////
    // CAdderDialog message handlers

    void CAdderDialog::OnOK()
    {
        CEdit* pEdit = (CEdit*) GetDlgItem(IDC_NEWTEXT);
        CListBox* pList = (CListBox*) (m_pParent->GetDlgItem(IDC_LIST));

        ASSERT(pList != NULL);
        ASSERT(pEdit != NULL);

        if (pList != NULL && pEdit != NULL)
        {
            CString str;
            pEdit->GetWindowText(str);
            pList->AddString(str);
        }
    }

    BOOL CAdderDialog::Create()
    {
        MessageBox("hello!","title",MB_OK);
        CvCapture*                  pCap = NULL;
        CvBlobTrackerAutoParam1     param = {0};
        CvBlobTrackerAuto*          pTracker = NULL;

        float       scale = 1;
        const char* fg_name = NULL;
        const char* bd_name = NULL;
        const char* bt_name = NULL;
        const char* btpp_name = NULL;
        const char* bta_name = NULL;
        char*       bta_data_name = NULL;
        char*       track_name = NULL;
        const char* bt_corr = NULL;
     
        DefModule_FGDetector*           pFGModule = NULL;
        DefModule_BlobDetector*         pBDModule = NULL;
        DefModule_BlobTracker*          pBTModule = NULL;
        DefModule_BlobTrackPostProc*    pBTPostProcModule = NULL;
        DefModule_BlobTrackGen*         pBTGenModule = NULL;
        DefModule_BlobTrackAnalysis*    pBTAnalysisModule = NULL;
         
         // Set default parameters for one processing:
            if(!fg_name)
                         fg_name = FGDetector_Modules[0].nickname;
            if(!bd_name)
                         bd_name = BlobDetector_Modules[0].nickname;
            if(!bt_name)
                         bt_name = BlobTracker_Modules[0].nickname;
            if(!btpp_name)
                         btpp_name = BlobTrackPostProc_Modules[0].nickname;
            if(!bta_name)
                          bta_name = BlobTrackAnalysis_Modules[0].nickname;

            scale = (float)atof("1");

        for(pFGModule=FGDetector_Modules; pFGModule->nickname; ++pFGModule)
            if( fg_name && _stricmp(fg_name,pFGModule->nickname)==0 )
                break;

        for(pBDModule=BlobDetector_Modules; pBDModule->nickname; ++pBDModule)
            if( bd_name && _stricmp(bd_name,pBDModule->nickname)==0 ) break;

        for(pBTModule=BlobTracker_Modules; pBTModule->nickname; ++pBTModule)
            if( bt_name && _stricmp(bt_name,pBTModule->nickname)==0 ) break;

        for(pBTPostProcModule=BlobTrackPostProc_Modules; pBTPostProcModule->nickname; ++pBTPostProcModule)
            if( btpp_name && _stricmp(btpp_name,pBTPostProcModule->nickname)==0 ) break;

        for(pBTAnalysisModule=BlobTrackAnalysis_Modules; pBTAnalysisModule->nickname; ++pBTAnalysisModule)
            if( bta_name && _stricmp(bta_name,pBTAnalysisModule->nickname)==0 ) break;

        /* Create source video: */
        // it captures from *.avi file(s)

        if((pCap = cvCaptureFromFile("video3.avi"))==NULL)
        {
            printf("Can't open %s file\n");
            return -1;
        }

        {   /* Create autotracker module and its components: */
            param.FGTrainFrames = 0;

            /* Create FG Detection module: */
            param.pFG = pFGModule->create();
            if(!param.pFG)
                puts("Can not create FGDetector module");
            param.pFG->SetNickName(pFGModule->nickname);
           // set_params(argc, argv, param.pFG, "fg", pFGModule->nickname);

            /* Create Blob Entrance Detection module: */
            param.pBD = pBDModule->create();
            if(!param.pBD)
                puts("Can not create BlobDetector module");
            param.pBD->SetNickName(pBDModule->nickname);

            /* Create blob tracker module: */
            param.pBT = pBTModule->create();
            if(!param.pBT)
                puts("Can not create BlobTracker module");
            param.pBT->SetNickName(pBTModule->nickname);

            /* Create blob trajectory generation module: */
            param.pBTGen = NULL;
            if(pBTGenModule && track_name && pBTGenModule->create)
            {
                param.pBTGen = pBTGenModule->create();
                param.pBTGen->SetFileName(track_name);
            }
            if(param.pBTGen)
                param.pBTGen->SetNickName(pBTGenModule->nickname);
                
            /* Create blob trajectory post processing module: */
            param.pBTPP = NULL;
            if(pBTPostProcModule && pBTPostProcModule->create)
                param.pBTPP = pBTPostProcModule->create();
            if(param.pBTPP)
                param.pBTPP->SetNickName(pBTPostProcModule->nickname);

            param.UsePPData = (bt_corr && _stricmp(bt_corr,"PostProcRes")==0);

            /* Create blob trajectory analysis module: */
            param.pBTA = NULL;
            if(pBTAnalysisModule && pBTAnalysisModule->create)
            {
                param.pBTA = pBTAnalysisModule->create();
                param.pBTA->SetFileName(bta_data_name);
            }
            if(param.pBTA)
                param.pBTA->SetNickName(pBTAnalysisModule->nickname);

            /* Create whole pipline: */
            printf("\nPrameter :-%s",param);
            pTracker = cvCreateBlobTrackerAuto1(&param);
            if(!pTracker)
                puts("Can not create BlobTrackerAuto");
        }

        /* Run pipeline: */
        RunBlobTrackingAuto( pCap, pTracker);
             
        if(param.pBT)
            cvReleaseBlobTracker(&param.pBT);
        if(param.pBD)
            cvReleaseBlobDetector(&param.pBD);
        if(param.pBTGen)
            cvReleaseBlobTrackGen(&param.pBTGen);
        if(param.pBTA)
            cvReleaseBlobTrackAnalysis(&param.pBTA);
        if(param.pFG)
            cvReleaseFGDetector(&param.pFG);
        if(pTracker)
            cvReleaseBlobTrackerAuto(&pTracker);

        if(pCap)
            cvReleaseCapture(&pCap);
        return 0;
        //return CDialog::Create(m_nID, m_pParent);
    }

    void CAdderDialog::OnCancel()
    {
        ((CMainDlg*)m_pParent)->BoxDone();
        DestroyWindow();
        exit(0);
    }

    void CAdderDialog::PostNcDestroy()
    {
        delete this;
    }

    So, please suggest me any solution.

    Thanks in advance.


    • 已移动 Yi Feng LiModerator 2012年3月23日 10:00 3rd party issue (From:Visual C++ Language)
    2012年3月7日 14:51

全部回复

  • what is the error message dialog?

    we can't see it.

    you should click the "Insert Image" button at the top of the edit box, which is at the far right..


    Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.

    2012年3月9日 2:02
  • Hi Rahul,

    According to your description, I'd like to suggest you move to OpenCV Forum for more information abourt your issue. And this thread will be moves to "Off-Topic Posts". It is because that we only discuss issuse regarding the C++ lanaguage, compiler and liker in "Visual C++ Language Forum".

    Thanks for your understanding and active participation in the MSDN Forum.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us


    2012年3月13日 7:08