为什么我无法在 Open CV 中正确显示矩形?
Why can't I get a rectangle to be displayed properly in Open CV?
我正在使用 Open CV 测试已经很经典的人脸检测代码,我正在Rect
vector
中获取人脸。所以我想让获得的Rects
显示在图像上。
while (true) {
camera >> cameraFrame;
if (cameraFrame.empty ()) {
cerr << "Error: Could grab any frame!" << endl;
exit(2);
}
imshow("Hola mundo", cameraFrame);
cameraFrame = shrinkImage(turn2Gray(cameraFrame));
imshow("Hola mundo gris", cameraFrame);
equalizeHist(cameraFrame, equalizedImage);
imshow("Hola mundo surreal y perturbador", equalizedImage);
int flags = CASCADE_SCALE_IMAGE;
Size minFeatureSize(20,20);
float searchScaleFactor = 1.1f;
int minNeighbors = 4;
std::vector<Rect> faces;
faceDetector.detectMultiScale(equalizedImage, faces, searchScaleFactor, minNeighbors, flags, minFeatureSize);
cout << "Caras: " << faces.size() << endl;
for (i=0; i< (int) faces.size(); i++) {
rectangle( equalizedImage, faces[i], CV_RGB(0,255,0), 2, 8, 0 );
}
if (waitKey(20) == 27) {
}
}
我从来没有显示任何矩形。我的rectangle()
功能出了什么问题?
我做了建议的编辑,这就是现在的检测周期
:while (true) {
camera >> cameraFrame;
if (cameraFrame.empty ()) {
cerr << "Error: Could grab any frame!" << endl;
exit(2);
}
imshow("Hola mundo", cameraFrame);
greyFrame = shrinkImage(turn2Gray(cameraFrame));
imshow("Hola mundo gris", greyFrame);
equalizeHist(greyFrame, equalizedImage);
imshow("Hola mundo surreal y perturbador", equalizedImage);
faceDetector.detectMultiScale(equalizedImage, faces, searchScaleFactor, minNeighbors, flags, minFeatureSize);
cout << "Caras: " << faces.size() << endl;
for (i=0; i < faces.size(); i++) {
rectangle( cameraFrame, faces[i], CV_RGB(0,255,0), 2, 8, 0 );
}
imshow("Hola Diego", cameraFrame);
if (waitKey(20) == 27) {
break;
}
}
您正在尝试将RGB颜色绘制到灰度img上,还需要在矩形绘制后执行imshow(),然后waitKey()来更新窗口
尝试:
Mat greyFrame = shrinkImage(turn2Gray(cameraFrame)); // make a new grey mat, keep the original for drawing later
imshow("Hola mundo gris", greyFrame);
equalizeHist(greyFrame, equalizedImage);
imshow("Hola mundo surreal y perturbador", equalizedImage);
// ...
for (i=0; i< (int) faces.size(); i++) {
rectangle( cameraFrame, faces[i], CV_RGB(0,255,0), 2, 8, 0 );
}
imshow("Hola diego", cameraFrame);
if (waitKey(20) == 27) {
break;
}
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 程序崩溃并显示"std::out_of_range"错误
- 在 QML VideoOutput 中将 cv::mat 显示为 QVideoFrame
- C++/openCV - 为什么显示图像会产生 Linux 分割错误?(打开CV错误?
- 在qpixMap中显示一个CV :: MAT(键入CV_32F)
- 在图片框中显示cv::Mat格式的网络摄像头提要
- 如何显示窗口大小不同的输出图像?通过使用 cv::Mat
- OpenCV 2.4:在MFC中显示cv::Mat
- 将我的阵列移动到 Mat 并使用打开的 CV 显示图像
- 使用直接显示控制相机,并使用打开的CV捕获图像
- 为什么我无法在 Open CV 中正确显示矩形?
- cv::imshow 在不同的线程上不显示 cv::mat 颜色
- 如何在Windows窗体应用程序中显示cv::Mat
- 显示带有cv::viz模块的WCloud
- 调试断言失败!在人脸识别打开Cv的检测和显示功能中