c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -
i read alot other solution still confused should mine...
#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; int main(int argc, const char** argv) { //create cascade classifier object used face detection cascadeclassifier face_cascade; //use haarcascade_frontalface_alt.xml library face_cascade.load("haarcascade_frontalface_alt.xml"); //setup video capture device , link first capture device videocapture capturedevice; capturedevice.open(0); //setup image files used in capture process mat captureframe; mat grayscaleframe; //create window present results namedwindow("outputcapture", 1); //create loop capture , find faces while (true) { //capture new image frame capturedevice >> captureframe; //convert captured image gray scale , equalize cvtcolor(captureframe, grayscaleframe, cv_bgr2gray); equalizehist(grayscaleframe, grayscaleframe); //create vector array store face found std::vector<rect> faces; //find faces , store them in vector array face_cascade.detectmultiscale(grayscaleframe, faces, 1.1, 3, cv_haar_find_biggest_object | cv_haar_scale_image, size(30, 30)); //draw rectangle found faces in vector array on original image (int = 0; < 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(captureframe, pt1, pt2, cvscalar(0, 255, 0, 0), 1, 8, 0); } //print output imshow("outputcapture", captureframe); //pause 33ms waitkey(33); } return 0; }
this error
opencv error: assertion failed in unknown function
it seems error happened after "capturedevice >> captureframe;" please guide me, taking image camera.
it seems videocapture
can't grab frame camera. add code check result of frame grabbing:
//create loop capture , find faces while (true) { //capture new image frame capturedevice >> captureframe; if (captureframe.empty()) { cout << "failed grab frame" << endl; break; } ...
if problem of videocapture
check installed drivers camera.
Comments
Post a Comment