我尝试在相机视图上使用MatchTemplate,但是当我尝试将位图转换回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;
}发布于 2013-10-29 13:49:46
您需要初始化模板。
Mat Template= new Mat();那你就可以用它了。另外,我希望Utils.bitmapToMat会为Template = null抛出异常,但这是另一个故事.
https://stackoverflow.com/questions/19635298
复制相似问题