error in runtime blank screen in opencv+android distance transform
I am getting a runtime blank-screen in distance transform in android+opencv I am using "mRgba = inputframe.rgba();" to take an input from camera and than I am doing threshold and all distance transform work. I dont know where something is wrong can anyone please answer me
My code is given below
Thanx in advance
package com.example.lastdemo;
import java.util.ArrayList;
import java.util.List;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.imgproc.Imgproc;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.SurfaceView;
import android.view.WindowManager;
public class MainActivity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "OCVSample::Activity";
public Bitmap newBitmap,bitmap;
public int no;
public Mat mBin,dist_8u;
public Bitmap bmpBinary;
public Mat imageMat;
public List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
public Mat hierarchy;
public Mat mRgba;
public Mat mGray;
public Mat mTemp,mTemp1;
private CameraBridgeViewBase mOpenCvCameraView;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
//mOpenCvCameraView.setOnTouchListener(MainActivity.this );
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public MainActivity() {
Log.i(TAG, "Instantiated new " + this.getClass());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate( savedInstanceState );
getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
setContentView(R.layout.tutorial1_surface_view);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById ( R.id.tutorial1_activity_java_surface_view );
mOpenCvCameraView.setVisibility( SurfaceView.VISIBLE );
mOpenCvCameraView.setCvCameraViewListener(this);
}
public void onCameraViewStarted(int width, int height) {
mGray = new Mat();
mRgba = new Mat();
}
public void onCameraViewStopped() {
}
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_BGRA2GRAY);
Imgproc.threshold(mGray, mBin, 40, 255, Imgproc.THRESH_BINARY);
Imgproc.distanceTransform(mGray, mTemp, Imgproc.DIST_LABEL_PIXEL, 3);
Core.normalize(mTemp, mBin, 0, 1., Core.NORM_MINMAX);
Imgproc.threshold(mBin, mBin, .5, 1., Imgproc.THRESH_BINARY);
mBin.convertTo(dist_8u, CvType.CV_8U);
mTemp1 = dist_8u;
hierarchy = new Mat();
Imgproc.findContours(dist_8u, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
no = contours.size();
return mTemp1;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this,
mLoaderCallback);
}
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
}
I just want the number of object in int "no" after distance transform please answer it really sucks
Answer plssss friends i m finding and trying to solve error since 2 week