我想将Mat转换为字节数据。它用于OpencV。
我的预期数据格式如下:
ex。)data = [112,113,0,1,0,225,........]
但是我的代码(System.outprint.ln(data))不等于上面的数据格式。 输出值为" I / System.out:[B @ 43d1d008"。
我该如何解决这个问题?
我的代码: ·当我触摸屏幕时,标志将被设置为" 1&#34 ;; 然后,在onCameraFrame中,Mat日期被转换为字节数据 并执行"的System.out.println(B)"
package opencv.ros.com.camera_opencv;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.WindowManager;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
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.Scalar;
import org.opencv.core.Size;
import java.io.BufferedOutputStream;
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener {
private CameraBridgeViewBase mCameraView;
private Mat mOutputFrame;
private volatile int Flag=0;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
mCameraView.enableView();
break;
default:
super.onManagerConnected(status);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
mCameraView = (CameraBridgeViewBase)findViewById(R.id.camera_view);
mCameraView.setCvCameraViewListener(this);
}
@Override
public void onPause() {
if (mCameraView != null) {
mCameraView.disableView();
}
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_4, this, mLoaderCallback);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_DOWN) {
Flag = 1;
System.out.println( Flag );
}
return true;
}
@Override
public void onDestroy() {
super.onDestroy();
if (mCameraView != null) {
mCameraView.disableView();
}
}
@Override
public void onCameraViewStarted(int width, int height) {
// Mat(int rows, int cols, int type)
// rows: height, cols: width
mOutputFrame = new Mat(height, width, CvType.CV_8UC3);
}
@Override
public void onCameraViewStopped() {
mOutputFrame.release();
}
@Override
public Mat onCameraFrame(Mat inputFrame) {
Mat img2 = new Mat(new Size(85,85),CvType.CV_8UC3);
if(Flag==1){
Flag=0;
int bufferSize = img2.channels()*img2.cols()*img2.rows();
byte [] b = new byte[bufferSize];
img2.get(0,0,b); // get all the pixels
System.out.println(b);
}
return img2;
}
}