Dale
Dale

Reputation: 21

opencv java resize does not work

I am doing android development in java with opencv. I am trying to get OpenCv Imgproc.resize() to zoom in on an image, but it does not change the magnification. It seems to just copy the same image from a source to destination Mat with no changes. Any help would be appreciated. Thanks. My code is:

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);

Upvotes: 1

Views: 3098

Answers (2)

Anonymous
Anonymous

Reputation: 119

I had the same problem before and I solve it by put those lines in the code :-

 public class MainActivity  extends Activity {

       //Put your code here ...


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

Upvotes: 1

berak
berak

Reputation: 39796

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

Upvotes: 0

Related Questions