Path: blob/master/DNN-OpenCV-Classification-Android/README.md
3118 views
This contains the code for Image Classification with OpenCV for Android. For more information - visit Image Classification with OpenCV for Android
Getting Started
Our code is tested using Python 3.7.5, but it should also work with any other python3.x. If you'd like to check your version run:
Virtual Environment
Let's create a new virtual environment. You'll need to install virtualenv package if you don't have it:
Now we can create a new virtualenv variable and call it env
:
The last thing we have to do is to activate it:
To install the required python dependencies run:
OpenCV
In this blog post we are using OpenCV 4.3.0 unavailable via pip
. The first step is building the OpenCV library. To do so:
Check the list of the below libraries. Install the missed dependencies:
For OpenCV Java installation we used default Java Runtime Environment and Java Development Kit:
Download the latest OpenCV version from the official repository:
Unzip the downloaded archives:
Rename the directories to match CMake paths:
Compile OpenCV. Create and enter a build directory:
Run CMake to configure the OpenCV build. Don't forget to set the right pass to the
PYTHON_EXECUTABLE
:
If you want to configure the build with some specific Java version, please, add the following fields, verifying the paths:
Check the output and make sure that everything is set correctly. After that we're ready to build it with:
Make sure, you didn't get any errors. In case of successful completion you will find the following files in the build
directory lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so
.
Then run the following command:
which creates the necessary links and cache to our freshly built shared library.
The last step is to move lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so
into the virtual environment installed packages:
OpenCV Android
For Android application development we will need OpenCV for Android:
Executing Model Conversion and Test Script
The proposed for the experiments MobileNetV2ToOnnx.py
script supports the --input_image
key to customize the model conversion pipeline. It defines the full input image path, including its name - "test_img_cup.jpg"
by default.
To run MobileNetV2 conversion case, please, choose one of the described below scenarios:
for the custom input image and running evaluation of the converted model:
for the default input image:
AI Courses by OpenCV
Want to become an expert in AI? AI Courses by OpenCV is a great place to start.