opencv for android官方教程Word下载.docx

上传人:b****5 文档编号:15706073 上传时间:2022-11-15 格式:DOCX 页数:15 大小:99.51KB
下载 相关 举报
opencv for android官方教程Word下载.docx_第1页
第1页 / 共15页
opencv for android官方教程Word下载.docx_第2页
第2页 / 共15页
opencv for android官方教程Word下载.docx_第3页
第3页 / 共15页
opencv for android官方教程Word下载.docx_第4页
第4页 / 共15页
opencv for android官方教程Word下载.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

opencv for android官方教程Word下载.docx

《opencv for android官方教程Word下载.docx》由会员分享,可在线阅读,更多相关《opencv for android官方教程Word下载.docx(15页珍藏版)》请在冰豆网上搜索。

opencv for android官方教程Word下载.docx

ThistutorialalsoassumesyouhaveOpenCV4AndroidSDKalreadyinstalledonyourdevelopmentmachineandOpenCVManageronyourtestingdevicecorrespondingly.Ifyouneedhelpwithanyofthese,youmayconsultourOpenCV4AndroidSDKtutorial.

Ifyouencounteranyerrorafterthoroughlyfollowingthesesteps,feelfreetocontactusviaOpenCV4AndroiddiscussiongrouporOpenCVQ&

Aforum.We’lldoourbesttohelpyouout.

UsingOpenCVLibraryWithinYourAndroidProject

InthissectionwewillexplainhowtomakesomeexistingprojecttouseOpenCV.Startingwith2.4.2releaseforAndroid,OpenCVManagerisusedtoprovideappswiththebestavailableversionofOpenCV.Youcangetmoreinformationhere:

AndroidOpenCVManagerandintheseslides.

Java

ApplicationDevelopmentwithAsyncInitialization

Usingasyncinitializationisarecommendedwayforapplicationdevelopment.ItusestheOpenCVManagertoaccessOpenCVlibrariesexternallyinstalledinthetargetsystem.

1.AddOpenCVlibraryprojecttoyourworkspace.UsemenuFile->

Import->

Existingprojectinyourworkspace.

PressBrowsebuttonandlocateOpenCV4AndroidSDK(OpenCV-2.4.9-android-sdk/sdk).

2.InapplicationprojectaddareferencetotheOpenCVJavaSDKinProject->

Properties->

Android->

Library->

AddselectOpenCVLibrary-2.4.9.

InmostcasesOpenCVManagermaybeinstalledautomaticallyfromGooglePlay.Forthecase,whenGooglePlayisnotavailable,i.e.emulator,developerboard,etc,youcaninstallitmanuallyusingadbtool.SeeHowtoselecttheproperversionofOpenCVManagerfordetails.

Thereisaverybasecodesnippetimplementingtheasyncinitialization.Itshowsbasicprinciples.Seethe“15-puzzle”OpenCVsamplefordetails.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

publicclassSample1JavaextendsActivityimplementsCvCameraViewListener{

privateBaseLoaderCallbackmLoaderCallback=newBaseLoaderCallback(this){

@Override

publicvoidonManagerConnected(intstatus){

switch(status){

caseLoaderCallbackInterface.SUCCESS:

{

Log.i(TAG,"

OpenCVloadedsuccessfully"

);

mOpenCvCameraView.enableView();

}break;

default:

super.onManagerConnected(status);

}

};

publicvoidonResume()

super.onResume();

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6,this,mLoaderCallback);

...

}

ItthiscaseapplicationworkswithOpenCVManagerinasynchronousfashion.OnManagerConnectedcallbackwillbecalledinUIthread,wheninitializationfinishes.Pleasenote,thatitisnotallowedtouseOpenCVcallsorloadOpenCV-dependentnativelibsbeforeinvokingthiscallback.LoadyourownnativelibrariesthatdependonOpenCVafterthesuccessfulOpenCVinitialization.DefaultBaseLoaderCallbackimplementationtreatapplicationcontextasActivityandcallsActivity.finish()methodtoexitincaseofinitializationfailure.Tooverridethisbehavioryouneedtooverridefinish()methodofBaseLoaderCallbackclassandimplementyourownfinalizationmethod.

ApplicationDevelopmentwithStaticInitialization

AccordingtothisapproachallOpenCVbinariesareincludedintoyourapplicationpackage.Itisdesignedmostlyfordevelopmentpurposes.Thisapproachisdeprecatedfortheproductioncode,releasepackageisrecommendedtocommunicatewithOpenCVManagerviatheasyncinitializationdescribedabove.

1.AddtheOpenCVlibraryprojecttoyourworkspacethesamewayasfortheasyncinitializationabove.UsemenuFile->

Existingprojectinyourworkspace,pressBrowsebuttonandselectOpenCVSDKpath(OpenCV-2.4.9-android-sdk/sdk).

2.IntheapplicationprojectaddareferencetotheOpenCV4AndroidSDKinProject->

AddselectOpenCVLibrary-2.4.9;

3.Ifyourapplicationprojectdoesn’thaveaJNIpart,justcopythecorrespondingOpenCVnativelibsfrom<

OpenCV-2.4.9-android-sdk>

/sdk/native/libs/<

target_arch>

toyourprojectdirectorytofolderlibs/<

.

IncaseoftheapplicationprojectwithaJNIpart,insteadofmanuallibrariescopyingyouneedtomodifyyourAndroid.mkfile:

addthefollowingtwocodelinesafterthe"

include$(CLEAR_VARS)"

andbefore"

includepath_to_OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk"

1

2

OPENCV_CAMERA_MODULES:

=on

OP

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1