OpenCV 및 C++을 처음 사용합니다. OpenCV를 Microsoft Visual Studio 2008 (32 비트)로 작업하고 Filtering Tutorial/Sobel Derivatives 및 기타 자습서가 작동하도록했습니다. opencv_contrib230d.lib opencv_calib3d230d.lib opencv_core230d.lib : 나는 링커 입력에이 라이브러리를 추가 한OpenCV Cascade Classifier Tutorial 예외
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** Function Headers */
void detectAndDisplay(Mat frame);
/** Global variables */
String face_cascade_name = "haarcascade_frontalface_alt.xml";
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
string window_name = "Capture - Face detection";
RNG rng(12345);
/** @function main */
int main(int argc, const char** argv)
{
CvCapture* capture;
Mat frame;
//-- 1. Load the cascades
if(!face_cascade.load(face_cascade_name)){ printf("--(!)Error loading\n"); return -1; };
if(!eyes_cascade.load(eyes_cascade_name)){ printf("--(!)Error loading\n"); return -1; };
//-- 2. Read the video stream
capture = cvCaptureFromCAM(-1);
if(capture)
{
while(true)
{
frame = cvQueryFrame(capture);
//-- 3. Apply the classifier to the frame
if(!frame.empty())
{ detectAndDisplay(frame); }
else
{ printf(" --(!) No captured frame -- Break!"); break; }
int c = waitKey(10);
if((char)c == 'c') { break; }
}
}
return 0;
}
/** @function detectAndDisplay */
void detectAndDisplay(Mat frame)
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor(frame, frame_gray, CV_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
//-- Detect faces
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30));
for(int i = 0; i < faces.size(); i++)
{
Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
ellipse(frame, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
Mat faceROI = frame_gray(faces[i]);
std::vector<Rect> eyes;
//-- In each face, detect eyes
eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30));
for(int j = 0; j < eyes.size(); j++)
{
Point center(faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5);
int radius = cvRound((eyes[j].width + eyes[i].height)*0.25);
circle(frame, center, radius, Scalar(255, 0, 0), 4, 8, 0);
}
}
//-- Show what you got
imshow(window_name, frame);
}
:
나는 지금이 튜토리얼에서 제공 한 코드를 사용하여 Cascade Classifier tutorial을 시도하고있다 opencv_features2d230d.lib opencv_highgui230d.lib opencv_video230d opencv_imgproc230d.lib opencv_ml230d.lib opencv_legacy230d.lib lib 디렉토리
opencv_haartraining_engined.lib 내가 (솔루션 파일이있는) 내 비주얼 스튜디오 프로젝트
의 주요 디렉토리에있는 xml 파일을 가지고 있지만 나는 다음을 얻을 opencv_gpu230d.lib opencv_objdetect230.lib 오류 난 실행할 때/디버그 :
**
First-chance exception at 0x76b1b9bc in OpenCV_CascadeClassifier.exe: Microsoft C++ exception: cv::Exception at memory location 0x002ff1d0..
Unhandled exception at 0x77e315de in OpenCV_CascadeClassifier.exe: Microsoft C++ exception: cv::Exception at memory location 0x002ff1d0..
**
잘못된 코드 줄을 표시하지 않지만 메모리 위치를 가리키며 나를 이해할 수없는 디스 어셈블리 코드를 보여줍니다.
질문 :가 어떻게 비주얼 스튜디오에서 OpenCV의 코드와 통신하는 웹캠에서 비디오 스트림을받을 수 있나요? 문제가 무엇인지, 아니면 다른 것을 놓치고 있습니까?
EDIT : 오류는 실제로 캐스케이드를로드하는 첫 번째 줄에서 발생합니다. 나는 성공적이지 않은 다른 장소에 캐스케이드 xml을 배치하려고 시도했다.
도움을 주시면 감사하겠습니다.
안녕 dannyxyz22, 응답 주셔서 감사합니다. 내가 디버깅하고 코드가 첫 번째로드 XML 줄에 불평하는 것 같다 : 'if (! face_cascade.load (face_cascade_name)) {printf ("- (!) Error loading \ n"); -1을 반환합니다. }; ' –
xml 파일을 4 개의 다른 위치에 배치하려고했습니다. (두 개의 디버그 폴더 포함) –
xml 파일에 대한 C : \ Users ... 등의 전체 경로를 지정하려고했지만 비슷한 오류가 발생합니다. –