Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your problem is that the mat object are known only after LoaderCallbackInterface is SUCCESS

do this(I didn't check your code) :

public class MainActivity extends Activity implements CvCameraViewListener2 {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView goster=(ImageView)findViewById(R.id.imageView1);
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.testx);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Config.RGB_565;
    Bitmap input = BitmapFactory.decodeFile("testx.jpg", options);



}
@Override
public void onResume() {
    super.onResume();
    overridePendingTransition(0, 0);
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
}
 public void onPause()
 {
     super.onPause();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }
 public void onDestroy() {
     super.onDestroy();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }
@Override
public void onCameraViewStarted(int width, int height) {
    // TODO Auto-generated method stub

}
@Override
public void onCameraViewStopped() {
    // TODO Auto-generated method stub

}
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    // TODO Auto-generated method stub
    return null;
}
Date startdate, enddate;
 private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {

                    Mat mat = new Mat();
                    // Utils.bitmapToMat(input, mat);
                    //     Highgui.imwrite("mat.jpg", mat);
                    goster.setImageBitmap(input);

                } //break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

}

Your problem is that the mat object are known only after LoaderCallbackInterface is SUCCESS

try to do this(I didn't check your code) :

public class MainActivity extends Activity implements CvCameraViewListener2 {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView goster=(ImageView)findViewById(R.id.imageView1);
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.testx);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Config.RGB_565;
    Bitmap input = BitmapFactory.decodeFile("testx.jpg", options);



}
@Override
public void onResume() {
    super.onResume();
    overridePendingTransition(0, 0);
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
}
 public void onPause()
 {
     super.onPause();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }
 public void onDestroy() {
     super.onDestroy();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }
@Override
public void onCameraViewStarted(int width, int height) {
    // TODO Auto-generated method stub

}
@Override
public void onCameraViewStopped() {
    // TODO Auto-generated method stub

}
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    // TODO Auto-generated method stub
    return null;
}
Date startdate, enddate;
 private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {

                    Mat mat = new Mat();
                    // Utils.bitmapToMat(input, mat);
                    //     Highgui.imwrite("mat.jpg", mat);
                    goster.setImageBitmap(input);

                } //break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

}