{"id":45835,"date":"2021-12-09T09:52:33","date_gmt":"2021-12-09T00:52:33","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=45835"},"modified":"2021-12-09T10:25:07","modified_gmt":"2021-12-09T01:25:07","slug":"%ec%95%88%eb%93%9c%eb%a1%9c%ec%9d%b4%eb%93%9c%eb%a1%9c-%eb%b0%b0%ec%9a%b0%eb%8a%94-opencv-convex-%ec%97%ac%eb%b6%80-%ea%b2%80%ec%82%ac%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=45835","title":{"rendered":"[\uc548\ub4dc\ub85c\uc774\ub4dc\ub85c \ubc30\uc6b0\ub294 OpenCV] Convex \uc5ec\ubd80 \uac80\uc0ac\ud558\uae30"},"content":{"rendered":"\n<p>Prerequisite : <a href=\"https:\/\/www.charlezz.com\/?p=45795\">\uc724\uacfd\uc120 \uae38\uc774 \uad6c\ud558\uae30<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Convex \uac80\uc0ac<\/h2>\n\n\n\n<p>Convex \uac80\uc0ac\ub294 \uc8fc\uc5b4\uc9c4 <strong>\uc724\uacfd\uc120\uc774 \ubcfc\ub85d\ud55c\uc9c0 \uc5ec\ubd80<\/strong>\ub97c \ud655\uc778\ud558\ub294 \uac83\uc744 \ub9d0\ud55c\ub2e4. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learnopencv.com\/wp-content\/uploads\/2018\/08\/convex-hull.jpg\" alt=\"Convex Hull\" class=\"wp-image-9302\" title=\"convex-hull \u2013 LearnOpenCV\u00a0\"\/><\/figure>\n\n\n\n<p>OpenCV\uc5d0\uc11c\ub294 isContourConvex()\ub77c\ub294 \ud568\uc218\ub97c \ud1b5\ud574 Convex \uac80\uc0ac\ub97c \ud560 \uc218 \uc788\ub2e4. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Imgproc.isContourConvex(contour)<\/pre>\n\n\n\n<p>contour: \uc724\uacfd\uc120 \uc88c\ud45c \uc815\ubcf4.<br>\ubc18\ud658\uac12: convex \uc5ec\ubd80<\/p>\n\n\n\n<p>convex\ub97c \uac80\uc0ac\ud558\ub294 \uc608\uc81c\ub97c \uc0b4\ud3b4\ubcf4\uc790.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1-820x1024.png\" alt=\"\" class=\"wp-image-45837\" width=\"615\" height=\"768\" srcset=\"https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1-820x1024.png 820w, https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1-240x300.png 240w, https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1-768x959.png 768w, https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1-1230x1536.png 1230w, https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1-1640x2048.png 1640w, https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2021\/12\/www.charlezz.com-opencv-convex-screenshot-1639010969525-1.png 1768w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/figure>\n\n\n\n<p>\ubcfc\ub85d\ud55c \ub3c4\ud615\uc758 \uacbd\uc6b0 Convex\ub77c\uace0 \ub9c8\ud0b9\ub418\uc5b4\uc788\uace0, \uc624\ubaa9\ud55c \ub3c4\ud615\uc758 \uacbd\uc6b0 Concave\ub77c\uace0 \ub9c8\ud0b9\ub418\uc5b4\uc788\ub2e4. \ud770 \ubc14\ud0d5\uc758 \ubc30\uacbd\ub3c4 \ud558\ub098\uc758 \ud070 convex\ud55c \uc724\uacfd\uc120\uc73c\ub85c \uc778\uc2dd\ub418\uc5c8\ub2e4.<\/p>\n\n\n\n<p>\uc608\uc81c\ucf54\ub4dc:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">val contours = ArrayList&lt;MatOfPoint&gt;()\nval hierarchy = Mat()\n\/\/ \uc724\uacfd\uc120 \uac80\ucd9c\nImgproc.findContours(\n    binary,\n    contours,\n    hierarchy,\n    Imgproc.<em>RETR_TREE<\/em>,\n    Imgproc.<em>CHAIN_APPROX_SIMPLE\n<\/em>)\n\nfor (i in 0 <em>until <\/em>contours.size) {\n    \/\/\uc724\uacfd\uc120 \uc911\uc810 \ucc3e\uae30\n    val contour = contours[i]\n    val moments = Imgproc.moments(contour)\n    val centerX = moments.m10 \/ moments.m00 - 60\n    val centerY = moments.m01 \/ moments.m00 + 10\n    val center = Point(centerX, centerY)\n\n    \/\/ \uac80\ucd9c\ud55c \uc724\uacfd\uc120 \uadf8\ub9ac\uae30\n    Imgproc.drawContours(src, contours, i, <em>RED<\/em>)\n\n    \/\/ \ucee8\ubca1\uc2a4 \uac80\ucd9c \uc815\ud655\ub3c4\ub97c \ub192\uc774\uae30 \uc704\ud574 \uc724\uacfd\uc120 \uadfc\uc0ac\ud654\n    val contour2f = MatOfPoint2f(*contours[i].toArray())\n    val approxContour = MatOfPoint2f()\n    Imgproc.approxPolyDP(\n        contour2f,\n        approxContour,\n        Imgproc.arcLength(contour2f, true)*(0.02),\n        true\n    )\n\n    \/\/ \ucee8\ubca1\uc2a4 \uac80\uc0ac\ud558\uae30\n    val isConvex = Imgproc.isContourConvex(MatOfPoint(*approxContour.toArray()))\n\n    \/\/ \ucee8\ubca1\uc2a4\ub77c\uba74 \ub3c4\ud615\uc704\uc5d0 Convex\ub77c\uace0 \ub9c8\ud0b9, \uc544\ub2c8\uba74 Concave\ub85c \ub9c8\ud0b9\n    if(isConvex){\n        Imgproc.putText(src, \"Convex\",center,Imgproc.<em>FONT_HERSHEY_SIMPLEX<\/em>, 1.0, <em>RED<\/em>)\n    }else{\n        Imgproc.putText(src, \"Concave\",center,Imgproc.<em>FONT_HERSHEY_SIMPLEX<\/em>, 1.0, <em>RED<\/em>)\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisite : \uc724\uacfd\uc120 \uae38\uc774 \uad6c\ud558\uae30 Convex \uac80\uc0ac Convex \uac80\uc0ac\ub294 \uc8fc\uc5b4\uc9c4 \uc724\uacfd\uc120\uc774 \ubcfc\ub85d\ud55c\uc9c0 \uc5ec\ubd80\ub97c \ud655\uc778\ud558\ub294 \uac83\uc744 \ub9d0\ud55c\ub2e4. OpenCV\uc5d0\uc11c\ub294 isContourConvex()\ub77c\ub294 \ud568\uc218\ub97c \ud1b5\ud574 Convex \uac80\uc0ac\ub97c \ud560 \uc218 \uc788\ub2e4. Imgproc.isContourConvex(contour) contour: \uc724\uacfd\uc120 \uc88c\ud45c \uc815\ubcf4.\ubc18\ud658\uac12: convex \uc5ec\ubd80 convex\ub97c \uac80\uc0ac\ud558\ub294 \uc608\uc81c\ub97c \uc0b4\ud3b4\ubcf4\uc790. \ubcfc\ub85d\ud55c \ub3c4\ud615\uc758 \uacbd\uc6b0 Convex\ub77c\uace0 \ub9c8\ud0b9\ub418\uc5b4\uc788\uace0, \uc624\ubaa9\ud55c \ub3c4\ud615\uc758 \uacbd\uc6b0 Concave\ub77c\uace0 \ub9c8\ud0b9\ub418\uc5b4\uc788\ub2e4. \ud770 \ubc14\ud0d5\uc758 \ubc30\uacbd\ub3c4 \ud558\ub098\uc758 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[27],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45835"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45835"}],"version-history":[{"count":2,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45835\/revisions"}],"predecessor-version":[{"id":45848,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45835\/revisions\/45848"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}