{"id":1411,"date":"2015-05-04T23:23:44","date_gmt":"2015-05-04T15:23:44","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1411"},"modified":"2015-07-30T14:40:30","modified_gmt":"2015-07-30T06:40:30","slug":"opencv-and-processing-2","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2015\/05\/04\/opencv-and-processing-2\/","title":{"rendered":"OpenCV and Processing 2"},"content":{"rendered":"<p>The second example loads the OpenCV library; creates an identity matrix; and print its content in the console window.<br \/>\n&nbsp;<br \/>\n<!--more--><br \/>\n<strong>Example 2<\/strong><\/p>\n<pre lang=\"java\">\r\nimport org.opencv.core.Core;\r\nimport org.opencv.core.Mat;\r\nimport org.opencv.core.CvType;\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n  println(Core.VERSION);\r\n  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);\r\n  noLoop();\r\n}\r\n\r\nvoid draw() {\r\n  background(0);\r\n  Mat m = Mat.eye(3, 3, CvType.CV_8UC1);\r\n  println(m.dump());\r\n}\r\n<\/pre>\n<p>&nbsp;<br \/>\nThe command<\/p>\n<pre lang=\"java\">\r\nSystem.loadLibrary(Core.NATIVE_LIBRARY_NAME);\r\n<\/pre>\n<p>will load the <strong>opencv-300.jar<\/strong> library in the <strong>code<\/strong> folder.<\/p>\n<p><strong>Mat<\/strong> is the major data structure to maintain the matrix data in OpenCV. The static function<\/p>\n<pre lang=\"java\">Mat.eye(3, 3, CvType.CV_8UC1)<\/pre>\n<p>will create an identity matrix of size 3 x 3. Each data item is 1 element of 8 bit unsigned character. For image data we test later, we may use data type CV_8UC3 for the red, green and blue channels.<br \/>\nThe last command will print the matrix dump as string. The console output will be<\/p>\n<pre>\r\n[  1,   0,   0;\r\n   0,   1,   0;\r\n   0,   0,   1]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The second example loads the OpenCV library; creates an identity matrix; and print its content in the console window. &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,79],"tags":[3,62],"class_list":["post-1411","post","type-post","status-publish","format-standard","hentry","category-books","category-software-2","tag-opencv","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1411"}],"version-history":[{"count":7,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1411\/revisions"}],"predecessor-version":[{"id":1623,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1411\/revisions\/1623"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}