java - Why wont imshow() method work in OpenCV when i try to use it in intellij - Stack Overflow

admin2025-04-15  0

I am not able to use OpenCV's imshow() method . Can someone please help me with this . I will post a screenshot of the errors im facing . i would also appreciate some help in configuring intellij for OpenCV . This is the error im facing

Exception in thread "main" java.lang.RuntimeException: Unknown exception.
    at org.bytedeco.opencv.global.opencv_highgui.imshow(Native Method)
    at org.example.Main.main(Main.java:35)
public class Main {

    public static void main(String[] args) {
        Loader.load(opencv_core.class);


        VideoCapture capture = new VideoCapture(0);

        if (!capture.isOpened()){
            System.out.println("error eerror");
            return;
        }

        Mat frame = new Mat();

        while (true){
            if (capture.read(frame)){
                opencv_highgui.imshow("camera" , frame);

            }

            if (opencv_highgui.waitKey(1) == 27 ){
                break;
            }
            else {
                System.out.println("Unable to capture frame");
                break;
            }
        }

        capture.release();
        opencv_highgui.destroyAllWindows();
    }
}

this is what i wanted to try . The camera is turned on for a second and then this error pops up . Any help is appreciated . Thank you.

转载请注明原文地址:http://www.anycun.com/QandA/1744715400a86619.html