c++ - 带有fedora 23的Opencv Qt:程序意外完成

标签 c++ qt opencv

The program has unexpectedly finished. Starting /home/tamercan/build-myfirst2-Desktop_Qt_5_7_0_GCC_64bit-Debug/myfirst2... /home/tamercan/build-myfirst2-Desktop_Qt_5_7_0_GCC_64bit-Debug/myfirst2 crashed.



这是我的main.cpp
#include <opencv2/core/base.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/core/types.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect/objdetect_c.h>
#include <opencv2/objdetect.hpp>
#include <opencv2/videoio.hpp>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0



    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
    // Load Face cascade (.xml file)
        CascadeClassifier face_cascade;
        face_cascade.load( "xml/haarcascade_frontalface_alt.xml" );

    while (1)
    {
        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

         if (!bSuccess) //if not success, break loop
        {
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }
         // Detect faces
             std::vector<Rect> faces;
             face_cascade.detectMultiScale( frame, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

             // Draw circles on the detected faces
             for( int i = 0; i < faces.size(); i++ )
             {
                 Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
                 ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );


                     imshow( "Detected Face", frame );
             }



                 //rectangle( frame, center, Size( faces[i].width*2, faces[i].height*2), Scalar( 255, 0, 255 ) );




        if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
       {
            cout << "esc key is pressed by user" << endl;
            break;
       }
    }
    return 0;

}

我的.pro文件是
QT += core
QT -= gui

CONFIG += c++11

TARGET = myfirst2
CONFIG += console
CONFIG -= app_bundle

QMAKE_DEFAULT_INCDIRS="" && make

TEMPLATE = app

SOURCES += main.cpp

INCLUDEPATH += /usr/include/
LIBS += -L/usr/lib -lopencv_core -lopencv_highgui -lopencv_video -lopencv_videoio -lopencv_imgproc -lopencv_ml -lopencv_features2d -lopencv_calib3d -lopencv_objdetect

最佳答案

我通过将opencv的bin和lib文件的路径添加到PATH来解决了这个问题:

关于c++ - 带有fedora 23的Opencv Qt:程序意外完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40484505/

相关文章:

c++ - 正确使用移动语义

c++ - 离开默认构造函数后 unique_ptr 变为空

c++ - QMainWindow 打开后从静态函数运行 QDialog 对象

c++ - 制作一个 Mat 类型对象的数组。输出窗口显示相同的帧

java - 将一组垫传递给 native 代码

c++ - Qt 像素图操作

c++ - 模板类的默认值,C++

c++ - 为什么 osgEarth 不使用 Qt 构建?

linux - Qt 小部件大小错误 + 小部件更新问题

python - OpenCV/图像处理技术,用于查找图像中亮点的中心