我有一个使用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;
}
照片:
修改
错误同时弹出,但我必须关闭窗口以检查其他错误:
第一个错误(第一个窗口): 检测器de Rosto.exe中0x74FB1D4D处的未处理异常Microsoft C ++异常:cv ::内存位置0x00D6C280处的异常。
第二个错误(控制台一):OpenCV错误:断言失败(scn == 3 || scn == 4)在cv :: cvtColor中,文件C:\ buildslave64 \ win64_amdoc1 \ 2_4_PackSlave-win32-vc11-shared \ opencv \ modules \ imgproc \ src \ color.cpp,第3737行
第3次错误(向下一次): 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:
当它正在编译时,错误发生之前出现了这些东西!
答案 0 :(得分:1)
第一个错误是由于缺少异常处理引起的。没有catch
可以处理错误。从那里开始,它都是下坡路。尝试继续处于错误状态而不是处理异常将破坏OpenCV的内部状态。
答案 1 :(得分:1)
#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;
}
试试这个我希望它会有所帮助.................