{"id":1511,"date":"2015-06-22T23:27:09","date_gmt":"2015-06-22T15:27:09","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1511"},"modified":"2015-07-05T22:14:15","modified_gmt":"2015-07-05T14:14:15","slug":"opencv-and-processing-11","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2015\/06\/22\/opencv-and-processing-11\/","title":{"rendered":"OpenCV and Processing 11"},"content":{"rendered":"<p>In this example, I demonstrate the use of the image processing module (Imgproc) with the filter2D function. It is similar to the generic Photoshop filter where you can design the convolution matrix. The example references <a href=\"http:\/\/docs.opencv.org\/3.0-beta\/doc\/tutorials\/core\/mat-mask-operations\/mat-mask-operations.html#maskoperationsfilter\">the OpenCV tutorial<\/a> and uses a sharpen filter. It also uses the <strong>CVImage<\/strong> class in the<a href=\"http:\/\/www.magicandlove.com\/blog\/2015\/06\/21\/opencv-and-processing-10\/\"> last post<\/a>.<\/p>\n<p>Here is a screen shot of the Processing window.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/06\/OpenCV-00320.png\" alt=\"\" title=\"OpenCV-00320\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-1512\" srcset=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/06\/OpenCV-00320.png 640w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/06\/OpenCV-00320-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><br \/>\n<!--more--><\/p>\n<pre lang=\"java\">\r\nimport processing.video.*;\r\n\r\nimport org.opencv.imgproc.Imgproc;\r\nimport org.opencv.core.CvType;\r\n\r\nCapture cap;\r\nCVImage img;\r\nPShape shp;\r\nMat kernel; \/\/ Convolution kernel\r\n\r\nvoid setup() {\r\n  size(640, 480, P3D);\r\n  println(Core.VERSION);\r\n  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);\r\n  cap = new Capture(this, width, height);\r\n  cap.start();\r\n  img = new CVImage(width, height);\r\n  shp = createShape(RECT, 0, 0, width, height);\r\n  kernel = new Mat(3, 3, CvType.CV_32FC1);\r\n  kernel.put(0, 0, 0);\r\n  kernel.put(0, 1, -1);\r\n  kernel.put(0, 2, 0);\r\n  kernel.put(1, 0, -1);\r\n  kernel.put(1, 1, 5);\r\n  kernel.put(1, 2, -1);\r\n  kernel.put(2, 0, 0);\r\n  kernel.put(2, 1, -1);\r\n  kernel.put(2, 2, 0);\r\n}\r\n\r\nvoid draw() {\r\n  background(0);\r\n  arrayCopy(cap.pixels, img.pixels);\r\n  img.toCV(); \/\/ load the pixels to Mat\r\n  \r\n  Mat src = img.getBGR();\r\n  Mat dst = new Mat(src.size(), src.type());\r\n  Imgproc.filter2D(src, dst, src.depth(), kernel);\r\n  \r\n  img.fromCV(dst); \/\/ update the img with Mat dst\r\n  shp.setTexture(img);\r\n  shape(shp, 0, 0);\r\n  text(\"Frame rate: \" + nf(round(frameRate), 2), 10, 20);\r\n  src.release();\r\n  dst.release();\r\n}\r\n\r\nvoid captureEvent(Capture c) {\r\n  c.read();\r\n  c.loadPixels();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this example, I demonstrate the use of the image processing module (Imgproc) with the filter2D function. It is similar to the generic Photoshop filter where you can design the convolution matrix. The example references the OpenCV tutorial and uses a sharpen filter. It also uses the CVImage class in the last post. Here is [&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":[128,3,62],"class_list":["post-1511","post","type-post","status-publish","format-standard","hentry","category-research","category-software-2","tag-image-processing","tag-opencv","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1511","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=1511"}],"version-history":[{"count":3,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1511\/revisions"}],"predecessor-version":[{"id":1557,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1511\/revisions\/1557"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1511"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}