Programm keeps running, destroyAllWindows() doesnt work either

Hello,

I use openCV via Maven and Java. And even a very small programm doesn’t work as expected:

private static void startCV(){
        nu.pattern.OpenCV.loadLocally();
        Mat f= Imgcodecs.imread("D:\\Bilder\\bikinigross.jpg");
        HighGui.namedWindow("bild", HighGui.WINDOW_AUTOSIZE);
        HighGui.imshow("bild",f);
        HighGui.waitKey(500);
        HighGui.destroyAllWindows();

    }

This programm keeps running and the window doesn’t close.

welcome.

you should debug it, i.e. step through it and determine when it stops reacting.

Well, If i add some println Statments they will be executed. It is simply that the window with the image stays open and therefore the program won’t finish.

If I look in the HighGui class it seems to me that destroyAllWindows() doesnt’t close the window but only deletes it from the map where it was stored. But on the other hand I am certainly not the first one to use this library so if this was the reason it should have been fixed already.

not sure, if this is properly maintained. which opencv version did you get from there ?

indeed, you’re right:

it seems to expect another waitKey() call for the actual cleanup:

that would be news to me and contradicts all official examples I’ve ever seen. those windows.remove() calls are sure to do more than just “remove” it from a list.

This my maven dependency:

org.openpnp opencv 4.5.1-2

So, what is the take away?

can you try to put a HighGui.waitKey(1); after the destroyAllWindows() call ?

Then I get an error message: “Error: waitKey must be used after an imshow”
And the programm stops but only because of this error.

1 Like