0

我正在尝试在相机视图上使用 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;
        }
4

1 回答 1

0

您需要初始化模板。

Mat Template= new Mat();

然后你就可以使用它了。我也希望Utils.bitmapToMat抛出异常,Template = null但这是一个不同的故事......

于 2013-10-29T13:49:46.247 回答