{"id":1781,"date":"2018-09-17T00:14:58","date_gmt":"2018-09-16T15:14:58","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=1781"},"modified":"2018-09-17T00:20:10","modified_gmt":"2018-09-16T15:20:10","slug":"blog97","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog97\/","title":{"rendered":"(97) OpenCV #2 : Sobel\u30d5\u30a3\u30eb\u30bf\u30fc\u3067\u30a8\u30c3\u30b8\u62bd\u51fa"},"content":{"rendered":"<h1 class=\"my_h\">1. \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>Python\u3067 OpenCV\u306e\u7b2c 2\u56de\u76ee\u3001\u4eca\u56de\u306f OpenCV\u306e Sobel\u95a2\u6570\u3092\u4f7f\u3063\u3066\u753b\u50cf\u306e\u30a8\u30c3\u30b8\u62bd\u51fa\u3092\u3084\u308a\u305f\u3044\u3002<\/p>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b<\/h1>\n<p>\u307e\u305a\u306f\u5143\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u3001\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u3059\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport cv2\r\nfrom PIL import Image\r\n\r\n# \u5bfe\u8c61\u753b\u50cf\u3092\u30ed\u30fc\u30c9\r\nimg = cv2.imread(&quot;img001.jpg&quot;)\r\n\r\n# \u30ab\u30e9\u30fc\u753b\u50cf\u3092\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\r\nimgG = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\r\n\r\n# \u753b\u50cf\u3092\u8868\u793a\r\npilG = Image.fromarray(imgG)\r\npilG.show()\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/001.png\" alt=\"\" \/><\/p>\n<p>\u6b21\u306b X\u65b9\u5411\u306e\u52fe\u914d\u3092\u7b97\u51fa\u3059\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# X\u65b9\u5411\u306e\u52fe\u914d\u3092\u7b97\u51fa\r\nsx = cv2.Sobel(imgG, cv2.CV_64F, 1, 0, ksize=3)\r\n\r\n# \u753b\u50cf\u3092\u8868\u793a\r\npltSX = Image.fromarray(sx)\r\npltSX.show()\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/002.png\" alt=\"\" \/><\/p>\n<p>\u6b21\u306b Y\u65b9\u5411\u306e\u52fe\u914d\u3092\u7b97\u51fa\u3059\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# Y\u65b9\u5411\u306e\u52fe\u914d\u3092\u7b97\u51fa\r\nsy = cv2.Sobel(imgG, cv2.CV_64F, 0, 1, ksize=3)\r\n\r\n# \u753b\u50cf\u3092\u8868\u793a\r\npltSY = Image.fromarray(sy)\r\npltSY.show()\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/003.png\" alt=\"\" \/><\/p>\n<p>\u6700\u5f8c\u306b X,Y\u4e21\u65b9\u5411\u3092\u5408\u308f\u305b\u305f\u753b\u50cf\u306e\u52fe\u914d\u3092\u7b97\u51fa\u3059\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\n\r\n# \u4e21\u65b9\u5411\u5408\u308f\u305b\u305f\u52fe\u914d\u3092\u7b97\u51fa\r\ngrad = np.sqrt(sx ** 2 + sy ** 2)\r\n\r\n# \u753b\u50cf\u3092\u8868\u793a\r\npltGr = Image.fromarray(grad)\r\npltGr.show()\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/004.png\" alt=\"\" \/><\/p>\n<h1 class=\"my_h\">3. \u6240\u611f<\/h1>\n<p>\u3061\u3087\u3063\u3068\u30a8\u30c3\u30b8\u62bd\u51fa\u306b\u306f\u5411\u304b\u306a\u3044\u753b\u50cf\u3060\u3063\u305f\u304b\u306a&#8230;<\/p>\n<h1 class=\"my_h\">4. \u53c2\u8003<\/h1>\n<p>\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002 m(_ _)m<br \/>\n<a href=\"http:\/\/labs.eecs.tottori-u.ac.jp\/sd\/Member\/oyamada\/OpenCV\/html\/py_tutorials\/py_imgproc\/py_gradients\/py_gradients.html\" target=\"_blank\">http:\/\/labs.eecs.tottori-u.ac.jp\/sd\/Member\/oyamada\/OpenCV\/html\/py_tutorials\/py_imgproc\/py_gradients\/py_gradients.html<\/a><\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>1. \u3084\u308a\u305f\u3044\u3053\u3068 Python\u3067 OpenCV\u306e\u7b2c 2\u56de\u76ee\u3001\u4eca\u56de\u306f OpenCV\u306e Sobel\u95a2\u6570\u3092\u4f7f\u3063\u3066\u753b\u50cf\u306e\u30a8\u30c3\u30b8\u62bd\u51fa\u3092\u3084\u308a\u305f\u3044\u3002 2. \u3084\u3063\u3066\u307f\u308b \u307e\u305a\u306f\u5143\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u3001\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u3059\u308b\u3002 import cv\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog97\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1781","post","type-post","status-publish","format-standard","hentry","category-opencv"],"views":7159,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/comments?post=1781"}],"version-history":[{"count":3,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1781\/revisions"}],"predecessor-version":[{"id":1788,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1781\/revisions\/1788"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=1781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=1781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=1781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}