图像拼接:NullPointerException [英] Image stitching: NullPointerException
本文介绍了图像拼接:NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经运行了这段代码.结果似乎未生成result.png:
I have run this code. It seems to be that result.png is not generated as a result:
public class ImageStitching {
public static void main(String[] args){
MatVector images = new MatVector(2);
images.put(0,cvLoadImage("sample1.png"));
images.put(1,cvLoadImage("sample2.png"));
IplImage result = new IplImage(null);
int status = stitcher.stitch(images,result);
if( status == stitcher.OK )
{
cvSaveImage("result.png", result);
}
result = cvLoadImage("result.png");
final CanvasFrame canvas = new CanvasFrame("My Image", 1);
// Request closing of the application when the image window is closed.
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
// Show image on window.
canvas.showImage(result);
}
}
,错误是
Exception in thread "main" java.lang.NullPointerException
at com.googlecode.javacv.CanvasFrame.showImage(CanvasFrame.java:366)
at com.googlecode.javacv.CanvasFrame.showImage(CanvasFrame.java:363)
at ImageStitching.main(ImageStitching.java:50)
java:50 is canvas.showImage(result);
推荐答案
显然,调用showImage
时result
为null.
Apparently, result
is null when you call showImage
.
您的代码中的问题是您测试状态是否为OK(if ( status == stitcher.OK )
),然后无论如何尝试加载文件.您的代码应类似于:
The problem in your code is that you test if the status is OK (if ( status == stitcher.OK )
), and then you try to load the file anyway. Your code should be something like:
if ( status != stitcher.OK )
{
std::cout << "ERROR" << std::endl;
return 1;
}
那么您可能会发现问题出在缝合上.
Then you would probably see that the problem comes from the stitching.
此外,您无需在显示文件之前将result
写入文件.
Moreover, you don't need to write result
to a file before showing it.
这篇关于图像拼接:NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文