OpenCV错误:断言失败<scn 3 =“”:: scn =“=”4 =“”>未知函数,</scn>

时间:2013-12-03 10:57:29

标签: c++ opencv visual-studio-2013

我从其他解决方案中读到很多但我仍然困惑我应该怎样对待我...

#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错误:未知函数中的断言失败

似乎错误发生在“captureDevice&gt;&gt; captureFrame;”之后请指导我,这是从相机拍摄的图像。

2 个答案:

答案 0 :(得分:1)

似乎VideoCapture无法从相机中抓取相框。添加此代码以检查帧抓取的结果:

//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检查您是否安装了相机的驱动程序。

答案 1 :(得分:0)

好的,我想我知道发生了什么。我尝试运行该程序,它运行得很好。

您可能没有链接所需的DLL。确保(如果您使用的是Windows)您的 opencv / bin 包含在您的环境变量中。这是我的 CMakeLists.txt 文件,让您更轻松,

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(SO_example)

FIND_PACKAGE(OpenCV REQUIRED)

SET (SOURCES
    #VTKtoPCL.h
    main.cpp
    )

add_executable(so_example ${SOURCES})
target_link_libraries(so_example ${OpenCV_LIBS})