Reputation: 43
How can I use OpenCV to process process some images saved on a smartphone, without using JavaCameraView?
I want to process an image saved on the SD card and then show the result of the process on the screen. I implemented my according to the tutorials from opencv4android libraries and they use the method onCameraFrame to show the image and implement the CameraViewListener and use CameraBridgeViewBase. However, I only want to process an image, I don´t want to use the camera to capture images and I think those elements may be unnecessary.
How can I change the opencv4android libraries and process stored images using OpenCV without using the camera?
Upvotes: 4
Views: 1100
Reputation: 201
If someone is still looking for an answer:
package com.example.ocv4androidwithoutcamera;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.InstallCallbackInterface;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends Activity implements LoaderCallbackInterface {
protected BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
onOpenCVReady();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume()
{
super.onResume();
Log.i("DEMO", "Trying to load OpenCV library");
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_4, this, mOpenCVCallBack))
{
Log.e("DEMO", "Cannot connect to OpenCV Manager");
}
}
protected void onOpenCVReady(){
//this should crash if opencv is not loaded
Mat img = new Mat();
Toast.makeText(getApplicationContext(), "opencv ready", Toast.LENGTH_LONG).show();
}
@Override
public void onManagerConnected(int status) {
// TODO Auto-generated method stub
}
@Override
public void onPackageInstall(int operation,
InstallCallbackInterface callback) {
// TODO Auto-generated method stub
}
}
Don’t forget to add opencv library in Project Properties => Android => Library.
Upvotes: 6