我尝试在相机视图上使用MatchTemplate,但是当我尝试将位图转换回mat时,输出mat为null,并且没有错误。
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if(Template != null){
Imgproc.matchTemplate(mRgba, Template, mRgba, Imgproc.TM_SQDIFF);
Core.putText(mRgba, "Matching", new Point(50, 50), BIND_AUTO_CREATE, BIND_AUTO_CREATE, Color_Green, 2);
}
return mRgba;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Mat tmp = new Mat (100, 100, CvType.CV_8UC3, new Scalar(4));
Imgproc.cvtColor(mRgba, tmp, Imgproc.COLOR_RGBA2mRGBA, 0);
bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(tmp, bmp);
bmp = Bitmap.createBitmap(bmp, mRgba.cols()/2-50, mRgba.rows()/2-50, 100, 100, null, false);
//show for debug
ImageView Img = (ImageView)findViewById(R.id.imageView1);
Img.setImageBitmap(bmp);
Bitmap matbitmap = bmp.copy(Bitmap.Config.ARGB_8888, false);
Utils.bitmapToMat(matbitmap, Template);//the output Template is null,so that I can't do next work
return false;
}
答案 0 :(得分:0)
您需要初始化模板。
Mat Template= new Mat();
然后你可以使用它。另外我希望Utils.bitmapToMat
为Template = null
抛出异常,但这是另一回事......