我有一个二进制图像。现在,当我点击我想要的按钮时,我该怎么做。?请帮我。
这是我的代码:
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2, Camera.PictureCallback {
private static final String TAG = "MainActivity";
private JavaCameraView mOpenCvCameraView;
private static final int REQUEST_CODE = 123;
private Button mButton;
private Mat mRgba;
private Mat mByte;
private Mat imGgray, imgCandy;
CameraBridgeViewBase.CvCameraViewFrame inputFrame;
BaseLoaderCallback mBaseLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
super.onManagerConnected(status);
switch (status) {
case BaseLoaderCallback.SUCCESS:
{
mOpenCvCameraView.enableView();
break;
}
default:
{
super.onManagerConnected(status);
break;
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
mButton = (Button) findViewById(R.id.detetionbutton);
mOpenCvCameraView = (JavaCameraView) findViewById(R.id.textdetetion_view);
mOpenCvCameraView.setCvCameraViewListener(this);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
mButton.setOnClickListener(new View.OnClickListener() { // take a picture
@Override
public void onClick(View v) {
}
});
}
@Override
public void onPause() {
super.onPause();
if (mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
}
}
@Override
public void onResume() {
super.onResume();
if (OpenCVLoader.initDebug() == true) {
Log.i(TAG, "opencv loaded");
mBaseLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
} else {
Log.i(TAG, "opencn not loade");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, this, mBaseLoaderCallback);
}
}
@Override
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
mByte = new Mat(height, width, CvType.CV_8UC4);
imGgray = new Mat(height, width, CvType.CV_8UC4);
imgCandy = new Mat(height, width, CvType.CV_8UC1);
}
@Override
public void onCameraViewStopped() {
mRgba.release();
}
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
Imgproc.cvtColor(mRgba, imGgray, Imgproc.COLOR_RGB2GRAY);
Imgproc.adaptiveThreshold(imGgray, mByte, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 35, 5);
return mByte; // this is m Binary image
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {}
}