Qt-Opencv移植

895 words

准备

下载cmake

下载Download | CMake软件,并安装:

image-20221117170329077

下载Opencv

下载Opencv源码:

image-20221117170514707

编译移植

opencv源码解压

1
2
3
4
5
6
#解压
unzip opencv-4.6.0
#移动
cd opencv-4.6.0
#新建编译目录与输出目录
mkdir build install

cmake配置

设置路径

第一个选择源码路径,第二个选择编译目录

image-20221117170914152

设置交叉编译链

点击Configure之后,开始设置编译环境

image-20221117171813013

image-20221117171836307

修改配置

  1. 设置生成的模块

image-20221117171215688

image-20221117171304773

  1. 设置编译的模块

    image-20221117171416669

image-20221117171443902

image-20221117171455816

  1. 设置QT环境

    image-20221117171518437

  2. 设置输出目录

    image-20221117171556346

生成

点击Generate之后,进入build目录下,执行:

1
2
make -j12
make install

QT中使用Opencv

  1. 修改pro文件
1
2
INCLUDEPATH += ./lib/include/opencv4
LIBS += -L$$PWD/lib/lib -lopencv_world
  1. 新建工程,并在MainWindow中修改:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);

Mat img=imread("./4.jpg",1);
waitKey(0);
// Convert to graycsale
Mat img_gray;
cvtColor(img, img_gray, COLOR_BGR2GRAY);
// Blur the image for better edge detection
Mat img_blur;
GaussianBlur(img_gray, img_blur, Size(3,3), 0);
// Canny edge detection
Mat edges;
Canny(img_blur, edges, 75, 200, 3, false);
// Display canny edge detected image
imshow("Canny edge detection", edges);
waitKey(0);
}
Comments