c++ - 运行 OpenCV 3.1 迷你应用程序时出现蓝屏

标签 c++ opencv visual-studio-2015

我在计算机上运行基于 OpenCV 的项目时遇到了几个问题。我在 Visual Studio 2015 中使用 OpenCV 3.1.0,所以我使用的是 vc14 .lib 和 .dll。 OpenCV 的官方网页说 3.1.0 支持 Visual Studio 14 2015,所以我不认为这是问题所在。

我正在运行的代码是这样的:

enter code here
#include<stdio.h>
#include<math.h>
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv2\objdetect\objdetect.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<vector>

using namespace cv;
using namespace std;

int main()
{
       CascadeClassifier face_cascade, eye_cascade;
   if (!face_cascade.load("haarcascade_frontalface_alt.xml")) {
    printf("Error loading cascade file for face");
    return 1;
}
if (!eye_cascade.load("haarcascade_eye.xml")) {
    printf("Error loading cascade file for eye");
    return 1;
}
VideoCapture capture(0); //-1, 0, 1 device id
if (!capture.isOpened())
{
    printf("error to initialize camera");
    return 1;
}
Mat cap_img, gray_img;
vector<Rect> faces, eyes;
while (1)
{
    capture >> cap_img;
    waitKey(10);
    cvtColor(cap_img, gray_img, CV_BGR2GRAY);
    cv::equalizeHist(gray_img, gray_img);
    face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0, 0), cvSize(300, 300));
    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);
        Mat faceROI = gray_img(faces[i]);
        eye_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
        for (size_t j = 0; j< eyes.size(); j++)
        {
            //Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5, faces[i].y+eyes[j].y+eyes[j].height*0.5);
            Point center(faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5);
            int radius = cvRound((eyes[j].width + eyes[j].height)*0.25);
            circle(cap_img, center, radius, Scalar(255, 0, 0), 2, 8, 0);
        }
        rectangle(cap_img, pt1, pt2, cvScalar(0, 255, 0), 2, 8, 0);
    }
    imshow("Result", cap_img);
    waitKey(3);
    char c = waitKey(3);
    if (c == 27)
        break;
}
return 0;
}

这只是我在网上找到的一个例子。

我真的很想了解 OpenCV 但我无法运行任何东西:(

我正在使用 Windows 8.1

蓝屏就像下面的链接:

https://cdn.xtremerain.com/wp-content/uploads/2015/12/Kernel-Security-Check-Failure-HD-Screenshot.jpg

编辑:这很奇怪,虽然它是通过安装 windows 10 解决的,但事实并非如此。

我意识到它只会在我关闭应用程序时发生。

最佳答案

我认为您需要检查 roi 矩形是否适合图像区域。 detectMultiScale 可以给出部分位于图像之外的矩形。

关于c++ - 运行 OpenCV 3.1 迷你应用程序时出现蓝屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34750779/

相关文章:

python - cv2.VideoWriter 在 Jetson Nano 上运行不佳

c++ - 用于 Visual Studio 6 代码兼容性的 Visual Studio 2015

c++ - 检测运算符 << 序列的结尾

c++ - 为什么 boost::any 不保存字符串文字?

java - 如何使用OpenCV绘制具有正确旋转角度的boundingRect?

c++ - Qt+OpenCV : Symbols not found for architecture x86_64

c# - .NET native 在哪里?

c# - 添加 MasterDetailPage 后 Xamarin.forms 应用程序中的 System.InvalidCastException

c++ - 源代码可以在 GCC 中编译,但不能在 Visual Studio 中编译

c++ - std::condition_variable – 通知一次但等待线程被唤醒两次