博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理
阅读量:6038 次
发布时间:2019-06-20

本文共 5577 字,大约阅读时间需要 18 分钟。

《基于qml创建最简单的图像处理程序》系列课程及配套代码

基于qml创建最简单的图像处理程序(1)-基于qml创建界面
课程1附件
基于qml创建最简单的图像处理程序(2)-使用c++&qml进行图像处理
课程2附件
基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理
课程3附件

    在qml的系统中引入OpenCV,最复杂的地方在于环境的配置—一旦错误,系统即使能够编译成功,但是也会在启动的闪退;本文主要就是讲解在qml的系统(目标平台为Android,编码平台为windows)中如何正确配置OpenCV环境,并且将(2)中的图像处理结果进一步修改成为使用OpenCV来进行图像处理的结果;对于QT来说,实际上说的就是如何配置.pro文件。

 
一、环境配置,可以参考:
QT
+= quick
CONFIG
+= c
++
11
android {
message("Using android configuration")
ANDROID_OPENCV = D:/OpenCV-android-sdk/sdk/native
INCLUDEPATH += \
$$ANDROID_OPENCV/jni/include/opencv    \
$$ANDROID_OPENCV/jni/include/opencv2    \
$$ANDROID_OPENCV/jni/include            \
LIBS += \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_ml.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_objdetect.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_calib3d.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_video.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_features2d.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_highgui.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_flann.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_imgproc.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_core.a     \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibjpeg.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibpng.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibtiff.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibjasper.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libtbb.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libtegra_hal.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_java3.so
}
# The following
define makes your compiler emit warnings
if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES
+= QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile
if you use deprecated APIs.
# In order to
do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES
+= QT_DISABLE_DEPRECATED_BEFORE
=0x060000    # disables all the APIs deprecated before Qt
6.
0.
0
SOURCES
+= main.cpp \
    imageProcessor.cpp
RESOURCES
+= qml.qrc
# Additional import path used to resolve QML modules in Qt Creator
's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
    imageProcessor.h
DISTFILES += \
    android/AndroidManifest.xml \
    android/gradle/wrapper/gradle-wrapper.jar \
    android/gradlew \
    android/res/values/libs.xml \
    android/build.gradle \
    android/gradle/wrapper/gradle-wrapper.properties \
    android/gradlew.bat
contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_EXTRA_LIBS = \
        D:/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_java3.so
}
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
 
 
其中标红加粗的两个地方,是尤其需要注意进行修改的地方,分别对于
配置环境变量,当然你要根据你实际的地址来修改
ANDROID_OPENCV = D:/OpenCV-android-sdk/sdk/native
配置InClude地址
INCLUDEPATH += \
$$ANDROID_OPENCV/jni/include/opencv    \
$$ANDROID_OPENCV/jni/include/opencv2    \
$$ANDROID_OPENCV/jni/include            \
配置Libs地址
LIBS += \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_ml.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_objdetect.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_calib3d.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_video.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_features2d.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_highgui.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_flann.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_imgproc.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_core.a     \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibjpeg.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibpng.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibtiff.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibjasper.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libtbb.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libtegra_hal.a \
$$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_java3.so
尤其需要注意,这个顺序不能够错。
最后,还要将libopencv_java3.so当都付到.apk文件中
contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_EXTRA_LIBS = \
        D:/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_java3.so
 
二、引入头文件和命名空间,修改算法函数:
直接在头文件中引入头文件,并且表明命名空间
#
ifndef IMAGEPROCESSOR_H
#
define IMAGEPROCESSOR_H
#
include
<QObject
>
#
include
<QString
>
#
include
<opencv2
/core
/core.hpp
>
#
include
<opencv2
/highgui
/highgui.hpp
>
#
include
<opencv2
/imgproc
/imgproc.hpp
>
using
namespace cv;
using
namespace std;
 
按照前文所说,修改相关算法函数。因为本来函数都是以路径作为输入输出的,所以这里的操作比较简单。这里得到的算法名称可能和实际不一致,问题不大:
 
//具体的图像处理算法,注意图片处理的结果直接保存到了destFile中去//
static 
void _gray(QString sourceFile, QString destFile)
{
    Mat src 
= imread(sourceFile.toStdString());
    cv
:
:cvtColor(src,src,COLOR_BGR2GRAY);
    imwrite(destFile.toStdString(),src);
}
static 
void _binarize(QString sourceFile, QString destFile)
{
    Mat src 
= imread(sourceFile.toStdString());
    cv
:
:cvtColor(src,src,COLOR_BGR2GRAY);
    threshold(src,src,
100,
255,THRESH_OTSU);
    imwrite(destFile.toStdString(),src);
}
static 
void _emboss(QString sourceFile, QString destFile)
{
    Mat src 
= imread(sourceFile.toStdString());
    cv
:
:cvtColor(src,src,COLOR_BGR2GRAY);
    
int thresh 
= 
100;
    Canny( src, src, thresh, thresh
*
2
3 );
    imwrite(destFile.toStdString(),src);
}
//END 具体的图像处理算法,注意图片处理的结果直接保存到了destFile中去//
 
这里得到的就是一个canny的效果,也是通过调用OpenCV才得到的结果。那么这样一个框架就建立了。感谢阅读至此!希望有所帮助

 

目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com

转载地址:http://golhx.baihongyu.com/

你可能感兴趣的文章
css 禁止选中文本
查看>>
bzoj2165
查看>>
tomcat 配置首页
查看>>
算术运算表达式正则及分析
查看>>
Oracle 12c 多租户 手工创建 pdb 与 手工删除 pdb
查看>>
shell初涉
查看>>
[浪子学编程][MS Enterprise Library]ObjectBuilder之创建策略祥解(二)
查看>>
ASP.NET 中设置路径的三种方式
查看>>
EBS使用 Distributed AD在多个节点并行adpatch
查看>>
windows添加和删除服务
查看>>
关于云栖,有点无语的几个地方,管理能不能管?
查看>>
Windows线程的同步与互斥
查看>>
C#进阶系列——MEF实现设计上的“松耦合”(四):构造函数注入
查看>>
AngularJs ng-change事件/指令(转)
查看>>
linux系统下安装两个或多个tomcat
查看>>
ProtoBuffer 简单例子
查看>>
iOS多线程开发系列之(一)NSThread
查看>>
微信小程序初体验(上)- 腾讯ISUX社交用户体验设计成员出品
查看>>
SAP WM Physical Inventory Method ST & PZ
查看>>
一次快速的数据迁移感悟
查看>>