日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

基于Android studio3.6的JNI教程之opencv實例詳解

瀏覽:133日期:2022-09-26 16:01:13

基本環境:

Android studio3.6

NDK:r14b(盡量使用該版本)

Opencv3.4.1 android sdk

基于Android studio3.6的JNI教程之opencv實例詳解

(1)新建工程OpenCVDemo,選擇,一定要選擇Native c++類型,最后要選c++14支持。

(2)File->Project Structure->SDK Location,設置這3個路徑,NDK選擇r14b。

(3)任意找一張圖片,復制到res/drawable。

(4)修改布局文件res/layout/ activity_main.xml

<?xml version='1.0' encoding='utf-8'?><RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='match_parent' android:layout_height='match_parent'> <ImageView android: android:layout_width='match_parent' android:layout_height='match_parent' /> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_alignParentBottom='true' android:orientation='horizontal'> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_weight='1' android:text='show' /> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_weight='1' android:text='process' /> </LinearLayout></RelativeLayout>

(5)修改java文件,app/src/main/java/ com.example.opencvdemo/ MainActivity

主要修改包括修改

繼承OnClickListener類,

修改onCreate方法

增加c++的接口函數,getEdge

實現點擊按鈕的方法,

整體代碼如下,

(6)Termi

package com.example.opencvdemo;import androidx.appcompat.app.AppCompatActivity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener{ // Used to load the ’native-lib’ library on application startup. static { System.loadLibrary('native-lib'); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = findViewById(R.id.imageView); findViewById(R.id.show).setOnClickListener(this); findViewById(R.id.process).setOnClickListener(this); } /** * A native method that is implemented by the ’native-lib’ native library, * which is packaged with this application. */ //獲得Canny邊緣 public native void getEdge(Object bitmap); private ImageView imageView; @Override public void onClick(View v) { if (v.getId() == R.id.show) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test); imageView.setImageBitmap(bitmap); } else { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test); getEdge(bitmap); imageView.setImageBitmap(bitmap); } }}

nal下進入appsrcmainjava這一層目錄,執行,

javah com.example.opencvdemo.MainActivity

將生成的com_example_opencvdemo_MainActivity.h,剪切到app/src/main/cpp目錄下。

(7)修改app/src/main/cpp下面的native-lib.cpp,主要通過c++實現getEdge方法,主要代碼如下,

#include <jni.h>#include <string>#include 'com_example_opencvdemo_MainActivity.h'#include <android/bitmap.h>#include <opencv2/opencv.hpp>using namespace cv;extern 'C'JNIEXPORT void JNICALLJava_com_example_opencvdemo_MainActivity_getEdge(JNIEnv *env, jobject obj, jobject bitmap){ // TODO: implement getEdge() AndroidBitmapInfo info; void *pixels; CV_Assert(AndroidBitmap_getInfo(env, bitmap, &info) >= 0); CV_Assert(info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 || info.format == ANDROID_BITMAP_FORMAT_RGB_565); CV_Assert(AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0); CV_Assert(pixels); if (info.format == ANDROID_BITMAP_FORMAT_RGBA_8888) { Mat temp(info.height, info.width, CV_8UC4, pixels); Mat gray; cvtColor(temp, gray, COLOR_RGBA2GRAY); Canny(gray, gray, 125, 225); cvtColor(gray, temp, COLOR_GRAY2RGBA); } else { Mat temp(info.height, info.width, CV_8UC2, pixels); Mat gray; cvtColor(temp, gray, COLOR_RGB2GRAY); Canny(gray, gray, 125, 225); cvtColor(gray, temp, COLOR_GRAY2RGB); } AndroidBitmap_unlockPixels(env, bitmap);}

(8)修改CMakeLists.txt

包括增加opencv包含路徑,增加opencv鏈接,增加目標庫的鏈接(OpenCV_LIBS和jnigraphics)

全部代碼如下,

# For more information about using CMake with Android Studio, read the# documentation: https://d.android.com/studio/projects/add-native-code.html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.4.1)# Creates and names a library, sets it as either STATIC# or SHARED, and provides the relative paths to its source code.# You can define multiple libraries, and CMake builds them for you.# Gradle automatically packages shared libraries with your APK.#設置OpenCV-android-sdk路徑set( OpenCV_DIR E:/Android/OpenCV-android-sdk/sdk/native/jni )find_package(OpenCV REQUIRED )if(OpenCV_FOUND) include_directories(${OpenCV_INCLUDE_DIRS}) message(STATUS 'OpenCV library status:') message(STATUS ' version: ${OpenCV_VERSION}') message(STATUS ' libraries: ${OpenCV_LIBS}') message(STATUS ' include path: ${OpenCV_INCLUDE_DIRS}')else(OpenCV_FOUND) message(FATAL_ERROR 'OpenCV library not found')endif(OpenCV_FOUND) set(CMAKE_SHARED_LINKER_FLAGS '${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a') add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). native-lib.cpp ) # Searches for a specified prebuilt library and stores the path as a# variable. Because CMake includes system libraries in the search path by# default, you only need to specify the name of the public NDK library# you want to add. CMake verifies that the library exists before# completing its build. find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) # Specifies libraries CMake should link to your target library. You# can link multiple libraries, such as libraries you define in this# build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. native-lib ${OpenCV_LIBS} jnigraphics # Links the target library to the log library # included in the NDK. ${log-lib} )

(9)修改app/build.gradle

主要增加cmake的cppFlags,arguments

全部代碼如下,

apply plugin: ’com.android.application’android { compileSdkVersion 29 buildToolsVersion '29.0.3' defaultConfig { applicationId 'com.example.opencvdemo' minSdkVersion 16 targetSdkVersion 29 versionCode 1 versionName '1.0' testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' externalNativeBuild { cmake { cppFlags '-std=c++14 -frtti -fexceptions' arguments ’-DANDROID_STL=gnustl_shared’ //支持C++異常處理標準模板快,ndk16+需要注釋 //abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64' } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(’proguard-android-optimize.txt’), ’proguard-rules.pro’ } } externalNativeBuild { cmake { path 'src/main/cpp/CMakeLists.txt' version '3.10.2' } }}dependencies { implementation fileTree(dir: ’libs’, include: [’*.jar’]) implementation ’androidx.appcompat:appcompat:1.1.0’ implementation ’androidx.constraintlayout:constraintlayout:1.1.3’ testImplementation ’junit:junit:4.12’ androidTestImplementation ’androidx.test.ext:junit:1.1.1’ androidTestImplementation ’androidx.test.espresso:espresso-core:3.2.0’}

