How to Integrate OpenCV with Android Studio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there and welcome to my channel my name is shafeev yunus and in this channel we will be presenting android video tutorials in this tutorial we will be integrating opencv into android application so what is first opencv opencv stands for open computer vision library it's an open source computer vision library that helps and provide the infrastructure to do computer vision and machine learning application it has several interfaces to i don't know like windows linux and mac os and especially android we'll be doing the integration with android today it also featured cuda which is stand for the open extent for the gpu gpu thing to use the gpu into your basically linux windows or your android so the first thing is to create an android studio project okay so we'll be creating new empty activity here we'll click next name it whatever you want i will name it open opencv okay i'll be using kotlin as language or you can open your existing project in which you want to integrate opencv great basically there is two ways to integrate opencv into your project there is well the easiest way and there is the the complicated way it's not that complicated but we will see in a minute so the easiest way you would you will go first to quickbird studio repository they have an opencv android repository in which you can copy just a simple dependency which is this one they provide and they provide an easy way to integrate opencv into your android application via gradle it's just simple as that copy the implementation with opencv with contributions okay click and copy here go to your android studio and your gradle scripts choose build.gradle file okay for the app module and not the project much great here just paste that implementation you will need to get rid of this and this and we need basically version now opencv has several versions you can check check these versions from the releases and obviously if you go to opencv or g slash release i'll be pasting the links in the description below so here there is mutable versions on of android of opencv i will be choosing three points i will be choosing 3.4.50 this you can copy it and also check that quickbooks studio supported here it is okay go to android studio and paste it here great and now you can simply click sync now nice now and android studio is fully compatible with uh with opacity right now you can check this in your application by doing a simple command line simple line of code uh so opencv has a class open called opencv loader in which you have a method called init debug this will basically initialize opencv into your application now this method as you can see it returns a boolean which means if it which which tells if the initialization process were correct or not so we will just display the output of any debug okay we can do simply does in the text view or simply in log bar in the log line okay you copy that we'll say open tv loading stages like that and a content you can use string templates something like that we'll copy the tag for open cv great now we have just run the application when we will be running the application we will have an issue an issue in my computer yeah it's because i need java 11 to run you can simply fix this by going to file and choosing setting in the settings menu go to build execution and deployment search for build tools and now click on create in gradle gdk you have to choose 11 okay jdk 11. i'll be using the default with car with android switch okay select that and click ok great now you can launch your application i'm launching it in my emulator now go to your logcat file and here filter on the debug because we use log d which set for debug and here just choose open cv and now you can see here is our file our line opencv loading status was true it means it's loaded correctly okay that's the first first method of using opencv into android project okay the second way is a bit different okay so go to your build and okay what i did okay go to your build file and here just delete this line great now click sync now we will have some problems because we have to also delete this line and this line okay now check that the application is working correctly great the application is working correctly now we have to integrate opencv the second way so first of all you have to go to the releases panel of opencv you have to choose your version there is multiple versions to work with and once you choose a version make sure to download the android the android sdk and not other sdk okay just click on the android sdk and it will download okay that's the first step so basically i have my file in my desktop here i downloaded i downloaded 4.512 so you will open it and just extract it extract opencv into specified location that you like okay now here make sure you have the sdk file because there is uh there is a bug with android studio right now to import a module okay what i mean by that if you go to file and select a new and select import module this is the normal way to import to import to import opencv into your project so what you need to do is to click here select desktop directory and choose optioncv the extracted the extracted opencv and on in the sdk select the java folder and click ok now there is a bug with android studio in the mode the moment we are recording this video you can't click next or finish which is a book okay right now they are fixing it okay so we will do the process of this we of this wizard of importing module from source manually so the first thing to do is to go to your opencv here copy the sdk folder okay copy it and go to your source of the app you can basically click right open n and choose explore great here you can just paste it paste it here great you have to rename the file you don't have to but it is optional i will rename it to know it which is open cv and basically i can have a version name like five part two two like that click ok great now in android studio there is nothing appearing we have to tell the gradle the gradle script to use the opencv module go to settings.gradle file and here tell him to include the app and the opencv just be sure of the name of this photo i will just copy it and paste it here okay and click sync now great it will try to sync it great and here you go opencv 42 is here great and you will see another file of build.gradle opencv here it is there is this is how you can import it this is documentation basically sometimes there is some error with this file you will find the plugin com.application you have to change the application to library this one is good so it has no problem you can change also the target sdk version and the compiled sdk version to match the application version here is the application version it is 30 so change it here also to 30 here and here click sync now and you are ready to go so if you go here and you will try to use the open cv loader you won't find it why because the app module this one doesn't know anything about this module so we have to tell okay so basically there is a simple method go to this icon which means project structure or go to file and select project structure okay here under dependencies click on the app and we will add a dependency to the app okay the dependency is a module dependency because opencv is another module okay click on module and select this make sure you keep the implementation depend the implementation and click ok another okay and everything is good what happens under the hood is that we have the android studio added this line added this line you can we can do we can just copy and paste this line without going to project structure and adding the dependency option okay now if you if you want to type opencv dv loader we will find okay we will do just the same thing as we did before with the first way of quickbird studio it's log e okay go to plus no we will use content template open cv loading stages okay something like that something like that and choose copy this line okay we will change the tag to something else we'll just make it tag like that and we'll launch our application okay go to the locker tab and here search for tag and we will wait once the application is launched we must see a line here good opencv loading searches true great which means that the android studio and the integration with opencv has done successfully okay that's it for the video of today i hope you enjoyed it i hope you learned something if you learned something please leave a like and subscribe to the channel we'll be doing a lot of android stuff in here in this channel thank you very much and see you in the next video
Info
Channel: Charfaoui Younes
Views: 818
Rating: undefined out of 5
Keywords: AI, Machine Learning, Deep Learning, YOLO, Neural Networks, Object Detection, Python, OpenCV, Computer Vision, Android, Android Studio, Java, Kotlin, opencv tutorial, opencv projects, opencv android studio, opencv face recognition, opencv android, opencv android tutorial, android studio opencv tutorial, android studio opencv, android studio opencv camera, Face detection
Id: ECyOmSMgsPI
Channel Id: undefined
Length: 12min 19sec (739 seconds)
Published: Thu Sep 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.