Mobile vision 4: OpenCV, NDK and Android Studio

dtdzung · 45K views · 2016 · 34:09

Open on YouTube

Computer vision, speech & NLPC, C++, Rust, Go & systems languagesTesting, debugging & developer toolstutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering how to get camera frames into OpenCV on Android, or as an example of the NDK and JNI setup that people follow and sometimes struggle with.

Recommended by 1 people across 1 different months, 2016 to 2017.

What it is

A 34-minute screen-recorded tutorial from the dtdzung channel on setting up OpenCV with the Android NDK in Android Studio and writing native C++ OpenCV code for an Android app. It walks through the project setup, JNI headers and the MainActivity camera code. It is part 4 of a mobile vision series.

What people said

Recommends Reeven · 2016-11 · Stack Overflow · on “What format i should convert the frames to to be used in openCV”

If your activity implements OpenCV's CameraBridgeViewBase.CvCameraViewListener2, it will also implement the onCameraFrame method which comes with a CvCameraViewFrame parameter. You can get your image in grayscale or RGBA format from that. This guy does it in this tutorial [this video] . This tutorial is about integrating native C++ OpenCV code, but if you do not need to do that, just pay attention to the part where he works on his MainActivity. EDIT: If you have access to your preview frame's data as a byte array, have you tried simply putting that data into a mat? Mat foo = new Mat(height, width, type); //type is probably CvType.CV_8UC1 foo.put(0, 0, data);

Cites ATutorMe · 2017-01 · Stack Overflow · on “Can OpenCV for Android leverage the standard C++ Support to get native build support on Android Studio 2.2 for Windows?”

This question is really good. Some of the AndroidNDK/OpenCV tutorials that I've come across follow a cumbersome approach (see [this video] ), where you have to compile jni headers, etc., and the power of Android Studio's IntelliJ magic is lost. +1 for the question and +1 for the answer below.

Cites Jonathan Seow · 2017-09 · Stack Overflow · on “Execution failed for task ":app:ndkBuild". >Process 'Command' finished with non-zero exit value 2”

Hi guys I am currently following a tutorial on Youtube to create a mobile application using android studio, unfortunately I ran into a few errors and could not solve it myself. The errors are the same for both the .cpp and .h file. Any help will be appreciated, thanks in advance! :) This is the error in my gradle build: Error:Execution failed for task ':app:ndkBuild'. > Process 'command 'C:/Users/dell/AppData/Local/Android/sdk/ndk-bundle/ndk- build.cmd'' finished with non-zero exit value 2 This is my .h File (Android studio says that there is a typo error for "jint" and missing ";"): /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> #include <stdio.h> #include <opencv2/o