(10)整體目錄結構如下,

基于Android studio3.6的JNI教程之opencv實例詳解

運行程序,

基于Android studio3.6的JNI教程之opencv實例詳解

代碼鏈接:

References:

https://www.jianshu.com/p/6e16c0429044

https://www.bilibili.com/video/av55834524/

總結

到此這篇關于基于Android studio3.6的JNI教程之opencv實例詳解的文章就介紹到這了,更多相關android studio JNI教程opencv內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Android
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产精品一区二区精品视频观看 | 国产一区2区在线观看| av高清不卡| 国产激情久久| 国产精品亚洲成在人线| 国产精品成人自拍| 久久99久久久精品欧美| 欧美激情视频一区二区三区免费 | 日韩一区二区免费看| 91九色精品国产一区二区| 久久青草久久| 亚洲经典在线| 综合干狼人综合首页| 日本午夜精品| 国内精品亚洲| 婷婷综合六月| 日韩国产专区| 91精品观看| 国产一区丝袜| 国产超碰精品| 99久久激情| 国产美女高潮在线| 四虎成人av| 亚洲伦乱视频| 色婷婷精品视频| 激情综合自拍| 日韩亚洲国产欧美| 午夜在线一区| 日本亚洲最大的色成网站www | 国产精品777777在线播放| 日韩精品亚洲一区二区三区免费| 九九在线精品| 日本精品不卡| 99香蕉国产精品偷在线观看| 亚洲免费黄色| 涩涩涩久久久成人精品| 日本va欧美va欧美va精品| 国产精品调教| 久久精品91| 最新国产精品| 国产91欧美| 99国产精品久久久久久久成人热| 亚洲精品大全| 国产欧美激情| 电影亚洲精品噜噜在线观看| 9色精品在线| 国产精品观看| 九一成人免费视频| 国产调教精品| 久久伦理在线| 国产美女撒尿一区二区| 尤物在线精品| 成人午夜在线| 91精品啪在线观看国产爱臀| 日本不良网站在线观看| 蜜臀久久久久久久| 欧美少妇精品| 久久精品99国产国产精| 人人精品亚洲| 欧美亚洲自偷自偷| 欧美va天堂在线| 精品三区视频| 日本a级不卡| 亚洲欧美日韩一区在线观看| 久久中文字幕一区二区| 亚洲精选久久| 日韩一区二区久久| 欧美日韩免费看片| 成人午夜网址| 国产精品99久久免费| 18国产精品| 视频一区二区中文字幕| 久久久精品久久久久久96 | 久久亚洲资源中文字| 国产精品日韩欧美一区| 成人免费电影网址| 国产精品99一区二区三| 日韩高清电影一区| 日韩欧美久久| 亚洲男人在线| 亚洲字幕久久| 亚洲精品黄色| 亚洲精品激情| 中文字幕日韩欧美精品高清在线| 久久中文视频| 亚洲性色av| 欧美一区二区三区高清视频| 99国产精品免费视频观看| 蜜桃av.网站在线观看| 快播电影网址老女人久久| 视频在线不卡免费观看| 国产+成+人+亚洲欧洲在线| 美女视频黄 久久| 日韩国产激情| 99国产精品| 亚洲欧洲免费| 欧美日韩一区二区国产 | 久久久久久婷| 国产盗摄——sm在线视频| 日韩欧美国产精品综合嫩v| 久久电影tv| 色婷婷综合网| 久久av一区| 国产精品一在线观看| 高清不卡一区| 一本一道久久a久久精品蜜桃| 久久一二三区| 久久99久久人婷婷精品综合| 日韩一区二区三区免费播放| 国产精品美女久久久| 奇米亚洲欧美| 久久精品免费一区二区三区 | 视频精品一区| 成人在线黄色| 日本大胆欧美人术艺术动态| 欧美一级久久| 韩国精品主播一区二区在线观看| 午夜在线精品偷拍| 国产 日韩 欧美 综合 一区| 国产精品嫩草99av在线| 国产精品99久久免费| 亚洲一区国产| 国产成人精品一区二区三区视频| 国产99精品一区| 天堂久久一区| 综合色一区二区| 久久亚洲专区| 国产精品欧美一区二区三区不卡| 999精品一区| 丰满少妇一区| 久久精品97| 天堂精品久久久久| 一区三区视频| 欧美国产小视频| 国产精品亚洲四区在线观看| 亚洲麻豆一区| 亚洲欧美日本视频在线观看| 91一区二区| 国精品产品一区| 久久精品超碰| 国产精品日本一区二区不卡视频| 亚洲伊人精品酒店| 天堂中文av在线资源库| 国产一区二区久久久久| 亚洲精品福利| 麻豆精品视频在线| 国产激情综合| 欧美成a人片免费观看久久五月天| 日韩精品免费观看视频| 久久亚洲国产精品一区二区| 午夜国产精品视频免费体验区| 性欧美videohd高精| 亲子伦视频一区二区三区| 91久久在线| 国产精品99视频| 香蕉视频成人在线观看| 日本亚洲最大的色成网站www| 日韩在线一区二区| 国产综合精品| 欧美日韩精品一本二本三本| 亚洲先锋成人| 视频在线观看一区| 欧美一区久久| 欧美激情五月| 日韩国产网站| 激情综合亚洲| 国产精品亚洲欧美一级在线| 精品午夜视频| 亚洲午夜av| 美女精品在线| 国产精品调教| 激情婷婷久久| 三级欧美在线一区| 国产精品日本一区二区不卡视频| 精品国产第一福利网站| 91九色精品国产一区二区| 日韩激情av在线| 亚洲黄色网址| 日本成人在线不卡视频| 国产videos久久| 国产精品普通话对白| 国产精品亚洲片在线播放| 欧美精选视频一区二区| 午夜天堂精品久久久久| 亚洲黄色网址| 欧美日韩a区| 欧美日韩四区| 国产精品高清一区二区| 在线日韩欧美| 久久97视频| 欧美一区在线观看视频| 亚洲一区区二区| 色在线中文字幕| 国产亚洲欧美日韩在线观看一区二区| 欧美激情aⅴ一区二区三区| 欧美日韩国产综合网| 国产精品国产三级国产在线观看| 国产精品呻吟| 日韩精品首页| 色吊丝一区二区|