zynq-7000学习笔记(十五)——在QT上调用opencv加载图片并显示

PC平台:WINDOWS 10 64位 + 虚拟机Ubuntu 14.04

Xilinx设计开发套件:Xilinx_vivado_sdk_2015.4

开发板:Zed Board

USB摄像头:罗技 C270(720P)

Linux源码:2016_R1

Linaro文件系统:linaro-vivid-developer-20150618-705.tar.gz

QT库:qt-everywhere-opensource-src-4.7.3.tar.gz

openCV: opencv-3.1.0


一、修改qmake.conf,把opencv库的路径添加进去

#
# qmake configuration for building with arm-none-linux-gnueabi-g++
#

include(../../common/g++.conf)
include(../../common/linux.conf)
include(../../common/qws.conf)

###############################################################################################
QMAKE_LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video \
		-lopencv_features2d -lopencv_calib3d -lopencv_objdetect \
		-lopencv_flann -lopencv_imgcodecs

INCLUDEPATH += /home/luotong/working/opencvlib/include
LIBS += /home/luotong/working/opencvlib/lib/libopencv_core.so \
	/home/luotong/working/opencvlib/lib/libopencv_imgproc.so \
	/home/luotong/working/opencvlib/lib/libopencv_highgui.so \
	/home/luotong/working/opencvlib/lib/libopencv_ml.so \
	/home/luotong/working/opencvlib/lib/libopencv_video.so \
	/home/luotong/working/opencvlib/lib/libopencv_features2d.so \
	/home/luotong/working/opencvlib/lib/libopencv_calib3d.so \
	/home/luotong/working/opencvlib/lib/libopencv_objdetect.so \
	/home/luotong/working/opencvlib/lib/libopencv_flann.so \
	/home/luotong/working/opencvlib/lib/libopencv_imgcodecs.so
###############################################################################################	

# modifications to g++.conf
QMAKE_CC                = ${CROSS_COMPILE}gcc
QMAKE_CXX               = ${CROSS_COMPILE}g++
QMAKE_LINK              = ${CROSS_COMPILE}g++
QMAKE_LINK_SHLIB        = ${CROSS_COMPILE}g++

# modifications to linux.conf
QMAKE_AR                = ${CROSS_COMPILE}ar cqs
QMAKE_OBJCOPY           = ${CROSS_COMPILE}objcopy
QMAKE_STRIP             = ${CROSS_COMPILE}strip

QMAKE_CFLAGS="${CROSS_COMPILE_CFLAGS} -I$(ZYNQ_QT_INSTALL)/include -DZYNQ"
QMAKE_CXXFLAGS="${CROSS_COMPILE_CPPFLAGS} -I$(ZYNQ_QT_INSTALL)/include -DZYNQ"
QMAKE_LFLAGS="-L$(ZYNQ_QT_INSTALL)/lib -L/home/luotong/working/opencvlib/lib"


load(qt_config)

二、用QT creator创建一个项目,在界面上添加一个button和textlabel

zynq-7000学习笔记(十五)——在QT上调用opencv加载图片并显示_第1张图片

mainwindow.cpp

void MainWindow::on_pushButton_clicked()
{
    image = cv::imread("/home/luotong/working/test.jpg");

    Mat rgb;
    QImage img;
    if(image.channels()==3)
    {
        //cvt Mat BGR 2 QImage RGB
        cvtColor(image,rgb,CV_BGR2RGB);
        img =QImage((const unsigned char*)(rgb.data),
                    rgb.cols,rgb.rows,
                    rgb.cols*rgb.channels(),
                    QImage::Format_RGB888);
    }
    else
    {
        img =QImage((const unsigned char*)(image.data),
                    image.cols,image.rows,
                    image.cols*image.channels(),
                    QImage::Format_RGB888);
    }

    ui->label->setPixmap(QPixmap::fromImage(img));
    ui->label->resize(ui->label->pixmap()->size());
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include 

#include 
#include 
#include 

using namespace cv;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;

    cv::Mat image;
};

#endif // MAINWINDOW_H

三、编译,运行

# /home/luotong/working/qt_install/bin/qmake -project
# qmake -spec /home/luotong/working/qt_install/mkspecs/qws/linux-arm-gnueabi-g++
# make
zynq-7000学习笔记(十五)——在QT上调用opencv加载图片并显示_第2张图片

点击button

zynq-7000学习笔记(十五)——在QT上调用opencv加载图片并显示_第3张图片

你可能感兴趣的:(Zynq-7000)