首页 > 编程语言 >在win和android上同时进行OpenCV程序设计

在win和android上同时进行OpenCV程序设计

时间:2022-12-25 10:34:44浏览次数:44  
标签:OpenCV win armeabi v7a OPENCV libs android libopencv ANDROID

这里仅以widget为例,如果使用qtquick是一样的。具体以下几步:


1、项目创建的时候,选择android和desktop两类(前提是安装的时候已经都选择了)



在win和android上同时进行OpenCV程序设计_android


这样,在程序设计的过程中,我们就可以通过切换来进行选择



在win和android上同时进行OpenCV程序设计_android_02


如果对于已经配置好kti(构建套件)的项目,可以先删除目录下的.pro.user文件,而后重新打开项目,则自动跳出构建套件配置界面



在win和android上同时进行OpenCV程序设计_Android_03


2、配置文件:


对配置文件的修改是主要知识点所在,首先在不同平台下,要填写不同的前缀。对于pc平台是


​ win32 {……} ​



对于Android平台是


​ android {……} ​



大小写不可写错,此外就是OpenCV基础环境的配置。对于pc平台需要做的是配置系统路径、设置include和lib路径;对于Android平台需要做的是 设置include和lib路径,并且将 libopencv_java3.so 拷贝到最后的.apk中去。参考的配置文件如下,其中重要的部分已经加粗。


​​QT         +=         quick        
QT += multimedia
CONFIG += c ++
11


win32 {
message("当前使用PC配置")
WIN32_OPENCV = D:/JsxyheluOpenCV/New-QT-dll/install
INCLUDEPATH += \
$$WIN32_OPENCV/include/opencv \
$$WIN32_OPENCV/include/opencv2 \
$$WIN32_OPENCV/include
LIBS += \
$$WIN32_OPENCV/x86/mingw/lib/
libopencv_core320.dll.a
\​​

​​ $$WIN32_OPENCV/x86/mingw/lib/libopencv_highgui320.dll.a\
$$WIN32_OPENCV/x86/mingw/lib/libopencv_imgproc320.dll.a\
$$WIN32_OPENCV/x86/mingw/lib/libopencv_imgcodecs320.dll.a\
$$WIN32_OPENCV/x86/mingw/lib/libopencv_highgui320.dll.a\
$$WIN32_OPENCV/x86/mingw/lib/libopencv_videoio320.dll.a
}

android {
message("当前使用Android配置")
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 \
todocpp.cpp \
calibration.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 += \
todocpp.h \
calibration.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 ​​




并设置正确的环境变量(如何在Windows和Android平台下编译OpenCV请参考博客中其它博文)


在win和android上同时进行OpenCV程序设计_android_04


3、编写界面和代码


为说明方便,在简单的widget上面显示一个自己生成的圆。其中圆的生成和最终显示都调用OpenCV代码。那么如果这个是成功的,则证明OpenCV环境配置正确。


​​include        "mainwindow.h"       
# include "ui_mainwindow.h"
using namespace cv;
Mat tmp;
MainWindow : :MainWindow(QWidget *parent)
:

QMainWindow(parent),
ui( new Ui : :MainWindow)
{
ui - >setupUi( this);
}

MainWindow : : ~MainWindow()

{
delete ui;
}

void MainWindow : :on_pushButton_pressed()
{
Mat src(Size( 640, 480),CV_8UC1,cv :
:Scalar(
255));

circle(src,Point( 100, 100), 100,Scalar(
0),
-
1);

// 格式转换
QPixmap qpixmap = Mat2QImage(src);
// 将图片显示到label上
ui - >label -
>setPixmap(qpixmap);

}

//格式转换
QPixmap Mat2QImage(Mat src)
{
QImage img;
//根据QT的显示方法进行转换
if(src.channels() == 3)
{
cvtColor( src, tmp, CV_BGR2RGB );
img = QImage( ( const unsigned char
*)(tmp.data), tmp.cols, tmp.rows, QImage
:
:Format_RGB888 );

}
else

{
img = QImage( ( const unsigned char
*)(src.data), src.cols, src.rows, QImage
:
:Format_Grayscale8 );

}
QPixmap qimg = QPixmap : :fromImage(img) ;

return qimg;
}

​​



4、结果和小结



在win和android上同时进行OpenCV程序设计_android_05



在win和android上同时进行OpenCV程序设计_QT_06


在两类平台上进行配置,其原始原因是为了能够加快项目初期,Android+OpenCV处理程序的调试速度,主要的难点在于.pro文件的配置。


在项目实践过程中的如何提高实现速度?我们在后面的文章中继续分享。


感谢阅读至此,希望有所帮助!


标签:OpenCV,win,armeabi,v7a,OPENCV,libs,android,libopencv,ANDROID
From: https://blog.51cto.com/jsxyhelu2017/5967927

相关文章

  • 纷繁复杂的操作系统到底是什么关系从APPLE到Android到Linux等
    各个系统之间的关系最近接触了很多很多系统,多种多样,纷繁复杂,感觉有点乱想整理以下思路,结果一下笔内容还挺多,不全,就是现在能见到的,梳理一下,站在一个外行的角度写写省的乱,不......
  • win10安装
    1.准备PE和win10iso安装文件2.启动时按F12(或其他)使开机从UBS启动2.1戴尔灵越15笔记本装win10系统BIOS设置步骤(1)开机一直按F2进入BIOS,按F2进入BIOS界面,切换......
  • golang在win10安装、环境配置 和 goland(IDE开发golang配置)
    前言本人在使用goland软件开发go时,对于goland软件配置网上资料少,为了方便自己遗忘、也为了希望和我一样的小白能够更好的使用,所以就写下这篇博客,废话不多说开考。一、查......
  • Windows 编程式修改电脑壁纸
    废话(可以跳过)(平时修改电脑的壁纸的时候,我们都是需要手动点击来进行修改的,想必可能想到,其实设置这个程序,也是通过win提供的API来实现的,我们点击就会调用这个API)......
  • Acwing 第 83 场周赛 ABC
    https://www.acwing.com/activity/content/competition/problem_list/2714/4785.奇偶题目大意:给定一个字符串,问我们去重后单词数是奇是偶?输入样例1:wjmzbmr输出样......
  • 使用Docker编译android10源码
    环境准备安装WSL2修改默认路径安装DockerDesktop,迁移docker到其他盘符,docker配置镜像加速。https://blog.csdn.net/qq_43430759/article/details/127604483dockerpu......
  • #Python #OpenCV 使用Python为你的圣诞节增添更多乐趣
    ​ 目录1.前言2.目标与效果展示3.下载OpenCV图形识别库4.下载python支持的v2模块5.图片素材 6.代码  1.前言    ​编辑    MerryChri......
  • 记录一次win10修复|System Failed to Initialize In Windows|CBSLog
    起因:系统初始化失败,尝试使用如下命令行修复sfc/SCANNOW生成CBS日志,可以搜索关键字“Couldnot”定位到问题行关闭联想锁屏后解决cmd问题最终退出杀软后成功安装参......
  • Windows平台RTMP、RTSP播放器录像模块精细化控制
    技术背景上篇文章,我们介绍了Unity平台RTMP、RTSP播放器录像功能,这里,我们详细的介绍下,做个RTSP或RTMP拉流端录像模块有哪些需要考虑的技术点?在我们常规的考量,RTMP或RTSP流录......
  • Android studio学习第一期
    下载工具 Androidstudio参考博客https://blog.csdn.net/weixin_45406151/article/details/114531103汉化完成并创建了虚拟手机 安卓app项目目录结构模块编译规......