{"id":1740,"date":"2018-09-11T03:05:49","date_gmt":"2018-09-10T18:05:49","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=1740"},"modified":"2018-09-18T03:58:41","modified_gmt":"2018-09-17T18:58:41","slug":"blog96","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog96\/","title":{"rendered":"(96) OpenCV #1 : \u307e\u305a\u306f\u4f7f\u3063\u3066\u307f\u308b\u3002"},"content":{"rendered":"<h1 class=\"my_h\">1. \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>Python\u3067 OpenCV\u3092\u4f7f\u3063\u3066\u307f\u305f\u3044\u3002<\/p>\n<p><a href=\"https:\/\/opencv.org\/\" target=\"_blank\">OpenCV<\/a> \u306b\u3064\u3044\u3066\u306f\u8aac\u660e\u3059\u308b\u307e\u3067\u3082\u306a\u3044\u304c\u3001CV(Computer Vision)\u306e\u540d\u306e\u901a\u308a\u3001\u753b\u50cf\u8a8d\u8b58\u306a\u3069\u306b\u4ee3\u8868\u3055\u308c\u308b\u753b\u50cf\u30fb\u6620\u50cf\u51e6\u7406\u95a2\u9023\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3060\u3002<\/p>\n<p>C++\u3067\u306f\u3061\u3087\u304f\u3061\u3087\u304f\u4f7f\u3063\u3066\u3044\u308b\u304c\u3001Python\u3067\u306f\u4f7f\u3063\u305f\u3053\u3068\u304c\u306a\u3044\u3002<br \/>\n\u753b\u50cf\u30c7\u30fc\u30bf\u306f\uff12\u6b21\u5143\u3001\uff13\u6b21\u5143\u914d\u5217\u306a\u306e\u3067\u3001\u914d\u5217\u64cd\u4f5c\u3092\u7c21\u6f54\u306b\u66f8\u3051\u308b Python\u3060\u3068\u753b\u50cf\u30c7\u30fc\u30bf\u3092\u6271\u3044\u6613\u3044\u306f\u305a\u3002<\/p>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b<\/h1>\n<h3 class=\"my_h\">(0) \u4e8b\u524d\u6e96\u5099<\/h3>\n<p>\u3053\u3053\u3067\u306f anaconda\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f Python3 \u74b0\u5883\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<br \/>\npip\u7b49\u3001anaconda\u914d\u4e0b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u8d77\u52d5\u3059\u308b\u3088\u3046\u306b\u30d1\u30b9\u3092\u901a\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nexport PATH=~\/anaconda3\/bin\/:$PATH\r\n<\/pre>\n<p><a href=\"https:\/\/www.dogrow.net\/python\/blog47\/\" target=\"_blank\">\u203banaconda\u306e\u5165\u308c\u65b9\u306f\u3053\u3061\u3089\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/a><\/p>\n<h3 class=\"my_h\">(1) OpenCV\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>\u5165\u9580\u7de8\u306a\u306e\u3067\u3001\u30bd\u30fc\u30b9\u304b\u3089\u30b3\u30f3\u30d1\u30a4\u30eb\u3067\u306f\u306a\u304f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u3057\u3066\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u7269\u3092\u4f7f\u3046\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# pip\u304c\u5165\u3063\u3066\u3044\u308b\u304b\uff1f\r\npython3 -m pip -V\r\n\r\n# Case1 : \u306a\u3051\u308c\u3070\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\nwget https:\/\/bootstrap.pypa.io\/get-pip.py\r\npython3 get-pip.py\r\nrm get-pip.py\r\n\r\n# Case2 : \u3042\u3063\u3066\u3082\u66f4\u65b0\u3057\u3066\u304a\u304f\u3002\r\npip install -U pip\r\n\r\n# OpenCV\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\npip install opencv-python\r\n\r\n# msgpack\u304c\u53e4\u3044\u3068\u6012\u3089\u308c\u305f\u306e\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\npip install --upgrade msgpack\r\n\r\n# \u3064\u3044\u3067\u306b PIL\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3002\r\npip install pillow\r\n<\/pre>\n<h3 class=\"my_h\">(2) \u30ab\u30e9\u30fc\u753b\u50cf\u3092\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u3059\u308b\u3002<\/h3>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport cv2\r\n\r\n# \u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u51fa\u3059\u3002\r\nimg = cv2.imread(&quot;pic.jpg&quot;)\r\n\r\n# \u5e73\u5747\u5024\u3092\u6c42\u3081\u308b\u3002\r\nimgG = img.mean(axis=2)\r\n\r\n# \u8868\u793a\r\nfrom PIL import Image\r\nimgP = Image.fromarray(imgG) # numpy\u914d\u5217\u304b\u3089\u5909\u63db\r\nimgP.show()\r\n<\/pre>\n<p>\u3067\u304d\u305f\uff01<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/003.jpg\" alt=\"\" \/><\/p>\n<p>\u3067\u3082&#8230;<br \/>\n\u3053\u308c\u3067\u306f\u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u51fa\u3057\u306b OpenCV\u3092\u4f7f\u3063\u3066\u3044\u308b\u3060\u3051\u3067\u5b9d\u306e\u6301\u3061\u8150\u308c\u3060\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u5ea6\u306f OpenCV\u3067\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u3059\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport cv2\r\n\r\n# \u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u51fa\u3059\u3002\r\nimg = cv2.imread(&quot;pic.jpg&quot;)\r\n\r\n# \u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u3059\u308b\u3002\r\nimgG = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\r\n\r\n# \u8868\u793a\r\nfrom PIL import Image\r\nimgP = Image.fromarray(imgG) # numpy\u914d\u5217\u304b\u3089\u5909\u63db\r\nimgP.show()\r\n<\/pre>\n<p>\u3067\u304d\u305f\uff01<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/004.jpg\" alt=\"\" \/><\/p>\n<h1 class=\"my_h\">3. \u304a\u307e\u3051<\/h1>\n<h3 class=\"my_h\">(1) \u753b\u50cf\u306e\u8868\u793a\u65b9\u6cd5\uff08cv2\u3092\u4f7f\u3046\u5834\u5408\uff09<\/h3>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u4f8b\u3067\u306f PIL\u3092\u4f7f\u3063\u3066\u8868\u793a\u3057\u3066\u3044\u308b\u3002<br \/>\nOpenCV\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u4f8b\u3067\u306f\u3001cv2\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport cv2\r\nimg = cv2.imread('image.jpg')\r\ncv2.namedWindow('image', cv2.WINDOW_AUTOSIZE)\r\ncv2.imshow('image', img)\r\ncv2.waitKey()\r\ncv2.destroyAllWindows()\r\n<\/pre>\n<p>Window\u306e\u30bf\u30a4\u30c8\u30eb\u30d0\u30fc\u306b\u4efb\u610f\u306e\u6587\u5b57\u5217\u3092\u66f8\u3051\u308b\u306e\u3067\u3053\u3061\u3089\u306e\u65b9\u304c\u3088\u3044\u304b\uff1f<br \/>\n\u3067\u3082\u3001\u6700\u5f8c\u306b waitkey() \u306a\u308b\u4e00\u884c\u3092\u5b9f\u884c\u3057\u306a\u3044\u3068\u8868\u793a\u3055\u308c\u306a\u3044\u306e\u306f\u306a\u305c\uff1f<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2018\/09\/100.png\" alt=\"\" \/><\/p>\n<p>\u8a73\u7d30\u306f\u3053\u3061\u3089\u306e\u516c\u5f0f\u30da\u30fc\u30b8\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<br \/>\n<a href=\"https:\/\/docs.opencv.org\/master\/d5\/d98\/tutorial_mat_operations.html\" target=\"_blank\">Operations with images <\/a><\/p>\n<h1 class=\"my_h\">4. \u6240\u611f<\/h1>\n<p>\u3068\u308a\u3042\u3048\u305a Python\u3067 OpenCV\u521d\u4f53\u9a13\u306a\u306e\u3067\u3001\u3053\u308c\u3050\u3089\u3044\u306b\u3057\u3066\u304a\u3053\u3046\u3002<br \/>\n\u7d9a\u304f\u304b\u306a&#8230;<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>1. \u3084\u308a\u305f\u3044\u3053\u3068 Python\u3067 OpenCV\u3092\u4f7f\u3063\u3066\u307f\u305f\u3044\u3002 OpenCV \u306b\u3064\u3044\u3066\u306f\u8aac\u660e\u3059\u308b\u307e\u3067\u3082\u306a\u3044\u304c\u3001CV(Computer Vision)\u306e\u540d\u306e\u901a\u308a\u3001\u753b\u50cf\u8a8d\u8b58\u306a\u3069\u306b\u4ee3\u8868\u3055\u308c\u308b\u753b\u50cf\u30fb\u6620\u50cf\u51e6\u7406\u95a2\u9023\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3060\u3002\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog96\/\">\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":[10,36,16],"tags":[],"class_list":["post-1740","post","type-post","status-publish","format-standard","hentry","category-numpy","category-opencv","category-pil"],"views":2596,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1740","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=1740"}],"version-history":[{"count":34,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1740\/revisions"}],"predecessor-version":[{"id":1877,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1740\/revisions\/1877"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=1740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=1740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=1740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}