使用resize Open Cv Java时出现空指针异常
我正在编写一个程序,在保留纵横比的同时调整图像的大小。基本上,我试图将源图像放入一个20x20的框中,并保留纵横比使用resize Open Cv Java时出现空指针异常,java,opencv,Java,Opencv,我正在编写一个程序,在保留纵横比的同时调整图像的大小。基本上,我试图将源图像放入一个20x20的框中,并保留纵横比 float ra= (float)20/image.width(); Size dsize = new Size((int)(image.height()*ra),20); // System.out.println(image.height() + " "+image.width()); //System.out.println((int)(image.height()*ra)+
float ra= (float)20/image.width();
Size dsize = new Size((int)(image.height()*ra),20);
// System.out.println(image.height() + " "+image.width());
//System.out.println((int)(image.height()*ra)+" " + 20);
Imgproc.resize(image,output, dsize,ra,ra, Imgproc.INTER_LINEAR);
输入,图像是一个垫子。image.height()=10,image.width()=28。新尺寸为7,20。
但是,当我运行代码时,在Imgproc.resize()处会出现一个空指针异常。我找不到原因。即使我运行,也会出现同样的错误
Imgproc.resize(image,output,dsize);
- 使用dsize或比例因子,不能同时使用两者
- 你可能忘了: 输出=新垫();//您可以传递空垫,但不能为空