gpt4 book ai didi

c++ - OpenCV 错误:断言失败 在未知函数中,

转载 作者:行者123 更新时间:2023-11-28 07:15:11 25 4
gpt4 key购买 nike

我从其他解决方案中阅读了很多,但我仍然困惑我应该如何处理我的...

#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 Error: Assertion failed in unknown function

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

最佳答案

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

关于c++ - OpenCV 错误:断言失败 <scn == 3::scn == 4> 在未知函数中,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com