OpenCV错误:断言失败< scn == 3 :: scn == 4>在未知函数中, [英] OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function,

查看:213
本文介绍了OpenCV错误:断言失败< scn == 3 :: scn == 4>在未知函数中,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从其他解决方案中读了很多,但我仍然困惑我应该怎么做我的...

I read alot from other solution but i still confused what should i do with 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 the cascade classifier object used for the face detection
    CascadeClassifier face_cascade;
    //use the haarcascade_frontalface_alt.xml library
    face_cascade.load("haarcascade_frontalface_alt.xml");

    //setup video capture device and link it to the first capture device
    VideoCapture captureDevice;
    captureDevice.open(0);

    //setup image files used in the capture process
    Mat captureFrame;
    Mat grayscaleFrame;

    //create a window to present the results
    namedWindow("outputCapture", 1);

    //create a loop to capture and find faces
    while (true)
    {
        //capture a new image frame
        captureDevice >> captureFrame;

        //convert captured image to gray scale and equalize
        cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
        equalizeHist(grayscaleFrame, grayscaleFrame);

        //create a vector array to store the face found
        std::vector<Rect> faces;

        //find faces and store them in the vector array
        face_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, Size(30, 30));

        //draw a rectangle for all found faces in the vector array on the original image
        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(captureFrame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
        }

        //print the output
        imshow("outputCapture", captureFrame);

        //pause for 33ms
        waitKey(33);
    }
    return 0;
}

这是错误


OpenCV错误:未知函数中的断言失败

OpenCV Error: Assertion failed in unknown function

看起来错误发生在captureDevice> > captureFrame;请指导我,这是从相机拍摄的图像。

It seems the error happened after "captureDevice >> captureFrame;" Please guide me, this is taking image from camera.

推荐答案

看起来像 VideoCapture 无法从您的相机抓取帧。添加此代码以检查框架抓取的结果:

It seems like VideoCapture can't grab frame from your camera. Add this code to check result of frame grabbing:

//create a loop to capture and find faces
while (true)
{
    //capture a new image frame
    captureDevice >> captureFrame;
    if (captureFrame.empty())
    {
        cout << "Failed to grab frame" << endl;
        break;
    }
    ...

如果是 VideoCapture 检查您是否为相机安装了驱动程序。

If it is a problem of VideoCapture check that you installed drivers for your camera.

这篇关于OpenCV错误:断言失败&lt; scn == 3 :: scn == 4&gt;在未知函数中,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