c++ - OpenCV 的 Visual Studio 错误?

标签 c++ visual-studio opencv visual-studio-2012

我有一个使用 Visual Studio 2012 使用 OpenCV 制作的项目,它从网络摄像头捕获视频并检查是否有面孔。我测试了几天并且它工作正常但今天我再次测试它并给我这个错误我不知道该怎么办!我没有改变任何代码或 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;
}

图片:

Image of the error

编辑:

错误同时弹出,但我必须关闭窗口以检查其他错误:

第一个错误(窗口一): Detetor de Rosto.exe 中 0x74FB1D4D 处的未处理异常 Microsoft C++ 异常:内存位置 0x00D6C280 处的 cv::Exception。


第二个错误(控制台一):OpenCV 错误:断言失败(scn == 3 || scn == 4)在 cv::cvtColor,文件 C:\buildslave64\win64_amdoc1\2_4_PackSlave-win32-vc11-shared\opencv\modules\imgproc\src\color.cpp,第 3737 行


第三个错误(下一个): KernelBase.dll!_RaiseException@16() msvcr110.dll!_CxxThrowException(voidpExceptionObject,const_s_ThrowInfopThrowInfo) 第 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:

编译时在错误之前出现这个东西!

enter image description here

最佳答案

第一个错误是由于您缺乏异常处理造成的。没有处理错误的catch。从那里开始一切都在走下坡路。尝试在错误状态下继续,而不是处理异常会破坏 OpenCV 的内部状态。

关于c++ - OpenCV 的 Visual Studio 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24934869/

相关文章:

c# - 霍纳算法

c++ - 当前 OpenCV 中的 lib 文件夹(或其替代文件夹)在哪里?

opencv - 在这种情况下,Haar Cascade 会不会过于准确而无用?

c++ - 如何在 Windows 上使用 Vim 编译 C++ 代码?

c++ - C++ 或 Qt 中的文件相关异常类

regex - Visual Studio 2008 搜索和替换正则表达式

opencv - OpenCL:为什么不能将指向指针的指针作为参数传递给内核函数?

c++ - Turbo C++ 和 GCC(在 Windows 上使用代码块)以不同方式评估相同的三元表达式

c++ - 单链表时间

c++ - 如何查找项目从中继承其附加包含目录的内容