How to update the camera image on the javafx interface in real time after using opencv to obtain the camera image for processing?

problem description

after obtaining the camera image using opencv, perform a series of processing, including equalization, binarization, and so on, to obtain the imageView object, so how to put this object on the interface of javafx? And the camera will continue to send images over for processing, which requires the interface to be constantly refreshed.

problem environment background

I look up the information on the UI of javafx and its update is not thread-safe. I have tried to click the button and open a thread to use a loop to constantly let this thread update the main thread"s UI interface, but this will cause a serious problem, that is, the interface will get stuck. Am I updating the interface in the wrong way?

related codes

public void originalImageAction(ActionEvent actionEvent) {
    System.out.println(myCamera.getMyImage().status);
    Task<Integer> task = new Task<Integer>() {
        @Override
        protected Integer call() throws Exception {

            return 1;
        }
    };
    Thread thread = new Thread() {
        @Override
        public void run() {
            while (true){
                if(!myCamera.getMyImage().isOriginal()) {
                    myCamera.getMyImage().setOriginalStatus();
                    while (myCamera.getMyImage().isOriginal()){
                        //
                        Platform.runLater(() -> {
                            Borderpane.setCenter(myCamera.getImageView());//
                        });
                    }
                }
            }
        }
    };
    thread.setName("updateUiThread");
    thread.start();

}

result

above is the button click event I added. After clicking, start the thread to update the interface. It is expected that the displayed image can be refreshed in real time, resulting in a serious stutter problem. It is estimated that it is the problem of UI update. Platform.runLater will put the update of UI to the main thread, so that the main thread will get stuck once there are other updates. Is there anything you can do?

Menu