流网络摄像头的速度慢,无法"detectMultiScale"
Slow speed in stream webcam to do "detectMultiScale"
我是使用OpenCV的新手。我正在做一个示例人脸检测器应用程序控制台。我正在使用haarcascade从网络摄像头检测人脸。
我做了下一个代码:
int main(int, char**)
{
CascadeClassifier face_cascade;
face_cascade.load("haarcascade_frontalface_alt2.xml");
vector<Rect> faces;
Mat frame_gray;
const double scale_factor = 1.1;
const int min_neighbours = 2;
const int flags = 0 | CV_HAAR_SCALE_IMAGE;
VideoCapture cap(0); // open the default camera
if (!cap.isOpened()) // check if we succeeded
return -1;
Mat frame;
for (;;)
{
cvtColor(frame, frame_gray, CV_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
face_cascade.detectMultiScale(frame_gray, faces, scale_factor, min_neighbours, flags, Size(30, 30));
if (faces.size() == 0)
{
cout << "No face detected" << endl;
}
else
{
for (unsigned int i = 0; i<faces.size(); i++)
{
Point pt1(faces[i].x, faces[i].y);
Point pt2(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 1.5, 8, 0);
}
}
if (waitKey(30) >= 0) break;
}
return 0;
}
我测试了网络摄像头的速度很慢。我想这可能是通过图像的分辨率(640x480(。我想知道是否有任何方法可以保持分辨率并提高每帧之间的速度以进行检测。
谢谢!
您可以:
- 将最小脸尺寸从 Size(30, 30( 增加到 Size(50, 50((它可以提高 2-3 倍的性能(。
- 将scale_factor的值从 1.1 更改为 1.2;(它提高了 2 倍的性能(。
- 使用LBP检测器代替Haar检测器(速度快2-3倍(。
- 检查编译器选项(可能使用调试模式(。
相关文章:
- 无法在 CLion 中构建 C++ 项目
- C++,系统无法执行指定的程序
- 二叉排序树无法编译
- 嵌套在类中时无法设置成员数据
- 无法访问嵌套类.类的使用无效
- 提升 ASIO 无法识别计时器对象
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 无法找到/读取配置文件.conf-FileIOException
- 无法将结构注册为增强几何体3D点
- 无法通过空白将文本文件行分隔为矢量
- C++,我收到一个无法理解的编译器错误
- 我的简单if-else语句是如何无法访问的代码
- 无法创建抽象类的实例
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 模板类无法识别友元运算符
- QTreeView幻灯片多选后无法使用单击选择
- 无法链接 CMake 中的本地库
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- C++:无法访问声明的受保护成员