Below is the code i used
import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import java.io.InputStream;
public class MainActivity extends Activity {
ImageView iv;
protected BaseLoaderCallback OpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
System.out.println("tester");
onOpenCVReady();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private void OutputGrayMatToFile(Mat mGaryMat, String Filename)
{
ImageView img = (ImageView) findViewById(R.id.imgBelow);
Mat mRgba = new Mat();
Imgproc.cvtColor(mGaryMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mRgba, bmp);
img.setImageBitmap(bmp);
}
@Override
protected void onResume() {
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0,this,OpenCVCallBack);
}
protected void onOpenCVReady(){
//this should crash if opencv is not loaded
Mat img = new Mat();
Toast.makeText(getApplicationContext(), "opencv ready", Toast.LENGTH_LONG).show();
Bitmap footbm = BitmapFactory.decodeResource(getResources(), R.drawable.img);
// Bitmap footbm = BitmapFactory.decodeStream(is);
Mat footMat = new Mat();
//convert bitmap to opencv Mat
Utils.bitmapToMat(footbm, footMat);
//Convert to Gray image
Mat footGrayMat = new Mat();
Imgproc.cvtColor(footMat, footGrayMat, Imgproc.COLOR_BGR2GRAY, 1);
//Do canny
Mat outCannyMat = new Mat();
Imgproc.Canny(footGrayMat, outCannyMat, 80, 100, 3, false);
//output to file
OutputGrayMatToFile(outCannyMat, "Canny");
}
}
Question How can i get the square image from it I am not getting any idea as This is my first time using OpenCV and Image Processing.. So far i reached this point and quite frustrated with it or Anyone please tell me about any other better way with Object detection in an Image