{"id":3269,"date":"2021-07-23T08:42:11","date_gmt":"2021-07-23T08:42:11","guid":{"rendered":"https:\/\/www.bearloga.space\/?page_id=3269"},"modified":"2021-07-23T08:42:12","modified_gmt":"2021-07-23T08:42:12","slug":"opencv-gui","status":"publish","type":"page","link":"https:\/\/www.bearloga.space\/en\/opencv-gui\/","title":{"rendered":"OpenCV \u2014 GUI"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0433\u043b\u0430\u0432\u0430\u0445 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438, \u043a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 OpenCV.&nbsp;\u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u043c\u0443, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u043d\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 GUI, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a AWT \/ Swings \u0438 JavaFX.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u0442\u0430 \u0432 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434&nbsp;<strong>imread ()<\/strong>&nbsp;.&nbsp;\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0432 \u0444\u043e\u0440\u043c\u0435&nbsp;<strong>Matrix<\/strong>&nbsp;.&nbsp;\u041d\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 GUI (AWT \/ Swings \u0438 JavaFX), \u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430&nbsp;<strong>BufferedImage<\/strong>&nbsp;\u043f\u0430\u043a\u0435\u0442\u0430&nbsp;<strong>java.awt.image.BufferedImage<\/strong>&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0448\u0430\u0433\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430&nbsp;<strong>Mat<\/strong>&nbsp;\u0438\u0437 OpenCV \u0432 \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<strong>BufferedImage<\/strong>&nbsp;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u0428\u0430\u0433 1: \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0442 \u0432 MatOfByte<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0431\u0430\u0439\u0442\u0430.&nbsp;\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434&nbsp;<strong>imencode ()<\/strong>&nbsp;\u043a\u043b\u0430\u0441\u0441\u0430&nbsp;<strong>Imgcodecs<\/strong>&nbsp;.&nbsp;\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">imencode(ext, image, matOfByte);\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u2014<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Ext<\/strong>&nbsp;\u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 String, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (.jpg, .png \u0438 \u0442. \u0414.)<\/li><li><strong>\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/strong>&nbsp;\u2014 \u041c\u0430\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/li><li><strong>matOfByte<\/strong>&nbsp;\u2014 \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 MatOfByte<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ext<\/strong>&nbsp;\u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 String, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (.jpg, .png \u0438 \u0442. \u0414.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/strong>&nbsp;\u2014 \u041c\u0430\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>matOfByte<\/strong>&nbsp;\u2014 \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 MatOfByte<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u043e\u0434\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/Reading the image \nMat image = Imgcodecs.imread(file);\n\n\/\/instantiating an empty MatOfByte class \nMatOfByte matOfByte = new MatOfByte();\n\n\/\/Converting the Mat object to MatOfByte \nImgcodecs.imencode(\".jpg\", image, matOfByte);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u0428\u0430\u0433 2: \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 MatOfByte \u0432 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0439\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<strong>MatOfByte<\/strong>&nbsp;\u0432 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434&nbsp;<strong>toArray ()<\/strong>&nbsp;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">byte[] byteArray = matOfByte.toArray();\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u0428\u0430\u0433 3: \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 InputStream<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u044c\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 InputStream, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435, \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<strong>ByteArrayInputStream<\/strong>\u00a0.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/Preparing the InputStream object \nInputStream in = new ByteArrayInputStream(byteArray);\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u0428\u0430\u0433 4: \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 InputStream<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 Input Stream, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435, \u0432 \u043c\u0435\u0442\u043e\u0434&nbsp;<strong>read ()<\/strong>&nbsp;\u043a\u043b\u0430\u0441\u0441\u0430&nbsp;<strong>ImageIO<\/strong>&nbsp;.&nbsp;\u042d\u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 BufferedImage.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/Preparing the BufferedImage \nBufferedImage bufImage = ImageIO.read(in);\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AWT \/ Swings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0440\u0435\u0439\u043c\u0430 AWT \/ Swings, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<strong>\u043c\u0435\u0442\u043e\u0434\u0430 imread ()<\/strong>&nbsp;\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0439\u0442\u0435 \u0435\u0433\u043e \u0432&nbsp;<strong>BufferedImage,<\/strong>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0435 \u0448\u0430\u0433\u0438.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430&nbsp;<strong>JFrame<\/strong>&nbsp;\u0438 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0435 \u0432 ContentPane JFrame, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/Instantiate JFrame \nJFrame frame = new JFrame();\n \n\/\/Set Content to the JFrame \nframe.getContentPane().add(new JLabel(new ImageIcon(bufImage))); \nframe.pack(); \nframe.setVisible(true);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u043f\u0440\u0438\u043c\u0435\u0440<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435&nbsp;<strong>\u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/strong>&nbsp;\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438&nbsp;<strong>\u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c<\/strong>&nbsp;\u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u043e\u043a\u043d\u043e \u0441\u0432\u0438\u043d\u0433\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 OpenCV.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import java.awt.image.BufferedImage;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.InputStream;\n\nimport javax.imageio.ImageIO;\nimport javax.swing.ImageIcon;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\n\nimport org.opencv.core.Core;\nimport org.opencv.core.Mat;\nimport org.opencv.core.MatOfByte;\nimport org.opencv.imgcodecs.Imgcodecs;\n\npublic class DisplayingImagesUsingSwings {\n   public static void main(String args[]) throws Exception { \n      \/\/Loading the OpenCV core library  \n      System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); \n    \n      \/\/Reading the Image from the file and storing it in to a Matrix object \n      String file = \"C:\/EXAMPLES\/OpenCV\/sample.jpg\"; \n      Mat image = Imgcodecs.imread(file); \n    \n      \/\/Encoding the image \n      MatOfByte matOfByte = new MatOfByte();       \n      Imgcodecs.imencode(\".jpg\", image, matOfByte); \n\n      \/\/Storing the encoded Mat in a byte array \n      byte[] byteArray = matOfByte.toArray(); \n\n      \/\/Preparing the Buffered Image \n      InputStream in = new ByteArrayInputStream(byteArray); \n      BufferedImage bufImage = ImageIO.read(in); \n\n      \/\/Instantiate JFrame \n      JFrame frame = new JFrame(); \n\n      \/\/Set Content to the JFrame \n      frame.getContentPane().add(new JLabel(new ImageIcon(bufImage))); \n      frame.pack(); \n      frame.setVisible(true);\n      \n      System.out.println(\"Image Loaded\");     \n   } \n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Image Loaded\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043e\u043a\u043d\u043e, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0435\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/displaying_image_using_swings.png\" alt=\"\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Swings\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c JavaFX<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c JavaFX, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<strong>\u043c\u0435\u0442\u043e\u0434\u0430 imread ()<\/strong>&nbsp;\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0439\u0442\u0435 \u0435\u0433\u043e \u0432&nbsp;<strong>BufferedImage<\/strong>&nbsp;.&nbsp;\u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0439\u0442\u0435 BufferedImage \u0432 WritableImage, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">WritableImage writableImage = SwingFXUtils.toFXImage(bufImage, null);\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<strong>WritableImage<\/strong>&nbsp;\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430&nbsp;<strong>ImageView<\/strong>&nbsp;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ImageView imageView = new ImageView(writableImage);\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u043f\u0440\u0438\u043c\u0435\u0440<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a&nbsp;<strong>\u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/strong>&nbsp;\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438&nbsp;<strong>\u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c<\/strong>&nbsp;\u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u043e\u043a\u043d\u043e JavaFX \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 OpenCV.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import java.awt.image.BufferedImage;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\n\nimport javafx.application.Application;\nimport javafx.embed.swing.SwingFXUtils;\nimport javafx.scene.Group;\nimport javafx.scene.Scene;\nimport javafx.scene.image.ImageView;\nimport javafx.scene.image.WritableImage;\nimport javafx.stage.Stage;\n\nimport javax.imageio.ImageIO;\n\nimport org.opencv.core.Core;\nimport org.opencv.core.Mat;\nimport org.opencv.core.MatOfByte;\nimport org.opencv.imgcodecs.Imgcodecs;\n\npublic class DisplayingImagesJavaFX extends Application {\n   @Override \n   public void start(Stage stage) throws IOException {   \n      WritableImage writableImage = loadImage(); \n  \n      \/\/Setting the image view \n      ImageView imageView = new ImageView(writableImage); \n        \n      \/\/Setting the position of the image \n      imageView.setX(50); \n      imageView.setY(25); \n        \n      \/\/setting the fit height and width of the image view \n      imageView.setFitHeight(400); \n      imageView.setFitWidth(500);\n      \n      \/\/Setting the preserve ratio of the image view\n      imageView.setPreserveRatio(true);\n      \n      \/\/Creating a Group object  \n      Group root = new Group(imageView);\n      \n      \/\/Creating a scene object\n      Scene scene = new Scene(root, 600, 400);\n      \n      \/\/Setting title to the Stage \n      stage.setTitle(\"Loading an image\");\n      \n      \/\/Adding scene to the stage\n      stage.setScene(scene);\n\n      \/\/Displaying the contents of the stage\n      stage.show();\n   } \n   public WritableImage loadImage() throws IOException {\n      \/\/Loading the OpenCV core library  \n      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );\n      \n      \/\/Reading the Image from the file and storing it in to a Matrix object\n      String file =\"C:\/EXAMPLES\/OpenCV\/sample.jpg\";\n      Mat image = Imgcodecs.imread(file);\n      \n      \/\/Encoding the image\n      MatOfByte matOfByte = new MatOfByte();\n      Imgcodecs.imencode(\".jpg\", image, matOfByte);\n\n      \/\/Storing the encoded Mat in a byte array\n      byte[] byteArray = matOfByte.toArray();\n      \n      \/\/Displaying the image\n      InputStream in = new ByteArrayInputStream(byteArray); \n      BufferedImage bufImage = ImageIO.read(in);\n\n      System.out.println(\"Image Loaded\");\n      WritableImage writableImage = SwingFXUtils.toFXImage(bufImage, null);\n      return writableImage; \n   }\n   public static void main(String args[]) {\n      launch(args); \n   } \n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Image Loaded<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0433\u043b\u0430\u0432\u0430\u0445 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438, \u043a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 OpenCV.&nbsp;\u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u043c\u0443, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[108],"tags":[],"class_list":["post-3269","page","type-page","status-publish","hentry","category-opencv"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/3269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/comments?post=3269"}],"version-history":[{"count":0,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/3269\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/media?parent=3269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/categories?post=3269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/tags?post=3269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}