我已经成功让OpenCV运行,方法如下:
我下载了Visual Studio 2015,并确保在安装过程中勾选了C++选项。这不是默认的,需要额外下载5GB。
我下载了QT 5.7版本,使用Visual Studio 2015 64位版本进行构建并安装。
我下载了Open CV 3.1.0并解压文件。
我将bin路径添加到环境变量中。例如:E:\OpenCv\build\x64\vc14\bin
我在QT中创建了一个项目,并将其添加到我的.pro文件中。
INCLUDEPATH += E:/OpenCv/build/include
debug {
LIBS += "E:/OpenCv/build/x64/vc14/lib/opencv_world310d.lib"
}
release {
LIBS += "E:/OpenCv/build/x64/vc14/lib/opencv_world310.lib"
}
我从示例中选取了一些最简代码,并成功编译了程序。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "opencv2/opencv.hpp"
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
Mat src, erosion_dst, dilation_dst;
int erosion_elem = 0;
int erosion_size = 0;
int dilation_elem = 0;
int dilation_size = 0;
int const max_elem = 2;
int const max_kernel_size = 21;
void Erosion( int, void* );
void Dilation( int, void* );
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
src = imread("C:\\Users\\IWC\\Desktop\\images.jpg");
if( src.empty() )
namedWindow( "Erosion Demo", WINDOW_AUTOSIZE );
namedWindow( "Dilation Demo", WINDOW_AUTOSIZE );
moveWindow( "Dilation Demo", src.cols, 0 );
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Erosion Demo",
&erosion_elem, max_elem,
Erosion );
createTrackbar( "Kernel size:\n 2n +1", "Erosion Demo",
&erosion_size, max_kernel_size,
Erosion );
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Dilation Demo",
&dilation_elem, max_elem,
Dilation );
createTrackbar( "Kernel size:\n 2n +1", "Dilation Demo",
&dilation_size, max_kernel_size,
Dilation );
Erosion( 0, 0 );
Dilation( 0, 0 );
waitKey(0);
}
MainWindow::~MainWindow()
{
delete ui;
}
void Erosion( int, void* )
{
int erosion_type = 0;
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
erode( src, erosion_dst, element );
imshow( "Erosion Demo", erosion_dst );
}
void Dilation( int, void* )
{
int dilation_type = 0;
if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement( dilation_type,
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
Point( dilation_size, dilation_size ) );
dilate( src, dilation_dst, element );
imshow( "Dilation Demo", dilation_dst );
}
INCLUDEPATH += C:/Users/micha/Documents/OpenCV/opencv/mingw-release/install/include/
- DumboLIBS += -L"C:\blah\blah"
。 - Dumbocore.hpp
、highgui.hpp
等等。 - Michael Lilleymake install
在某种程度上失败了,因此你只剩下骨架头文件,而不是与你的cmake配置对应的已生成头文件。 - zeFrenchy