{"id":6624,"date":"2019-06-07T20:19:31","date_gmt":"2019-06-07T11:19:31","guid":{"rendered":"https:\/\/itport.cloud\/?p=6624"},"modified":"2019-06-18T21:24:43","modified_gmt":"2019-06-18T12:24:43","slug":"post-6624","status":"publish","type":"post","link":"https:\/\/itport.cloud\/?p=6624","title":{"rendered":"(\u7b2c2\u56de)Python + OpenCV \u3067\u904a\u3093\u3067\u307f\u308b(\u57fa\u672c\u753b\u50cf\u51e6\u7406\u7de8)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"e79baee6aca1-1\">\u76ee\u6b21<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><a href=\"#p2-1\">\u306f\u3058\u3081\u306b<\/a><\/strong><\/li><li><strong><a href=\"#p2-2\">\u7d50\u679c\u51fa\u529b\u306b\u3064\u3044\u3066<\/a><\/strong><\/li><li><strong><a href=\"#p2-3\">\u57fa\u672c\u7684\u306a\u753b\u50cf\u51e6\u7406<\/a><\/strong><\/li><li><strong><a href=\"#p2-4\">\u304a\u308f\u308a\u306b<\/a><\/strong><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"p2-1\"><strong>\u306f\u3058\u3081\u306b<\/strong><\/h2>\n\n\n\n<p> \u524d\u56de\u306f\u3001Python(Anaconda)\u3068OpenCV\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u958b\u767a\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u307e\u3057\u305f\u3002<br>&nbsp;\u4eca\u56de\u306f\u3001\u5b9f\u969b\u306bOpenCV\u3092\u5229\u7528\u3057\u3066\u753b\u50cf\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"p2-2\"><strong>\u7d50\u679c\u51fa\u529b\u306b\u3064\u3044\u3066<\/strong><\/h2>\n\n\n\n<p>&nbsp;\u753b\u50cf\u51e6\u7406\u3092\u884c\u3044\u3001\u51e6\u7406\u5f8c\u306e\u753b\u50cf\u8868\u793a\u306f\u4e3b\u306b\u4ee5\u4e0b\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002 <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u30d5\u30a1\u30a4\u30eb\u51fa\u529b<\/li><li> \u753b\u9762\u51fa\u529b<\/li><li> Jupyter Notebook\u3092\u5229\u7528\u3057\u3001Notebbook\u4e0a\u3067\u30a4\u30f3\u30e9\u30a4\u30f3\u8868\u793a<\/li><\/ul>\n\n\n\n<p>&nbsp;\u305d\u308c\u305e\u308c\u306b\u3064\u3044\u3066\u3001\u5229\u7528\u65b9\u6cd5\u3092\u4e0b\u8a18\u3057\u307e\u3059\u3002 <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e38395e382a1e382a4e383abe587bae58a9b-2\"><strong>\u30d5\u30a1\u30a4\u30eb\u51fa\u529b<\/strong><\/h3>\n\n\n\n<p>&nbsp;cv2.imwrite\u30e1\u30bd\u30c3\u30c9\u306b\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u51fa\u529b\u3057\u3001\u7d50\u679c\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport cv2\nimg = cv2.imread('input.jpg')\ncv2.imwrite('output.jpg',img)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"e794bbe99da2e587bae58a9b-3\"><strong>\u753b\u9762\u51fa\u529b<\/strong><\/h3>\n\n\n\n<p>&nbsp;cv2.imshow\u30e1\u30bd\u30c3\u30c9\u306b\u3066\u753b\u50cf\u8868\u793a\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u8868\u793a\u3057\u307e\u3059\u3002<br>&nbsp;imshow\u30e1\u30bd\u30c3\u30c9\u306e\u307f\u3060\u3068\u8868\u793a\u3059\u308b\u3068\u540c\u6642\u306b\u7d42\u4e86\u3057\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u30ad\u30fc\u5165\u529b\u306b\u3088\u308b\u5f85\u6a5f\u51e6\u7406\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; highlight: [4]; title: ; notranslate\" title=\"\">\nimport cv2\nimg = cv2.imread('input.jpg')\ncv2.imshow('Window Name',img)\ncv2.waitKey(0) #\u30ad\u30fc\u5165\u529b\u5f85\u3061\u306b\u3057\u3066\u5f85\u6a5f(0\u306f\u7121\u671f\u9650\u5f85\u6a5f)\ncv2.destroyAllWindows() #\u8868\u793a\u3057\u305f\u753b\u50cf\u8868\u793a\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u7834\u68c4\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"jupyternotebooke381aee588a9e794a8-4\"><strong>JupyterNotebook\u306e\u5229\u7528<\/strong><\/h3>\n\n\n\n<p>Jupyter Notebook\u3068\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3001\u5b9f\u884c\u7d50\u679c\u3092\u8a18\u9332\u51fa\u6765\u308b\u30c4\u30fc\u30eb\u3067\u3059\u3002<br>Anaconda\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3068\u540c\u68b1\u3055\u308c\u3066\u304a\u308a\u3001Python\u306b\u9650\u3089\u305a\u591a\u7a2e\u306e\u8a00\u8a9e\u3092\u4f7f\u7528\u51fa\u6765\u307e\u3059\u3002<br><div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"https:\/\/jupyter.org\" data-lkc-id=\"28\" target=\"_blank\" rel=\"external noopener\"><div class=\"lkc-card\"><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"\/\/itport.cloud\/wp-content\/uploads\/pz-linkcard\/cache\/c17930d9b30bcc2c4f871fc42200cfbe593e127fbdc695c25f11bd147c442bc6.jpeg\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">Project Jupyter<\/div><div class=\"lkc-url\" title=\"https:\/\/jupyter.org\">https:\/\/jupyter.org<\/div><div class=\"lkc-excerpt\">The Jupyter Notebook is a web-based interactive computing platform. The notebook combines live code, equations, narrative text, visualizations, interactive dashboards and other media.<\/div><div class=\"lkc-more\">more<\/div><\/div><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=jupyter.org\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">jupyter.org<\/div><div class=\"lkc-share\"> <div class=\"lkc-sns-hb\">229 Users<\/div><\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div><\/p>\n\n\n\n<p>JupyterNotebook\u3067\u753b\u50cf\u3092\u30a4\u30f3\u30e9\u30a4\u30f3\u8868\u793a\u3059\u308b\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e2\u901a\u308a\u304c\u3042\u308a\u307e\u3059\u3002 <\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"matplotlibe38292e588a9e794a8-5\"> matplotlib\u3092\u5229\u7528 <\/h4>\n\n\n\n<p> matplotlib\u3068\u306f\u30b0\u30e9\u30d5\u3092\u4f5c\u6210\u30fb\u8868\u793a\u3059\u308bPython\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\nimg = cv2.imread('input.jpg')\nplt.imshow(img)\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"ipython-displaye383a2e382b8e383a5e383bce383abe38292e588a9e794a8-6\"> IPython.display\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5229\u7528 <\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport cv2\nfrom IPython.display import Image\nImage('input.jpg')\n<\/pre><\/div>\n\n\n<p> \u4eca\u56de\u306fOpenCV\u3067\u3069\u306e\u3088\u3046\u306a\u753b\u50cf\u51e6\u7406\u304c\u51fa\u6765\u308b\u306e\u304b\u3092\u8a66\u3059\u305f\u3081\u3001\u624b\u8efd\u306aJupyter Notebook\u4e0a\u3067matplotlib\u3092\u5229\u7528\u3057\u305f\u65b9\u6cd5\u3067\u8868\u793a\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"p2-3\"><strong>\u57fa\u672c\u7684\u306a\u753b\u50cf\u51e6\u7406<\/strong><\/h2>\n\n\n\n<p> OpenCV\u3067\u51fa\u6765\u308b\u57fa\u672c\u7684\u306a\u753b\u50cf\u51e6\u7406\u3092\u8a66\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br>&nbsp;\u4eca\u56de\u3001\u5229\u7528\u3057\u305f\u753b\u50cf\u306f\u4ee5\u4e0b\u306e\u30dd\u30b9\u30c8\u306e\u5199\u771f\u3067\u3059\u3002<br>\uff08\u203b\u8a18\u4e8b\u6295\u7a3f\u306e\u305f\u3081\u3001\u5b9f\u969b\u306e\u753b\u50cf\u3088\u308a\u3082\u7e2e\u5c0f\u3055\u308c\u3066\u304a\u308a\u307e\u3059\u3002\u753b\u50cf\u51e6\u7406\u5f8c\u306e\u7d50\u679c\u3082\u7e2e\u5c0f\u3057\u3066\u8868\u793a\u3057\u3066\u304a\u308a\u307e\u3059\u3002\uff09 <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/input-225x300.jpg\" alt=\"\" class=\"wp-image-6628\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/input-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/input-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/input.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption>\u30a4\u30f3\u30d7\u30c3\u30c8\u753b\u50cf<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e382b0e383ace383bce382b9e382b1e383bce383ab-7\"><strong>\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb<\/strong><\/h3>\n\n\n\n<p> \u307e\u305a\u306f\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u8868\u793a\u3067\u3059\u3002\u3044\u308f\u3086\u308b\u767d\u9ed2\u5199\u771f\u3067\u3059\u3002<br>\u660e\u6697\u306e\u307f\u306e\u60c5\u5831\u306b\u306a\u308b\u306e\u3067\u753b\u50cf\u51e6\u7406\u3067\u306f\u3088\u304f\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\ngry_img = cv2.imread('input.jpg', 0) #imread\u306e\u7b2c2\u5f15\u6570\u306b0\u3092\u6307\u5b9a\u3059\u308b\u3068\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3067\u8aad\u307f\u8fbc\u307f\n\nplt.gray() #matplotlib\u3067\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3067\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u6307\u5b9a\nplt.imshow(gry_img)\n<\/pre><\/div>\n\n\n<p> <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output1-225x300.jpg\" alt=\"\" class=\"wp-image-6630\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output1-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output1-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output1.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption>\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2e580a4e58c96-8\"><strong>2\u5024\u5316<\/strong><\/h3>\n\n\n\n<p> \u767d\u3068\u9ed2\u306e2\u8272\u306e\u307f\u3067\u69cb\u6210\u3055\u308c\u308b\u753b\u50cf\u306b\u5909\u63db\u3057\u307e\u3059\u3002<br>cv2.threshold\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u753b\u50cf\u304b\u30892\u5024\u5316\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; highlight: [6]; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\ngry_img = cv2.imread('input.jpg', 0) #\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3067\u8aad\u307f\u8fbc\u307f\nret, threshold_img = cv2.threshold(gry_img, 127, 255, cv2.THRESH_OTSU) #\u7b2c2,3\u5f15\u6570\u306f\u95be\u5024\u3001\u7b2c4\u5f15\u6570\u306f\u624b\u6cd5\u306e\u30d5\u30e9\u30b0\n\nplt.gray() #matplotlib\u3067\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3067\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u6307\u5b9a\nplt.imshow(threshold_img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output2-225x300.jpg\" alt=\"\" class=\"wp-image-6632\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output2-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output2-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output2.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption>\uff12\u5024\u5316<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e38388e383aae3839fe383b3e382b0-9\"><strong>\u30c8\u30ea\u30df\u30f3\u30b0<\/strong><\/h2>\n\n\n\n<p> \u753b\u50cf\u306e\u5207\u308a\u629c\u304d\u3092\u884c\u3044\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg')\nheight = img.shape&#x5B;0] #\u9ad8\u3055\nwidth = img.shape&#x5B;1] #\u5e45\ntrim_img = img&#x5B;100:height, 100:width] #\u9ad8\u3055(\u4e0a)\u30fb\u5e45(\u5de6)\u3092100pixel\u305a\u3064\u9664\u304f\n\ntrim_img = cv2.cvtColor(trim_img, cv2.COLOR_RGB2BGR) #matplotlib\u3067\u8868\u793a\u3059\u308b\u5834\u5408\u306fRGB\u304b\u3089BGR\u306b\u5909\u63db\nplt.imshow(trim_img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"223\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output3-223x300.jpg\" alt=\"\" class=\"wp-image-6633\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output3-223x300.jpg 223w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output3-238x320.jpg 238w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output3.jpg 475w\" sizes=\"auto, (max-width: 223px) 100vw, 223px\" \/><figcaption>\u30c8\u30ea\u30df\u30f3\u30b0<br>\uff08\u82e5\u5e72\u308f\u304b\u308a\u3065\u3089\u3044\u3067\u3059\u304c\u3001\u5de6\u4e0a\u306e\u30cf\u30a4\u30d3\u30b9\u30ab\u30b9\u304c\u7121\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u3002\uff09<br><\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e383aae382b5e382a4e382ba-10\"><strong>\u30ea\u30b5\u30a4\u30ba<\/strong><\/h3>\n\n\n\n<p> \u753b\u50cf\u306e\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3057\u307e\u3059\u3002\uff08\u7e2e\u5c0f\u3001\u62e1\u5927\uff09 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg')\nheight = img.shape&#x5B;0] #\u9ad8\u3055\nwidth = img.shape&#x5B;1] #\u5e45\nresize_img = cv2.resize(img, (int(width*0.5), int(height*0.5))) #\u30b5\u30a4\u30ba\u3092\u00d70.5\u3067\u7e2e\u5c0f\n\nresize_img = cv2.cvtColor(resize_img, cv2.COLOR_RGB2BGR) #matplotlib\u3067\u8868\u793a\u3059\u308b\u5834\u5408\u306fRGB\u304b\u3089BGR\u306b\u5909\u63db\nplt.imshow(resize_img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output4-225x300.jpg\" alt=\"\" class=\"wp-image-6634\" width=\"169\" height=\"225\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output4-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output4-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output4.jpg 480w\" sizes=\"auto, (max-width: 169px) 100vw, 169px\" \/><figcaption>\u30ea\u30b5\u30a4\u30ba<br><\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e5b084e5bdb1e5a489e68f9b-11\"><strong>\u5c04\u5f71\u5909\u63db<\/strong><\/h3>\n\n\n\n<p> \u3042\u308b\u5e73\u9762\u3092\u5225\u306e\u5e73\u9762\u306b\u5c04\u5f71\u3059\u308b\u5909\u63db\u3092\u884c\u3044\u307e\u3059\u3002<br>&nbsp;\u3088\u304f\u66f8\u985e\u306a\u3069\u3092\u30ab\u30e1\u30e9\u3067\u64ae\u5f71\u3057\u3066\u3001\u6b63\u9762\u304b\u3089\u306e\u5e73\u9762\u306b\u5909\u63db\u3057\u3066\u3044\u308b\u306e\u3092\u3088\u304f\u898b\u304b\u3051\u307e\u3059\u306d\u3002<br>&nbsp;\u3053\u3053\u3067\u306f\u3001numpy\u3068\u3044\u3046Python\u306e\u6570\u5024\u8a08\u7b97\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; highlight: [3]; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg')\nheight, width, ch = img.shape #\u753b\u50cf\u306e\u5927\u304d\u3055\u3092\u53d6\u5f97\n\n#points1\u306e\u5ea7\u6a19\u304b\u3089points2\u306e\u5ea7\u6a19\u306b\u5909\u63db\u3059\u308b\u305f\u3081\u3001\u5ea7\u6a19\u3092\u6307\u5b9a\npoints1 = np.float32(&#x5B;&#x5B;320,236],&#x5B;1104,402],&#x5B;12,332],&#x5B;1053,640]])\npoints2 = np.float32(&#x5B;&#x5B;0,0],&#x5B;1250,0],&#x5B;0,500],&#x5B;1250,500]])\n\n#\u900f\u8996\u5909\u63db\u306e\u884c\u5217\u3092\u6c42\u3081\u308b\nM = cv2.getPerspectiveTransform(points1, points2)\n\n#\u753b\u50cf\u3092\u5909\u63db\u3059\u308b\ndst = cv2.warpPerspective(img, M, (1250,500))\n\ndst = cv2.cvtColor(dst, cv2.COLOR_RGB2BGR) #matplotlib\u3067\u8868\u793a\u3059\u308b\u5834\u5408\u306fRGB\u304b\u3089BGR\u306b\u5909\u63db\nplt.imshow(dst)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"120\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output5-300x120.jpg\" alt=\"\" class=\"wp-image-6635\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output5-300x120.jpg 300w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output5-450x179.jpg 450w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output5.jpg 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption>\u5c04\u5f71\u5909\u63db<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e382a8e38383e382b8e6a49ce587ba-12\"><strong>\u30a8\u30c3\u30b8\u691c\u51fa<\/strong><\/h3>\n\n\n\n<p> \u753b\u50cf\u306e\u8f2a\u90ed\u3092\u691c\u51fa\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg', 0) #\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u3067\u8aad\u307f\u8fbc\u307f\ncanny_img = cv2.Canny(img, 50, 110) #\u7b2c2,3\u5f15\u6570\u306f\u95be\u5024\n\nplt.gray()\nplt.imshow(canny_img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output6-225x300.jpg\" alt=\"\" class=\"wp-image-6636\" width=\"226\" height=\"302\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output6-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output6-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output6.jpg 480w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><figcaption>\u30a8\u30c3\u30b8\u691c\u51fa<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e381bce3818be38197-13\">\u307c\u304b\u3057<\/h3>\n\n\n\n<p> \u753b\u50cf\u3092\u5e73\u6ed1\u5316\u3055\u305b\u308b\u30ac\u30a6\u30b7\u30a2\u30f3\u30d5\u30a3\u30eb\u30bf\u3092\u7528\u3044\u3066\u3001\u753b\u50cf\u306b\u307c\u304b\u3057\u51e6\u7406\u3092\u3044\u308c\u307e\u3059\u3002<br>&nbsp;\u30ac\u30a6\u30b7\u30a2\u30f3\u30d5\u30a3\u30eb\u30bf\u306b\u306f\u30ab\u30fc\u30cd\u30eb\u30b5\u30a4\u30ba\u304a\u3088\u3073\u6a19\u6e96\u504f\u5dee\u3092\u8abf\u6574\u3057\u3066\u3001\u307c\u304b\u3057\u5177\u5408\u3092\u8abf\u6574\u3057\u307e\u3059\u3002<br>&nbsp;\u3069\u3061\u3089\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3082\u6570\u5024\u304c\u5927\u304d\u304f\u306a\u308b\u3068\u307c\u304b\u3057\u5177\u5408\u304c\u5f37\u304f\u306a\u308a\u307e\u3059\u3002<br>&nbsp;\u6a19\u6e96\u504f\u5dee\u306b0\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u30ab\u30fc\u30cd\u30eb\u30b5\u30a4\u30ba(\u6b63\u306e\u5947\u6570\u3092\u6307\u5b9a)\u304b\u3089\u81ea\u52d5\u8a08\u7b97\u3055\u308c\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg')\ngauss_img = cv2.GaussianBlur(img, (15,15), 0) #\u7b2c2\u5f15\u6570\u306f\u30ab\u30fc\u30cd\u30eb\u3001\u7b2c3\u5f15\u6570\u306f\u6a19\u6e96\u504f\u5dee\n\ngauss_img = cv2.cvtColor(gauss_img, cv2.COLOR_RGB2BGR) #matplotlib\u3067\u8868\u793a\u3059\u308b\u5834\u5408\u306fRGB\u304b\u3089BGR\u306b\u5909\u63db\nplt.imshow(gauss_img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output8-225x300.jpg\" alt=\"\" class=\"wp-image-6637\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output8-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output8-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output8.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption>\u307c\u304b\u3057<br>\uff08\u308f\u304b\u308a\u306b\u304f\u3044\u3067\u3059\u304c\u307c\u3051\u3066\u307e\u3059\uff09<br><\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e383a2e382b6e382a4e382afe587a6e79086-14\"><strong>\u30e2\u30b6\u30a4\u30af\u51e6\u7406<\/strong><\/h3>\n\n\n\n<p> \u753b\u50cf\u306e\u30e2\u30b6\u30a4\u30af\u51e6\u7406\u306f\u3001\u753b\u50cf\u3092\u4e00\u65e6\u7e2e\u5c0f\u3057\u3001\u5143\u306e\u5927\u304d\u3055\u306b\u62e1\u5927\u3059\u308b\u3053\u3068\u3067\u30e2\u30b6\u30a4\u30af\u51e6\u7406\u3092\u65bd\u3059\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br>\uff08\u5b9f\u969b\u306f\u7e2e\u5c0f\u6642\u306b\u753b\u7d20\u306e\u5e73\u5747\u5316\u7b49\u306e\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u304c\u767a\u751f\u3057\u3066\u3044\u308b\uff09 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg')\norgsize = img.shape&#x5B;:2]&#x5B;::-1]\n\nimg = cv2.resize(img, (int(orgsize&#x5B;0]\/20), int(orgsize&#x5B;1]\/20))) #\u753b\u50cf\u30921\/20\u306b\u7e2e\u5c0f\nimg = cv2.resize(img, orgsize) #\u753b\u50cf\u3092\u5143\u306e\u30b5\u30a4\u30ba\u306b\u62e1\u5927\n\nimg = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) #matplotlib\u3067\u8868\u793a\u3059\u308b\u5834\u5408\u306fRGB\u304b\u3089BGR\u306b\u5909\u63db\nplt.imshow(img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output9-225x300.jpg\" alt=\"\" class=\"wp-image-6638\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output9-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output9-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output9.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption>\u30e2\u30b6\u30a4\u30af\u51e6\u7406<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e7b79ae381aee68f8fe794bb-15\"><strong>\u7dda\u306e\u63cf\u753b<\/strong><\/h3>\n\n\n\n<p> line\u95a2\u6570\u3067\u753b\u50cf\u306b\u7dda\u3092\u8ffd\u52a0\u3057\u3066\u63cf\u753b\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; highlight: [9]; title: ; notranslate\" title=\"\">\n%matplotlib inline\nimport cv2\nimport matplotlib.pyplot as plt\n\nimg = cv2.imread('input.jpg')\nheight = img.shape&#x5B;0] #\u9ad8\u3055\nwidth = img.shape&#x5B;1] #\u5e45\n\nimg = cv2.line(img, (0,0), (width,height), (0,0,255), 5) #\u7b2c2\u5f15\u6570\u304c\u59cb\u70b9\u3001\u7b2c3\u5f15\u6570\u304c\u7d42\u70b9\u3001\u7b2c4\u5f15\u6570\u304c\u8272\u3001\u7b2c5\u5f15\u6570\u304c\u7dda\u306e\u592a\u3055\nimg = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) #matplotlib\u3067\u8868\u793a\u3059\u308b\u5834\u5408\u306fRGB\u304b\u3089BGR\u306b\u5909\u63db\nplt.imshow(img)\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"300\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output10-225x300.jpg\" alt=\"\" class=\"wp-image-6639\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output10-225x300.jpg 225w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output10-240x320.jpg 240w, https:\/\/itport.cloud\/wp-content\/uploads\/2019\/06\/output10.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption>\u7dda\u306e\u63cf\u753b<br>\uff08\u5de6\u4e0a\u304b\u3089\u53f3\u4e0b\u306b\u7dda\u3092\u5165\u308c\u3066\u3044\u307e\u3059\uff09<br><\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"p2-4\"><strong>\u304a\u308f\u308a\u306b<\/strong><\/h3>\n\n\n\n<p> \u4eca\u56de\u306fOpenCV\u3067\u3069\u306e\u3088\u3046\u306a\u753b\u50cf\u51e6\u7406\u304c\u51fa\u6765\u308b\u306e\u304b\u3001\u57fa\u672c\u7684\u306a\u51e6\u7406\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u305f\u3002<br>\u6b21\u56de\u306f\u3001\u9854\u691c\u51fa\u5206\u985e\u5668\u3092\u4f7f\u7528\u3057\u3066\u9854\u691c\u51fa\u3092\u3057\u3066\u904a\u3093\u3067\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"\u76ee\u6b21 \u306f\u3058\u3081\u306b\u7d50\u679c\u51fa\u529b\u306b\u3064\u3044\u3066\u57fa\u672c\u7684\u306a\u753b\u50cf\u51e6\u7406\u304a\u308f\u308a\u306b \u306f\u3058\u3081\u306b \u524d\u56de\u306f\u3001Python(Anaconda)\u3068OpenCV\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u958b\u767a\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u307e\u3057\u305f\u3002&nbsp;\u4eca\u56de\u306f\u3001\u5b9f\u969b\u306bOpenCV\u3092\u5229\u7528\u3057\u3066\u753b\u50cf\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002 \u7d50\u679c\u51fa\u529b\u306b\u3064\u3044\u3066 &nbsp;\u753b\u50cf\u51e6\u7406\u3092\u884c\u3044\u3001\u51e6\u7406\u5f8c\u306e\u753b\u50cf\u8868\u793a\u306f\u4e3b\u306b\u4ee5\u4e0b\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002 \u30d5\u30a1\u30a4\u30eb\u51fa\u529b \u753b\u9762\u51fa\u529b Jupyter Notebook\u3092\u5229\u7528\u3057\u3001Notebbook\u4e0a\u3067\u30a4\u30f3\u30e9\u30a4\u30f3\u8868\u793a &nbsp;\u305d\u308c\u305e\u308c\u306b\u3064\u3044\u3066\u3001\u5229\u7528\u65b9\u6cd5\u3092\u4e0b\u8a18\u3057\u307e\u3059\u3002 \u30d5\u30a1\u30a4\u30eb\u51fa\u529b &nbsp;cv2.imwrite\u30e1\u30bd\u30c3\u30c9\u306b\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u51fa\u529b\u3057\u3001\u7d50\u679c\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002 import cv2 img = cv&hellip;","protected":false},"author":6,"featured_media":6808,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[52],"class_list":{"0":"post-6624","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-opencv","8":"tag-season15"},"_links":{"self":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts\/6624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6624"}],"version-history":[{"count":21,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts\/6624\/revisions"}],"predecessor-version":[{"id":7657,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts\/6624\/revisions\/7657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/media\/6808"}],"wp:attachment":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}