簡體   English   中英

使用OpenCV的Visual Studio錯誤?

[英]Visual Studio bug with OpenCV?

我有一個使用OpenCV和Visual Studio 2012制作的項目,它從網絡攝像頭捕獲視頻並檢查是否有臉孔。我測試了幾天,它可以正常工作,但今天我再次對其進行了測試,但出現此錯誤,但我沒有知道要做什么! 我沒有使用代碼或OpenCV的路徑更改任何內容。

碼:

#include<stdio.h>
#include<math.h>
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv2\objdetect\objdetect.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<vector>

using namespace cv;
using namespace std;

int main()
    {
    CascadeClassifier face_cascade;
    if(!face_cascade.load("c:\\haar\\haarcascade_frontalface_alt2.xml")) {
        printf("Erro a carregar o ficheiro cascade para o rosto!");
        return 1;
    }
    VideoCapture capture(0);
    if(!capture.isOpened())
    {
        printf("Erro ao tentar iniciar a camara!");
        return 1;
    }
    Mat cap_img,gray_img;
    vector<Rect> faces;
    while(1)
    {
        capture >> cap_img;
        cvtColor(cap_img, gray_img, CV_RGB2GRAY);
        cv::equalizeHist(gray_img,gray_img);
        face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
        for(int i=0; i < faces.size();i++)
        {
            Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
            Point pt2(faces[i].x,faces[i].y);
            rectangle(cap_img, pt1, pt2, cvScalar(191,191,191), 2, 8, 0);
        }
        imshow("Result", cap_img);
        if (waitKey(1)==27);
            break;
    }
    return 0;
}

圖片:

錯誤圖片

編輯:

錯誤會同時彈出,但是我必須關閉窗口才能檢查其他錯誤:

第一個錯誤(窗口一):Detetor de Rosto.exe中0x74FB1D4D處未處理的異常Microsoft C ++異常:cv ::異常在內存位置0x00D6C280。


第二個錯誤(控制台一個):OpenCV錯誤:cv :: cvtColor,文件C:\\ buildslave64 \\ win64_amdoc1 \\ 2_4_PackSlave-win32-vc11-shared \\ opencv \\ modules \\中的斷言失敗(scn == 3 || scn == 4) imgproc \\ src \\ color.cpp,第3737行


第三個錯誤(下一個):KernelBase.dll!_RaiseException@16()msvcr110.dll!_CxxThrowException(void pExceptionObject,const_s_ThrowInfo pThrowInfo)第152行opencv_core249.dll!59807dc5()[下面的幀可能不正確和/或丟失,沒有符號為opencv_core249.dll加載]

編輯2:

另外,當我關閉錯誤消息時,它還會打開一個名為Throw.cpp的文件,其中包含以下代碼:

/***
*throw.cxx - Implementation of the 'throw' command.
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       Implementation of the exception handling 'throw' command.
*
*       Entry points:
*       * _CxxThrowException - does the throw.
****/

#include <stddef.h>
#include <windows.h>
#include <mtdll.h>
#include <ehdata.h>
#include <eh.h>
#include <ehhooks.h>
#include <ehassert.h>
#include <trnsctrl.h>


#pragma hdrstop

//
// Make sure PULONG_PTR is available
//

#if defined(_X86_)
#define _W64 __w64
#else
#define _W64
#endif

#if !defined(PULONG_PTR)
#if defined(_WIN64)
typedef unsigned __int64 *      PULONG_PTR;
#else
typedef _W64 unsigned long *    PULONG_PTR;
#endif
#endif

#if defined(_M_X64)
extern "C" PVOID _ReturnAddress(VOID);
#pragma intrinsic(_ReturnAddress)
#endif

/////////////////////////////////////////////////////////////////////////////
//
// _CxxThrowException - implementation of 'throw'
//
// Description:
//      Builds the NT Exception record, and calls the NT runtime to initiate
//      exception processing.
//
//      Why is pThrowInfo defined as _ThrowInfo?  Because _ThrowInfo is secretly
//      snuck into the compiler, as is the prototype for _CxxThrowException, so
//      we have to use the same type to keep the compiler happy.
//
//      Another result of this is that _CRTIMP can't be used here.  Instead, we
//      synthesisze the -export directive below.
//
// Returns:
//      NEVER.  (until we implement resumable exceptions, that is)
//

