我已经运行了这段代码。似乎结果没有生成result.png:
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);
答案 0 :(得分:0)
显然,当您致电result
时,showImage
为空。
代码中的问题是您测试状态是否正常(if ( status == stitcher.OK )
),然后尝试加载文件。你的代码应该是这样的:
if ( status != stitcher.OK )
{
std::cout << "ERROR" << std::endl;
return 1;
}
然后你可能会发现问题来自缝合。
此外,在显示文件之前,您无需将result
写入文件。