{"id":1053,"date":"2009-08-18T19:35:25","date_gmt":"2009-08-18T10:35:25","guid":{"rendered":"https:\/\/www.iss.ai\/?p=1053"},"modified":"2009-08-18T19:35:25","modified_gmt":"2009-08-18T10:35:25","slug":"cvfindcontours%e3%81%ae%e7%b5%90%e6%9e%9c%e3%81%8b%e3%82%89%e5%ba%a7%e6%a8%99%e3%82%92%e5%be%97%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.iss.ai\/?p=1053","title":{"rendered":"cvFindContours\u306e\u7d50\u679c\u304b\u3089\u5ea7\u6a19\u3092\u5f97\u308b"},"content":{"rendered":"\t\t\t\t<p>OpenCV\u306ecvFindContours()\u306f\uff12\u5024\u753b\u50cf\u304b\u3089\u8f2a\u90ed\u3092\u53d6\u3063\u3066\u304d\u3066\u304f\u308c\u308b\u306e\u3060\u304c\uff0c<br \/>\n\t\t\t\t\u305d\u306e\u7d50\u679c\u304b\u3089\u8f2a\u90ed\u7dda\u306e\u30d4\u30af\u30bb\u30eb\u5ea7\u6a19\u3092\u3069\u3046\u3084\u3063\u3066\u53d6\u5f97\u3059\u308b\u306e\u304b\uff1f<br \/>\n\t\t\t\t\u3068\u3044\u3046\u306e\u3092\u8abf\u3079\u3066\uff0c\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u305f\uff0e<br \/>\n\t\t\t\t\uff08\u6700\u60aa\u300ccvDrawContours()\u3067\u63cf\u3044\u3066\u307f\u3066\u30d4\u30af\u30bb\u30eb\u306e\u8272\u3067\u5224\u65ad\u300d\u3068\u304b\u3044\u3046\u624b\u3082\u3042\u308b\u304c\u2026\uff09<\/p>\n\t\t\t\t<p>\u4eca\u56de\u306f\u8f2a\u90ed\u7dda\u3092\u69cb\u6210\u3059\u308b\u5168\u30d4\u30af\u30bb\u30eb\u306e\u5ea7\u6a19\u304c\u5fc5\u8981\u306a\u306e\u3067\u306f\u306a\u304f\u3066\uff0c\u8f2a\u90ed\u3092\u305d\u308c\u3068\u306a\u304f\u6298\u308c\u7dda\u8fd1\u4f3c\u3057\u305f\u7d50\u679c\u306e\u9802\u70b9\u7fa4\u306e\u5ea7\u6a19\u304f\u3089\u3044\u304c\u5f97\u3089\u308c\u308c\u3070\u3088\u3044\u72b6\u6cc1\u3060\u3063\u305f\u306e\u3067\uff0c<\/p>\n\t\t\t\t<ol>\n\t\t\t\t<li>cvFindContour()\u3067\u8f2a\u90ed\u3092\u691c\u51fa\u3057\u3066\u3082\u3089\u3046<\/li>\n\t\t\t\t<li>\u5404\u8f2a\u90ed\u3092\uff0ccvApproxPoly()\u3067\u6298\u308c\u7dda\u8fd1\u4f3c\u3059\u308b<\/li>\n\t\t\t\t<li>\u6298\u308c\u7dda\u306e\u9802\u70b9\u5ea7\u6a19\u3092\u3082\u3089\u3046<\/li>\n\t\t\t\t<\/ol>\n\t\t\t\t<p>\u3068\u3044\u3046\u624b\u9806\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u307f\u305f\uff0e\u3053\u306e\u624b\u9806\u3092\u307e\u3068\u3081\u305f\u95a2\u6570\u306f\u4ee5\u4e0b\u306e\u901a\u308a\uff0e(C++)<\/p>\n\t\t\t\t<pre>\r\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/cvFindContour -&gt; cvApproxPoly\r\n\/\/\u306e\u9806\u756a\u3067\u51e6\u7406\uff0e\u8f2a\u90ed\u3092\u591a\u89d2\u5f62\u8fd1\u4f3c\u3057\u305f\u969b\u306e\u9802\u70b9\u5ea7\u6a19\u7fa4\u3092\u5f97\u308b\uff0e\r\n\/\/\u203b\u5165\u529b\u753b\u50cfpSrc8U1C\u306f\uff0ccvFindContour\u306e\u4ed5\u69d8\u306b\u3088\u308a\u5909\u66f4\u3055\u308c\u308b\uff0e\r\n\/\/\t\u5acc\u306a\u3089\u30b3\u30d4\u30fc\u3092\u6e21\u3059\u3053\u3068\uff0e\r\ntypedef std::vector&lt; std::vector&lt;CvPoint&gt; &gt;\tType_ApproxContourContainer;\r\n\r\nbool GetApproxPolyContours(\tIplImage *pSrc8U1C,\t\/\/const\u3067\u306a\u3044\u5165\u529b\u753b\u50cf\r\n\t\t\t\t\t\t\tType_ApproxContourContainer *pDst,\t\/\/\u7d50\u679c\u53d7\u53d6\u5834\u6240\r\n\t\t\t\t\t\t\tdouble approx_accuracy_param\t\/\/cvApproxPoly\u306b\u6e21\u3059\u8fd1\u4f3c\u7cbe\u5ea6\u30d1\u30e9\u30e1\u30bf\r\n\t\t\t\t\t\t\t)\r\n{\r\n\t\/\/\u5f15\u6570\u30c1\u30a7\u30c3\u30af\r\n\tif( approx_accuracy_param &lt; 0 )return false;\r\n\tif(  pDst==NULL  ||  !CheckImgType( pSrc8U1C, IPL_DEPTH_8U, 1 )  )return false;\r\n\r\n\t\/\/cvFindContours\u3067Contour\u3092\u691c\u51fa\r\n\tCvMemStorage* storage = cvCreateMemStorage(0);\r\n\tCvSeq* contour = 0;\r\n\r\n\tint contour_count = cvFindContours( pSrc8U1C, storage, &amp;contour, sizeof(CvContour), CV_RETR_LIST , CV_CHAIN_APPROX_SIMPLE );\r\n\tif( contour_count &lt;= 0 )return false;\r\n\r\n\t\/\/\u5404Contour\u3092cvApproxPoly\u3067\u8fd1\u4f3c\u3057\u3066\uff0c\u7d50\u679c\u683c\u7d0d\u57df\u306b\u305d\u306e\u9802\u70b9\u5ea7\u6a19\u7fa4\u3092\u4fdd\u5b58\r\n\tpDst-&gt;resize( contour_count );\r\n\tType_ApproxContourContainer::iterator iDst = pDst-&gt;begin();\r\n\r\n\tfor( ; contour != 0; contour = contour-&gt;h_next )\r\n\t{\r\n\t\tCvSeq *approx = cvApproxPoly( contour, sizeof(CvContour), NULL, CV_POLY_APPROX_DP, approx_accuracy_param );\r\n\r\n\t\tiDst-&gt;resize( approx-&gt;total );\r\n\t\tfor( int i=0; i&lt;approx-&gt;total; i++ )\r\n\t\t{\r\n\t\t\tiDst-&gt;at(i) = *CV_GET_SEQ_ELEM( CvPoint, approx, i );\r\n\t\t}\r\n\t\tiDst++;\r\n\t}\r\n\r\n\t\/\/\u5f8c\u59cb\u672b\r\n\tcvReleaseMemStorage( &amp;storage );\r\n\treturn true;\r\n}\r\n<\/pre>\n\t\t\t\t<p>\uff08\u6700\u521d\u306e\u65b9\u306b\u3042\u308bCheckImgType(&#8230;)\u306f\uff0c\u6e21\u3055\u308c\u3066\u304d\u305f\u753b\u50cf\u304c8bit1ch\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u308b\u3082\u306e\uff0e\u7c21\u7d20\u3059\u304e\u308b\u306e\u3067\u30b3\u30fc\u30c9\u306f\u7701\u7565\uff0e\uff09<\/p>\n\t\t\t\t<p>cvFindContours()\u3067\u691c\u51fa\u3055\u308c\u305fcontour\u7fa4\u306e\u5de1\u56de\u306f\uff0c\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306ecvDrawContours()\u306e\u3068\u3053\u306b\u3042\u308b\u30b5\u30f3\u30d7\u30eb\u901a\u308a\u306b\uff0ch_next\u3067\u884c\u3046\uff08v_next\u306f\u3044\u3064\u4f7f\u3046\u306e\u3067\u3042\u308d\u3046\u304b\uff1f\uff09\uff0e<br \/>\n\t\t\t\t\uff08\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u5f8c\u59cb\u672b\u51e6\u7406\u304c\u7701\u7565\u3055\u308c\u3066\u3044\u308b\uff0estorage\u3092cvReleaseMemStrorage()\u3067\u5f8c\u59cb\u672b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3068\u601d\u3046\uff0e\uff09<\/p>\n\t\t\t\t<p>cvApproxPoly()\u306f\uff0c\u300c\u7b2c\uff13\u5f15\u6570\u304cNULL\u306a\u3089\u3070\u5165\u529b\u304c\u4f7f\u3063\u3066\u3044\u305f\u5834\u6240\u306b\u7d50\u679c\u3092\u4fdd\u5b58\u3059\u308b\u300d\u3068\u306e\u3053\u3068\uff08\u7d50\u679c\u3068\u3057\u3066\u30c7\u30fc\u30bf\u91cf\u304c\u5897\u3048\u305f\u5834\u5408\u3068\u304b\u5927\u4e08\u592b\u306a\u306e\u3060\u308d\u3046\u304b\uff1f\u3068\u308a\u3042\u3048\u305a\u7121\u4e8b\u306b\u52d5\u3044\u3066\u3044\u308b\u3088\u3046\u3060\u304c\uff09\uff0e<br \/>\n\t\t\t\t\u7cbe\u5ea6\u306b\u95a2\u3059\u308b\u30d1\u30e9\u30e1\u30bf\u306f\uff0c\u8fd1\u4f3c\u5f8c\u306e\u6298\u308c\u7dda\u3068\u8fd1\u4f3c\u524d\u306e\u30c7\u30fc\u30bf\u3068\u306e\u9593\u306e\u8a31\u5bb9\u8ddd\u96e2\u306e\u3088\u3046\u306a\u3082\u306e\u3060\u3068\u601d\u308f\u308c\u308b\uff08\u2190\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u540d\u3092\u30b0\u30b0\u3063\u3066\u51fa\u3066\u304d\u305f\u30da\u30fc\u30b8\u306b\u3042\u3063\u305f\u7d75\u3060\u3051\u304b\u3089\u306e\u60f3\u50cf\uff09\uff0e\uff08\u8a66\u3057\u306b\u8ca0\u306e\u5024\u3092\u5165\u308c\u3066\u307f\u305f\u3089\u5373\u6b7b\u306a\u3055\u308c\u305f\u306e\u3067\u6ce8\u610f\uff09<\/p>\n\t\t\t\t<p>\u5404contour\u304c\u6301\u3063\u3066\u3044\u308b\u30c7\u30fc\u30bf\uff08cvFindContours()\u306e\u5f15\u6570\u6307\u5b9a\u3067\uff0c\u7d50\u679c\u3092\u30c1\u30a7\u30a4\u30f3\u30b3\u30fc\u30c9\u3067\u306f\u306a\u304f\u70b9\u5217\u306b\u3057\u3066\u3044\u308b\u306e\u3067\uff0c\u30c7\u30fc\u30bf\u306f\u591a\u5206\u70b9\u5ea7\u6a19\u3067CvPoint\u578b\uff09\u306b\u306f\uff0cCV_GET_SEQ_ELEM\u306a\u308b\u30de\u30af\u30ed\u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u6a21\u69d8\u3067\uff0c\u3053\u308c\u3067\u7121\u4e8b\u306b\u5ea7\u6a19\u3092\u53d6\u5f97\u3067\u304d\u305f\uff0e<\/p>\n\t\t\t\t<p>\u306a\u304a\uff0c\u4eca\u56de\u306fcvApproxPoly()\u306e\u51e6\u7406\u304c\u5165\u3063\u3066\u3044\u308b\u304c\uff0c\u4e0d\u8981\u306a\u5834\u5408\u306f\u53d6\u3063\u6255\u3048\u3070\uff2f\uff2b\uff0e<br \/>\n\t\t\t\t\u2191\u306e\u30b3\u30fc\u30c9\u3067\u3044\u3048\u3070\uff0c\u8fd1\u4f3c\u51e6\u7406\u3092\u7701\u304f\u6700\u3082\u7c21\u5358\u306a\u65b9\u6cd5\u306f<br \/>\n\t\t\t\t\u00a0 CvSeq *approx = cvApproxPoly(&#8230;)<br \/>\n\t\t\t\t\u306e\u3068\u3053\u308d\u3092\uff0c<br \/>\n\t\t\t\t\u00a0 CvSeq *approx = contour;<br \/>\n\t\t\t\t\u3068\u3057\u3066\u3057\u307e\u3048\u3070\u3044\u3044\uff0e<br \/>\n\t\t\t\t\u203b\u305f\u3060\u3057\uff0ccvFindContours()\u81ea\u4f53\u3082\uff0c\u5f15\u6570\u6307\u5b9a\u306b\u3088\u3063\u3066\u30c7\u30fc\u30bf\u3092\u8fd1\u4f3c\u3059\u308b\u306e\u3067\u305d\u306e\u70b9\u306f\u6ce8\u610f\uff0e<\/p>\n\t\t\t\t<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.iss.ai\/wp-content\/uploads\/2009\/08\/Contour.png\" alt=\"Contour\" title=\"Contour\" width=\"508\" height=\"477\" class=\"alignnone size-full wp-image-1061\" srcset=\"https:\/\/www.iss.ai\/wp-content\/uploads\/2009\/08\/Contour.png 508w, https:\/\/www.iss.ai\/wp-content\/uploads\/2009\/08\/Contour-300x281.png 300w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><br \/>\n\t\t\t\t\u4e0a\u8a18\u95a2\u6570\u3092\u4f7f\u3063\u3066\u7cbe\u5ea6\u30d1\u30e9\u30e1\u30bf=5.0\u3067\u53d6\u5f97\u3067\u304d\u305f\u70b9\u5217\u3092\u8d64\u7dda\u3067\u3064\u306a\u3044\u3067\u307f\u305f\uff0e<br \/>\n\t\t\t\t\u3053\u306e\u95a2\u6570\u306b\u6e21\u3059\u5165\u529b\u753b\u50cf\u3092 cvCanny\u2192cvDilate \u3067\u4f5c\u3063\u305f\u305b\u3044\u3067\u8f2a\u90ed\u304c\u4e8c\u91cd\u306b\u51fa\u3066\u307e\u3059\u304c\uff0e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenCV\u306ecvFindContours()\u306f\uff12\u5024\u753b\u50cf\u304b\u3089\u8f2a\u90ed\u3092\u53d6\u3063\u3066\u304d\u3066\u304f\u308c\u308b\u306e\u3060\u304c\uff0c \u305d\u306e\u7d50\u679c\u304b\u3089\u8f2a\u90ed\u7dda\u306e\u30d4\u30af\u30bb\u30eb\u5ea7\u6a19\u3092\u3069\u3046\u3084\u3063\u3066\u53d6\u5f97\u3059\u308b\u306e\u304b\uff1f \u3068\u3044\u3046\u306e\u3092\u8abf\u3079\u3066\uff0c\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u305f\uff0e \uff08\u6700\u60aa\u300ccvDrawConto [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3,6],"tags":[19],"class_list":["post-1053","post","type-post","status-publish","format-standard","hentry","category-soft","category-tech","category-vision","tag-opencv"],"_links":{"self":[{"href":"https:\/\/www.iss.ai\/index.php?rest_route=\/wp\/v2\/posts\/1053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iss.ai\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iss.ai\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iss.ai\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iss.ai\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1053"}],"version-history":[{"count":12,"href":"https:\/\/www.iss.ai\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions"}],"predecessor-version":[{"id":1066,"href":"https:\/\/www.iss.ai\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions\/1066"}],"wp:attachment":[{"href":"https:\/\/www.iss.ai\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iss.ai\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iss.ai\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}