// We want double underscore for CxxThrowException for ARM CE only
__declspec(noreturn) extern "C" void __stdcall
#if !defined(_M_ARM) || defined(_M_ARM_NT)
_CxxThrowException(
#else
__CxxThrowException(
#endif
        void*           pExceptionObject,   // The object thrown
        _ThrowInfo*     pThrowInfo          // Everything we need to know about it
) {
        EHTRACE_ENTER_FMT1("Throwing object @ 0x%p", pExceptionObject);

        static const EHExceptionRecord ExceptionTemplate = { // A generic exception record
            EH_EXCEPTION_NUMBER,            // Exception number
            EXCEPTION_NONCONTINUABLE,       // Exception flags (we don't do resume)
            NULL,                           // Additional record (none)
            NULL,                           // Address of exception (OS fills in)
            EH_EXCEPTION_PARAMETERS,        // Number of parameters
            {   EH_MAGIC_NUMBER1,           // Our version control magic number
                NULL,                       // pExceptionObject
                NULL,
#if _EH_RELATIVE_OFFSETS
                NULL                        // Image base of thrown object
#endif
            }                      // pThrowInfo
        };
        EHExceptionRecord ThisException = ExceptionTemplate;    // This exception

        ThrowInfo* pTI = (ThrowInfo*)pThrowInfo;
        if (pTI && (THROW_ISWINRT( (*pTI) ) ) )
        {
            ULONG_PTR *exceptionInfoPointer = *reinterpret_cast<ULONG_PTR**>(pExceptionObject);
            exceptionInfoPointer--; // The pointer to the ExceptionInfo structure is stored sizeof(void*) infront of each WinRT Exception Info.

            WINRTEXCEPTIONINFO* wei = reinterpret_cast<WINRTEXCEPTIONINFO*>(*exceptionInfoPointer);
            pTI = wei->throwInfo;
        }

        //
        // Fill in the blanks:
        //
        ThisException.params.pExceptionObject = pExceptionObject;
        ThisException.params.pThrowInfo = pTI;
#if _EH_RELATIVE_OFFSETS
        PVOID ThrowImageBase = RtlPcToFileHeader((PVOID)pTI, &ThrowImageBase);
        ThisException.params.pThrowImageBase = ThrowImageBase;
#endif

        //
        // If the throw info indicates this throw is from a pure region,
        // set the magic number to the Pure one, so only a pure-region
        // catch will see it.
        //
        // Also use the Pure magic number on Win64 if we were unable to
        // determine an image base, since that was the old way to determine
        // a pure throw, before the TI_IsPure bit was added to the FuncInfo
        // attributes field.
        //
        if (pTI != NULL)
        {
            if (THROW_ISPURE(*pTI))
            {
                ThisException.params.magicNumber = EH_PURE_MAGIC_NUMBER1;
            }
#if _EH_RELATIVE_OFFSETS
            else if (ThrowImageBase == NULL)
            {
                ThisException.params.magicNumber = EH_PURE_MAGIC_NUMBER1;
            }
#endif
        }

        //
        // Hand it off to the OS:
        //

        EHTRACE_EXIT;
#if defined(_M_X64) && defined(_NTSUBSET_)
        RtlRaiseException( (PEXCEPTION_RECORD) &ThisException );
#else
        RaiseException( ThisException.ExceptionCode,
                        ThisException.ExceptionFlags,
                        ThisException.NumberParameters,
                        (PULONG_PTR)&ThisException.params );
#endif
}

編輯3:

在編譯時,出現此錯誤之前的錯誤!

在此處輸入圖片說明

第一個錯誤是由您缺乏異常處理引起的。 沒有catch將處理該錯誤。 從那里到那里都是下坡路。 嘗試以不良狀態繼續運行,而不是處理異常會破壞OpenCV的內部狀態。

    #include<stdio.h>
    #include<math.h>
    #include<opencv\cv.h>
    #include<opencv\highgui.h>
    #include<opencv2\objdetect\objdetect.hpp>
    #include<opencv2\highgui\highgui.hpp>
    #include<opencv2\imgproc\imgproc.hpp>
    #include<vector>

    using namespace cv;
    using namespace std;

    int main()
        {
        CascadeClassifier face_cascade;
        if(!face_cascade.load("c:\\haar\\haarcascade_frontalface_alt2.xml")) {
            printf("Erro a carregar o ficheiro cascade para o rosto!");
            return 1;
        }
        VideoCapture capture(0);
        if(!capture.isOpened())
        {
            printf("Erro ao tentar iniciar a camara!");
            return 1;
        }
        Mat cap_img,gray_img;
        vector<Rect> faces;
        while(1)
        {
            capture >> cap_img;
if(!cap_img.empty()){
            cvtColor(cap_img, gray_img, CV_RGB2GRAY);
            cv::equalizeHist(gray_img,gray_img);
            face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
            for(int i=0; i < faces.size();i++)
            {
                Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
                Point pt2(faces[i].x,faces[i].y);
                rectangle(cap_img, pt1, pt2, cvScalar(191,191,191), 2, 8, 0);
            }
            imshow("Result", cap_img);
            if (waitKey(1)==27);
                break;
}
else{
        printf("No Frame");
break;
}
        }
        return 0;
    }

試試這個,希望對你有幫助.................

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM