首页 > 编程语言 >基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理

基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理

时间:2022-12-25 10:35:03浏览次数:46  
标签:OPENCV armeabi libopencv opencv 图像处理 qml libs ANDROID v7a

《基于qml创建最简单的图像处理程序》系列课程及配套代码
基于qml创建最简单的图像处理程序(1)-基于qml创建界面
(0)​​课程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中去//

基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理_OpenCV

 

这里得到的就是一个canny的效果,也是通过调用OpenCV才得到的结果。那么这样一个框架就建立了。感谢阅读至此!希望有所帮助

 

标签:OPENCV,armeabi,libopencv,opencv,图像处理,qml,libs,ANDROID,v7a
From: https://blog.51cto.com/jsxyhelu2017/5967924

相关文章

  • 在win和android上同时进行OpenCV程序设计
    这里仅以widget为例,如果使用qtquick是一样的。具体以下几步:1、项目创建的时候,选择android和desktop两类(前提是安装的时候已经都选择了)这样,在程序设计的过程中,我......
  • #Python #OpenCV 使用Python为你的圣诞节增添更多乐趣
    ​ 目录1.前言2.目标与效果展示3.下载OpenCV图形识别库4.下载python支持的v2模块5.图片素材 6.代码  1.前言    ​编辑    MerryChri......
  • openmp在图像处理上面的运用
    //openmptest的测试程序//#include"stdafx.h"voidTest(intn){for(inti=0;i<10000;i++){intj=0;......
  • 为现有图像处理程序添加读写exif的功能
    为现有图像处理程序添加读取exif的功能exif是图片的重要参数,在使用过程中很关键的一点是exif的数据能够和图片一起存在。exif的相关功能在操作系统中就集成了,在csharp......
  • Python | Opencv的人脸检测和人类识别
    ✅作者简介:热爱科研的算法开发者,Python、Matlab项目可交流、沟通、学习。......
  • GOCVHelper图像处理算法库实例整编
       GOCVHelper主要包含图像处理、图像增强和基础文件处理三个部分。由于前两个部分较具有通用性,而且我在不同项目中都进行了反复使用,为了进一步说明类库内容,这里反过来......
  • 从条码识别中学习到的(来自课程《OpenCV计算机视觉产品实战2》)
    零、基本情况条码(一维码)已经广泛应用于我们日常生产实际,传统的条码识读方法是使用专用的激光扫描器来扫描条码,从而获取条码中的信息。这个过程人工介入程度较深、一般用......
  • 将GOCVHelper推向opencv——关于thinning函数的探索
      所以第一步就是opencvopencv_contrib联合起来。通过gitee来下载,速度非常快。https://gitee.com/mirrors/opencv_contrib/repository/archive/master.zip 配置......
  • 使用OpenCV实现摄像头测距
    摄像头测距就是计算照片中的目标物体到相机的距离。可以使用相似三角形(trianglesimilarity)方法实现,或者使用更复杂但更准确的相机模型的内参来实现这个功能使用相似三角......
  • OpenCV核心功能(核心模块)
    Mat-基本图像容器目标我们有多种方式从现实世界中获取数字图像:数码相机,扫描仪,计算机断层扫描和磁共振成像等等。在任何情况下,我们(人类)看到的都是图像。然而,当将其转换为......