opencv java resize不起作用

时间:2014-10-03 19:20:39

标签: java android opencv

我正在使用opencv在java中进行android开发。我试图让OpenCv Imgproc.resize()放大图像,但它不会改变放大率。它似乎只是将相同的图像从源复制到目标Mat而不进行任何更改。任何帮助,将不胜感激。谢谢。我的代码是:

Mat src = new Mat(bitmap.getWidth(), bitmap.getHeight(), CvType.CV_8UC3);

Utils.bitmapToMat(bitmap, src, true);

Mat dst = new Mat((int)(src.cols()*1.5), (int)(src.rows()*1.5), CvType.CV_8UC3);

Imgproc.resize(src, dst, dst.size()); //resize image

resizedBitmap = Bitmap.createBitmap(dst.cols(),  dst.rows(), Bitmap.Config.ARGB_8888);

Utils.matToBitmap(dst, resizedBitmap);

imageView.setImageBitmap(resizedBitmap);

2 个答案:

答案 0 :(得分:0)

Mat dst = new Mat(); //no, you don't have to pre-allocate it. this is no more C.
Imgproc.resize(src, dst, new Size(src.cols()*1.5), (int)(src.rows()*1.5)) ); //resize image
// or:
Imgproc.resize(src, dst, new Size(), 1.5, 1.5); //resize image

答案 1 :(得分:0)

之前我遇到过同样的问题,我解决了 将这些行放在代码中: -

 public class MainActivity  extends Activity {

       //Put your code here ...


        static {
                System.loadLibrary("opencv_java");
        }
    }