I apologize if this question has already been covered on this site, but I can't seem to find a straight forward answer. I'm making an android app that uses OpenCV to take a picture, process it to detect objects, and figure out the coordinates of those objects in the scene.
All the tutorials I find for android seem to be real time processing of the camera preview or using c++, which I would strongly prefer to not have to go down the c++ road. I'm sure I'm missing something simple but I don't know what it is.
On another note, the objects I'm trying to detect are billiards balls on a table. What would be the best pre-processing technique to better detect the balls? I did a quick test using the canny method, and it seems that the light reflecting off the balls breaks up the circle shape.
The below steps for using Android OpenCV sdk in Android Studio. This is a simplified version of this SO answer. Download latest OpenCV sdk for Android from OpenCV.org and decompress the zip file. Import OpenCV to Android Studio, From File -> New -> Import Module, choose sdk/java folder in the unzipped opencv archive.
What is the OpenCV routine for reading an image from a file? imread() Loads an image from a file. The function imread loads an image from the specified file and returns it.
I know it's too late, but someone may use this.
Highgui has been removed from opencv for android.
You can use Imgcodes instead.
Mat BGRMat = Imgcodecs.imread(getResources().getDrawable(R.drawable.img).toString());
This works for me (got the answer from here: How to get Mat with a drawable input in Android using OpenCV)
Mat img = null;
try {
img = Utils.loadResource(this, R.drawable.image_id, CvType.CV_8UC4);
} catch (IOException e) {
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With