问题
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);
}
}
and the error is
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);
回答1:
Apparently, result
is null when you call showImage
.
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.
Moreover, you don't need to write result
to a file before showing it.
来源:https://stackoverflow.com/questions/16624953/image-stitching-nullpointerexception