Displaying image and converting to grayscale - OpenCV for Android, Java API

前端 未结 4 970
陌清茗
陌清茗 2021-02-06 18:07

I\'m writing an Android app in Eclipse that uses the OpenCV4Android API. How can I display a Mat image easily, for debugging only? In C++, according to the OpenCV

4条回答
  •  别跟我提以往
    2021-02-06 18:50

    This is a sample code which would display an image (must have the image in drawable folder) in imageView using OpenCV:

     ImageVIew imgView = (ImageView) findViewById(R.id.sampleImageView);
            Mat mRgba = new MAt();
            mRgba = Utils.loadResource(MainAct.this, R.drawable.your_image,Highgui.CV_LOAD_IMAGE_COLOR);
            Bitmap img = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(),Bitmap.Config.ARGB_8888);
            Utils.matToBitmap(mRgba, img);
            imgView.setImageBitmap(img);
    

    and xml must have an ImageView as below :

    
    

    Hope this helps in solving your problem..

提交回复
热议问题