{"id":1442,"date":"2015-05-29T22:18:18","date_gmt":"2015-05-29T14:18:18","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1442"},"modified":"2015-07-30T14:36:09","modified_gmt":"2015-07-30T06:36:09","slug":"opencv-and-processing-5-2","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2015\/05\/29\/opencv-and-processing-5-2\/","title":{"rendered":"OpenCV and Processing 5"},"content":{"rendered":"<p>Now we proceed to first core part of the tutorials, representation of image in Processing and OpenCV. In Processing, the class is <a href=\"https:\/\/processing.org\/reference\/PImage.html\">PImage<\/a>. Digital video, <a href=\"https:\/\/processing.org\/reference\/libraries\/video\/Movie.html\">Movie <\/a>and live webcam feed, <a href=\"https:\/\/processing.org\/reference\/libraries\/video\/Capture.html\">Capture<\/a> are also PImage. When we import the external image file from the data folder through <a href=\"https:\/\/processing.org\/reference\/loadImage_.html\">loadImage()<\/a>, the format will usually be RGB. The internal representation is, however, ARGB.<br \/>\n&nbsp;<br \/>\n<!--more--><br \/>\nThe data is maintained in an integer linear array pixels[]. Each pixel is a 4 bytes <a href=\"https:\/\/processing.org\/reference\/color_datatype.html\">color<\/a> element.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1445\" title=\"PImage01\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/05\/PImage01.jpg\" alt=\"\" width=\"640\" height=\"311\" srcset=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/05\/PImage01.jpg 640w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/05\/PImage01-300x145.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>In the diagram, it is the representation of an image of size width (8) x height (6). The pixels are arranged from 0 to 47. Each cell is a color data element, and which is also an integer. The color element uses one byte to represent each elementary color, including alpha channel, in the order of ARGB.<\/p>\n<p>The following sketch displays the color information for a random pixel of the PImage loaded from an external file in the data folder.<br \/>\n&nbsp;<\/p>\n<pre lang=\"java\">\r\nPImage img;\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n  background(0);\r\n  img = loadImage(\"sample01.jpg\");\r\n  noLoop();\r\n}\r\n\r\nvoid draw() {\r\n  image(img, 0, 0);\r\n  int x = floor(random(img.width));\r\n  int y = floor(random(img.height));\r\n  color c = img.pixels[y*img.width + x];\r\n  println(\"Alpha: \" + alpha(c));\r\n  println(\"Red:   \" + red(c));\r\n  println(\"Green: \" + green(c));\r\n  println(\"Blue:  \" + blue(c));\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now we proceed to first core part of the tutorials, representation of image in Processing and OpenCV. In Processing, the class is PImage. Digital video, Movie and live webcam feed, Capture are also PImage. When we import the external image file from the data folder through loadImage(), the format will usually be RGB. The internal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,79],"tags":[3,62],"class_list":["post-1442","post","type-post","status-publish","format-standard","hentry","category-research","category-software-2","tag-opencv","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1442","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=1442"}],"version-history":[{"count":4,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1442\/revisions"}],"predecessor-version":[{"id":1618,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1442\/revisions\/1618"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1442"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}