{"action":"opened","issue":{"url":"https://api.github.com/repos/Arxa/Bachelor_Thesis/issues/5","repository_url":"https://api.github.com/repos/Arxa/Bachelor_Thesis","labels_url":"https://api.github.com/repos/Arxa/Bachelor_Thesis/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/Arxa/Bachelor_Thesis/issues/5/comments","events_url":"https://api.github.com/repos/Arxa/Bachelor_Thesis/issues/5/events","html_url":"https://github.com/Arxa/Bachelor_Thesis/issues/5","id":191811072,"number":5,"title":"How can I use Threads in JavaFX?","user":{"login":"Arxa","id":15330998,"avatar_url":"https://avatars.githubusercontent.com/u/15330998?v=3","gravatar_id":"","url":"https://api.github.com/users/Arxa","html_url":"https://github.com/Arxa","followers_url":"https://api.github.com/users/Arxa/followers","following_url":"https://api.github.com/users/Arxa/following{/other_user}","gists_url":"https://api.github.com/users/Arxa/gists{/gist_id}","starred_url":"https://api.github.com/users/Arxa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arxa/subscriptions","organizations_url":"https://api.github.com/users/Arxa/orgs","repos_url":"https://api.github.com/users/Arxa/repos","events_url":"https://api.github.com/users/Arxa/events{/privacy}","received_events_url":"https://api.github.com/users/Arxa/received_events","type":"User","site_admin":false},"labels":[{"id":482346430,"url":"https://api.github.com/repos/Arxa/Bachelor_Thesis/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":{"login":"Arxa","id":15330998,"avatar_url":"https://avatars.githubusercontent.com/u/15330998?v=3","gravatar_id":"","url":"https://api.github.com/users/Arxa","html_url":"https://github.com/Arxa","followers_url":"https://api.github.com/users/Arxa/followers","following_url":"https://api.github.com/users/Arxa/following{/other_user}","gists_url":"https://api.github.com/users/Arxa/gists{/gist_id}","starred_url":"https://api.github.com/users/Arxa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arxa/subscriptions","organizations_url":"https://api.github.com/users/Arxa/orgs","repos_url":"https://api.github.com/users/Arxa/repos","events_url":"https://api.github.com/users/Arxa/events{/privacy}","received_events_url":"https://api.github.com/users/Arxa/received_events","type":"User","site_admin":false},"assignees":[{"login":"Arxa","id":15330998,"avatar_url":"https://avatars.githubusercontent.com/u/15330998?v=3","gravatar_id":"","url":"https://api.github.com/users/Arxa","html_url":"https://github.com/Arxa","followers_url":"https://api.github.com/users/Arxa/followers","following_url":"https://api.github.com/users/Arxa/following{/other_user}","gists_url":"https://api.github.com/users/Arxa/gists{/gist_id}","starred_url":"https://api.github.com/users/Arxa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arxa/subscriptions","organizations_url":"https://api.github.com/users/Arxa/orgs","repos_url":"https://api.github.com/users/Arxa/repos","events_url":"https://api.github.com/users/Arxa/events{/privacy}","received_events_url":"https://api.github.com/users/Arxa/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2016-11-26T15:23:20Z","updated_at":"2016-11-26T15:23:20Z","closed_at":null,"body":"In Summary, we should use `Task` for heavy tasks and `Platform.runLater()` for GUI tasks.\r\n\r\n- Using `Task` to perform some heavy algorithms that are not interfering with our GUI.\r\n\r\n In the following snip of code, we are grabbing the video file frames by two in order to find their matched corners.\r\n\r\n```\r\nTask<Void> task = new Task<Void>()\r\n            {\r\n                @Override protected Void call() throws Exception\r\n                {\r\n                    while (true)\r\n                    {\r\n                        Mat frame1 = new Mat();\r\n                        Mat frame2 = new Mat();\r\n                        if (cap.read(frame1) && cap.read(frame2))\r\n                        {\r\n                            PixelProcessor.findMatchedCorners(frame1, frame2);\r\n                            System.out.println(\"finding corners...\");\r\n                        }\r\n                        else break;\r\n                    }\r\n                    return null;\r\n                }\r\n            };\r\n            Thread th = new Thread(task);\r\n            th.setDaemon(true);\r\n            th.start();\r\n```\r\n\r\n- Using `Platform.runLater()` to update our Scene Panel with our corner detected frames. We use a time delay to make it visible (something like a GIF)\r\n\r\n\r\n```\r\nTask task = new Task<Void>()\r\n        {\r\n            @Override\r\n            public Void call() throws Exception\r\n            {\r\n                for (FrameCorners f : frameCornersList)\r\n                {\r\n                    Platform.runLater(() -> {\r\n                        Platform.setImplicitExit(false);\r\n                        System.out.println(\"Showing image\");\r\n\r\n                        // Converting Mat to Image\r\n                        MatOfByte byteMat1 = new MatOfByte();\r\n                        Imgcodecs.imencode(\".bmp\", f.getFrame(), byteMat1);\r\n                        Image image1 = new Image(new ByteArrayInputStream(byteMat1.toArray()));\r\n                        ImageView iv1 = new ImageView(image1);\r\n                        // Show frame on Scene\r\n                        pane2.getChildren().add(iv1);\r\n                        iv1.fitHeightProperty().bind(pane2.heightProperty());\r\n                        iv1.fitWidthProperty().bind(pane2.widthProperty());\r\n                    });\r\n                    Thread.sleep(500);\r\n                }\r\n                return null;\r\n            }\r\n        };\r\n        Thread th = new Thread(task);\r\n        th.setDaemon(true);\r\n        th.start();\r\n```"}}
{"actor":{"display_login":"Arxa"}}