{"id":1585,"date":"2015-07-18T22:25:42","date_gmt":"2015-07-18T14:25:42","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1585"},"modified":"2015-07-18T22:25:42","modified_gmt":"2015-07-18T14:25:42","slug":"opencv-and-processing-17","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2015\/07\/18\/opencv-and-processing-17\/","title":{"rendered":"OpenCV and Processing 17"},"content":{"rendered":"<p>The example explores the Hough Circle detection in the <strong>Imgproc<\/strong> module. It starts with a greyscale copy of the live webcam image with an application of a blur filter, in this case, a <strong>medianBlur<\/strong>.<\/p>\n<div id='gallery-1' class='gallery galleryid-1585 gallery-columns-3 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/07\/photo0676.png'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/07\/photo0676-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" \/><\/a>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/07\/photo2503.png'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/07\/photo2503-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" \/><\/a>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/07\/photo2923.png'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2015\/07\/photo2923-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" \/><\/a>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n\n<p><!--more--><br \/>\nIt also makes use of the CVImage class for the conversion between PImage and Mat in OpenCV.<\/p>\n<pre lang=\"java\">\r\nimport processing.video.*;\r\n\r\nimport org.opencv.video.Video;\r\nimport org.opencv.core.Mat;\r\nimport org.opencv.imgproc.Imgproc;\r\n\r\nCapture cap;\r\nCVImage img;\r\n\r\nvoid setup() {\r\n  size(640, 480, P3D);\r\n  background(0);\r\n  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);\r\n  cap = new Capture(this, width, height);\r\n  cap.start();\r\n  cap.read();\r\n  img = new CVImage(width, height);\r\n  smooth();\r\n}\r\n\r\nvoid draw() {\r\n  img.copy(cap, 0, 0, cap.width, cap.height, 0, 0, img.width, img.height);\r\n  img.toCV();\r\n\r\n  Mat grey = img.getGrey();\r\n  Mat dst = new Mat(grey.size(), grey.type());\r\n  Imgproc.medianBlur(grey, dst, 5);\r\n  Mat circles = new Mat();\r\n  Imgproc.HoughCircles(dst, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 10, 100, 30, 10, 40);\r\n\r\n  background(0);\r\n  image(img, 0, 0);\r\n\r\n  fill(255, 200, 0);\r\n  if (circles.rows()>0) {\r\n    for (int i=0; i<circles.cols(); i++) {\r\n      double [] v = circles.get(0, i);\r\n      float x = (float)v[0];\r\n      float y = (float)v[1];\r\n      float r = (float)v[2];\r\n      ellipse(x, y, r*2, r*2);\r\n    }\r\n  }\r\n\r\n  fill(0);\r\n  noStroke();\r\n  rect(0, 0, 110, 30);\r\n  fill(255);\r\n  text(\"Frame rate: \" + nf(round(frameRate), 2), 10, 20, 0);\r\n  grey.release();\r\n  dst.release();\r\n  circles.release();\r\n}\r\n\r\nvoid captureEvent(Capture _c) {\r\n  _c.read();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The example explores the Hough Circle detection in the Imgproc module. It starts with a greyscale copy of the live webcam image with an application of a blur filter, in this case, a medianBlur.<\/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":[136,3,62],"class_list":["post-1585","post","type-post","status-publish","format-standard","hentry","category-research","category-software-2","tag-hough-circle","tag-opencv","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1585","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=1585"}],"version-history":[{"count":1,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1585\/revisions"}],"predecessor-version":[{"id":1589,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1585\/revisions\/1589"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}