Reputation: 53
I have a project made with Visual Studio 2012 using OpenCV, it captures video from an webcam and check if there are faces in. I tested a few days and it was working but today i tested it again and is giving me this error and i dont know what to do! I havent changed anything with the code or the Paths of OpenCV.....
Code:
#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;
}
Picture:
EDIT:
The errors pop-out at the same time but i must close the window to check the others so:
1st Error (Window one): Unhandled exception at at 0x74FB1D4D in Detetor de Rosto.exe Microsoft C++ exception:cv::Exception at memory location 0x00D6C280.
2nd Error (Console one): OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file C:\buildslave64\win64_amdoc1\2_4_PackSlave-win32-vc11-shared\opencv\modules\imgproc\src\color.cpp, line 3737
3rd Error (Down one): KernelBase.dll!_RaiseException@16() msvcr110.dll!_CxxThrowException(voidpExceptionObject,const_s_ThrowInfopThrowInfo) Line 152 opencv_core249.dll!59807dc5() [Frames below may be incorrect and/or missing, no symbols loaded for opencv_core249.dll]
EDIT 2:
Also when i close the errors message it opens an file called Throw.cpp and it contains this code:
/***
*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
}
EDIT 3:
When it is compiling appears this things down there right before the error!
Upvotes: 0
Views: 2856
Reputation: 79
#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;
}
Try this I hope it will help.................
Upvotes: 1
Reputation: 180295
The first error is caused by your lack of exception handling. There's no catch
which will deal with the error. From there on it's all downhill. Trying to continue in a bad state, instead of handling the exception will corrupt OpenCV's internal state.
Upvotes: 1