0

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);
JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
  • where are you creating your stitcher instance? – foundry May 18 '13 at 19:50
  • sorry i have missing it here Stitcher stitcher = Stitcher.createDefault(false); I had include it as the first line of the main method.sorry I have missed it here.If the instance was there it gives the same error. – user2294002 May 19 '13 at 00:35

1 Answers1

0

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.

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
  • Are you even sure that "sample1.png" and "sample2.png" are opened successfully? – JonasVautherin May 23 '13 at 07:14
  • How do you know this? Did you apply `canvas.showImage` on them? – JonasVautherin May 23 '13 at 09:08
  • By the way, [you don't behave correctly](http://stackoverflow.com/about) with your questions. When there is a valid answer to your question, you must validate it. You cannot use a question as an online assistance for your compilation problems. – JonasVautherin May 23 '13 at 09:18
  • yes. just check them with this code result = cvLoadImage("sample1.png"); final CanvasFrame canvas = new CanvasFrame("My Image", 1); canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); canvas.showImage(result); – user2294002 May 23 '13 at 09:19
  • Then you should investigate into the stitcher status, and this is another question. If it is not `status.OK`, then it is something else that will give you hints. – JonasVautherin May 23 '13 at 09:23