<?xml version="1.0" encoding="UTF-8" ?>
<rss version="0.91">
  <channel>
    <title>opencv python まとめ</title>
    <description>opencvのpythonコードをまとめるblog</description>
    <link>https://opencvpy.blog.shinobi.jp/</link>
    <language>ja</language>
    <copyright>Copyright (C) NINJATOOLS ALL RIGHTS RESERVED.</copyright>

    <item>
      <title>コーナー検出＆矩形を描く</title>
      <description>&lt;div class=&quot;highligh&quot; style=&quot;overflow: auto; word-wrap: normal;&quot;&gt;&lt;pre style=&quot;padding: .5em;&quot;&gt;&lt;span class=&quot;go&quot;&gt;・コーナーを検出し矩形を描く&lt;br /&gt;
&lt;br /&gt;
【Source Code】&lt;br /&gt;
&lt;br /&gt;
# coding: UTF-8&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;import cv2&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;import numpy as np&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;img = cv2.imread('Hough.png')&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;ret,thresh = cv2.threshold(gray,50,255,0)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;contours,hier = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;for cnt in contours:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;    if  cv2.contourArea(cnt)&amp;gt;5000:  # remove small areas like noise etc&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;        hull = cv2.convexHull(cnt)    # find the convex hull of contour&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;        hull = cv2.approxPolyDP(hull,0.1*cv2.arcLength(hull,True),True)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;        print(hull)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;        if len(hull)==4:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;            cv2.drawContours(img,[hull],0,(0,255,0),2)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;cv2.imshow('img',img)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;cv2.waitKey(0)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;go&quot;&gt;cv2.destroyAllWindows()&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: right; padding-right: 5px; font-size: small;&quot;&gt;&lt;a href=&quot;/&quot;&gt;&lt;strong&gt;&lt;span style=&quot;color: dimgray;&quot;&gt;syntax&lt;/span&gt;&lt;span style=&quot;color: steelblue;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: dimgray;&quot;&gt;html&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</description> 
      <link>https://opencvpy.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%82%B3%E3%83%BC%E3%83%8A%E3%83%BC%E6%A4%9C%E5%87%BA%EF%BC%86%E7%9F%A9%E5%BD%A2%E3%82%92%E6%8F%8F%E3%81%8F</link> 
    </item>

  </channel>
</rss>