{"id":6565,"date":"2019-04-01T10:05:28","date_gmt":"2019-04-01T01:05:28","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=6565"},"modified":"2020-05-28T12:31:25","modified_gmt":"2020-05-28T03:31:25","slug":"python%ea%b3%bc-opencv-15-%ec%9d%b4%eb%af%b8%ec%a7%80%ec%9d%98-%eb%93%b1%ec%b9%98%ec%84%a0contours-1-5","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=6565","title":{"rendered":"Python\uacfc OpenCV \u2013 15 : \uc774\ubbf8\uc9c0\uc758 \ub4f1\uce58\uc120(Contours) &#8211; 1\/5"},"content":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_imgproc\/py_contours\/py_contours_begin\/py_contours_begin.html#contours-getting-started \uc785\ub2c8\ub2e4.<\/p>\n<p>\ub4f1\uce58\uc120\uc774\ub780 \uc774\ubbf8\uc9c0\uc5d0\uc11c \ub3d9\uc77c\ud55c \uc0c9\uc774\ub098 \uac15\ub3c4\uac12\uc744 \uac00\uc9c0\ub294 \ud3ec\uc778\ud2b8\ub97c \uc5f0\uacb0\ud55c \ubaa8\ub4e0 \uc5f0\uc18d\ub41c \uc120\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4. \uc774 \ub4f1\uce58\uc120\uc740 \uac1d\uccb4 \uc778\uc2dd\uc774\ub098 \uc2dd\ubcc4\uc744 \uc704\ud55c \ubd84\uc11d\uc5d0 \ub9e4\uc6b0 \uc720\uc6a9\ud55c \ub3c4\uad6c\uc785\ub2c8\ub2e4. \ub4f1\uce58\uc120\uc744 \ubcf4\ub2e4 \ub354 \uc815\ud655\ud788 \ucd94\ucd9c\ud558\uae30 \uc704\ud574\uc11c \ubc14\uc774\ub108\ub9ac \uc774\ubbf8\uc9c0\ub97c \uc0ac\uc6a9\ud558\ub294\ub370, \uc774\ub97c \uc704\ud574\uc11c \uc774\ubbf8\uc9c0\uc5d0 \uc784\uacc4\uce58(Threshold) \uc801\uc6a9\uc774\ub098 Canny \uc678\uacfd\uc120 \uac80\ucd9c\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4. cv2.findCountors \ud568\uc218\uac00 \ub4f1\uce58\uc120\uc744 \ucd94\ucd9c\ud558\ub294 \ud568\uc218\uc778\ub370, \ub4f1\uce58\uc120 \ucd94\ucd9c \uacfc\uc815\uc5d0\uc11c \uc6d0\ubcf8 \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud55c \uc218\uc815\ub41c \uc774\ubbf8\uc9c0\ub97c \ubc18\ud658\ud569\ub2c8\ub2e4. OpenCV\uc5d0\uc11c \ub4f1\uce58\uc120\uc744 \ucd94\ucd9c\ud55c\ub2e4\ub294 \uac83\uc740 \uac80\uc815\uc0c9 \ubc30\uacbd\uc73c\ub85c\ubd80\ud130 \ud558\uc580\uc0c9 \uac1d\uccb4\ub97c \ubc1c\uacac\ud55c\ub2e4\ub294 \uac83\uace0 \uc720\uc0ac\ud569\ub2c8\ub2e4. \uadf8\ub7ec\ubbc0\ub85c \ubc18\ub4dc\uc2dc \ubc1c\uacac\ub41c \uac1d\uccb4\ub294 \ud558\uc580\uc0c9\uc774\uace0 \ubc30\uacbd\uc740 \uac80\uc815\uc0c9\uc774\ub77c\ub294 \uc810\uc744 \uae30\uc5b5\ud574\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<p>\ubc14\uc774\ub108\ub9ac \uc774\ubbf8\uc9c0\uc5d0\uc11c \ub4f1\uce58\uc120\uc744 \ucd94\ucd9c\ud558\ub294 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport numpy as np\r\nimport cv2\r\n\r\nim = cv2.imread('.\/data\/cornerTest.jpg')\r\nimgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)\r\nret,thresh = cv2.threshold(imgray,127,255,0)\r\nimage, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)\r\n\r\nprint(contours)\r\n<\/pre>\n<p>\ub4f1\uce58\uc120\uc740 \ub4f1\uce58\uc120\uc744 \uad6c\uc131\ud558\ub294 \uc88c\ud45c\uc5d0 \ub300\ud55c \ubc30\uc5f4\uc778\ub370, \uc704 \ucf54\ub4dc\uc758 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n[array([[[  0,   0]],\r\n        [[  0, 511]],\r\n        [[511, 511]],\r\n        [[511,   0]]], dtype=int32), \r\n array([[[107, 126]],\r\n        [[108, 125]],\r\n        [[265, 125]],\r\n        [[266, 126]],\r\n        [[266, 168]],\r\n        [[387, 168]],\r\n        [[388, 169]],\r\n        [[388, 375]],\r\n        [[387, 376]],\r\n        [[169, 376]],\r\n        [[168, 375]],\r\n        [[168, 270]],\r\n        [[108, 270]],\r\n        [[107, 269]]], dtype=int32)]\r\n<\/pre>\n<p>2\uac1c\uc758 \ub4f1\uce58\uc120\uc774 \ucd94\ucd9c\ub41c \uac83\uc774\uace0 \uac01 \ub4f1\uce58\uc120\uc758 \uad6c\uc131 \uc88c\ud45c\uac00 \ubc30\uc5f4 \uc694\uc18c\ub85c\uc368 \uc800\uc7a5\ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4. cv2.cvtColor \ud568\uc218\ub294 3\uac1c\uc758 \uc778\uc790\ub97c \ubc1b\uc2b5\ub2c8\ub2e4. \uccab\ubc88\uc9f8\ub294 \ub4f1\uace0\uc120 \ucd94\ucd9c \ub300\uc0c1\uc774 \ub418\ub294 \uc774\ubbf8\uc9c0\uc774\uace0, \ub450\ubc88\uc9f8\ub294 \ub4f1\uce58\uc120 \ucd94\ucd9c \ubc29\uc2dd\uc774\uba70 \uc138\ubc88\uc9f8\ub294 \ub4f1\uce58\uc120 \uacb0\uacfc\uc5d0 \ub300\ud55c \uadfc\uc0ac\uce58\ud654 \ubc29\uc2dd\uc5d0 \ub300\ud55c \uc9c0\uc815\uc785\ub2c8\ub2e4. \uc774 \ud568\uc218\uc758 \ubc18\ud658\uc740 \ub4f1\uce58\uc120 \ucd94\ucd9c \uacfc\uc815\uc5d0\uc11c \ubcc0\uacbd\ub41c \uc774\ubbf8\uc9c0\uc640 \ub4f1\uce58\uc120\uc758 \uad6c\uc131 \uc88c\ud45c \ubc30\uc5f4 \uadf8\ub9ac\uace0 \ub4f1\uce58\uc120\uc758 \uacc4\uce35\uac1d\uccb4\uc785\ub2c8\ub2e4. \ub450\ubc88\uc9f8\uc640 \uc138\ubc88\uc9f8\uc758 \uc778\uc790\ub294 \ucd94\ud6c4 \uc880\ub354 \uc790\uc138\ud788 \uc0b4\ud3b4\ubcf4\ub3c4\ub85d \ud558\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ub4f1\uce58\uc120\uc744 \uadf8\ub9ac\ub294 \ud568\uc218\ub294 cv2.drawContours \uc785\ub2c8\ub2e4. \uc774 \ud568\uc218\ub294 5\uac1c\uc758 \uc778\uc790\ub97c \ubc1b\ub294\ub370, \uccab\ubc88\uc9f8\ub294 \ub4f1\uce58\uc120\uc744 \uadf8\ub9b4 \uc774\ubbf8\uc9c0, \ub450\ubc88\uc9f8\ub294 \uadf8\ub9b4 \ub4f1\uce58\uc120\uc744 \uad6c\uc131\ud558\ub294 \uc88c\ud45c \ubc30\uc5f4, \uc138\ubc88\uc9f8\ub294 \ub4f1\uce58\uc120\uc758 \uc88c\ud45c \ubc30\uc5f4 \uc911 \uba87\ubc88\uc9f8 \ub4f1\uce58\uc120 \uc694\uc18c\ub97c \uadf8\ub9b4 \uac83\uc778\uc9c0\uc5d0 \ub300\ud55c \uc778\ub371\uc2a4\ub85c\uc368 -1\uc77c \uacbd\uc6b0 \ubaa8\ub4e0 \ub4f1\uce58\uc120\uc744 \uadf8\ub9bd\ub2c8\ub2e4. \ub124\ubc88\uc9f8\ub294 \uadf8\ub824\uc9c8 \ub4f1\uce58\uc120\uc758 \uc0c9\uc0c1, \ub2e4\uc12f\ubc88\uc9f8\ub294 \ub4f1\uce58\uc120\uc758 \uad75\uae30\uc785\ub2c8\ub2e4. \uc544\ub798\uc758 \ucf54\ub4dc\ub294 \ubaa8\ub4e0 \ub4f1\uce58\uc120\uc744 \ucd08\ub85d\uc120\uc73c\ub85c 3\ud53d\uc140 \uad75\uae30\ub85c \uadf8\ub9bd\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimg = cv2.drawContours(img, contours, -1, (0,255,0), 3)\r\n<\/pre>\n<p>\ub2e4\uc74c \ucf54\ub4dc\ub294 4\ubc88\uc9f8 \ub4f1\uce58\uc120 \uc694\uc18c\ub9cc\uc744 \uadf8\ub9ac\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimg = cv2.drawContours(img, contours, 3, (0,255,0), 3)\r\n<\/pre>\n<p>\ub300\ubd80\ubd84\uc758 \uacbd\uc6b0, \uc704\uc758 \ucf54\ub4dc\ubcf4\ub2e4\ub294 \uc544\ub798\uc758 \ucf54\ub4dc\uac00 \ub354 \uc720\uc6a9\ud569\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\ncnt = contours[4]\r\nimg = cv2.drawContours(img, [cnt], 0, (0,255,0), 3)\r\n<\/pre>\n<p>\uc55e\uc11c cv2.findContours \ud568\uc218\uc758 \uc778\uc790 \uc911 \uc138\ubc88\uc9f8\uc778 \ub4f1\uce58\uc120 \uacb0\uacfc\uc5d0 \ub300\ud55c \uadfc\uc0ac\uce58\ud654\uc5d0 \ub300\ud55c \uc778\uc790\uc5d0 \ub300\ud574 \uc880\ub354 \uc815\ub9ac\ub97c \ud574 \ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uc774 \uc778\uc790\ub85c \uc9c0\uc815\ud560 \uc218 \uc788\ub294 \uac12\uc740 cv2.CHAIN_APPROX_NONE\uacfc cv2.CHAIN_APPROX_SIMPLE \uc785\ub2c8\ub2e4. \uc55e\uc11c \ub4f1\uce58\uc120\uc774\ub780 \uc774\ubbf8\uc9c0\uc5d0\uc11c \ub3d9\uc77c\ud55c \uc0c9\uc0c1\uac12\uc774\ub098 \uac15\ub3c4\uac12\uc744 \uac16\ub294 \uc5f0\uc18d\ub41c \uc88c\ud45c\uc758 \ub9ac\uc2a4\ud2b8\ub77c\uace0 \ud558\uc600\uc2b5\ub2c8\ub2e4. \uc774\ub54c \uc88c\ud45c\uc758 \ub9ac\uc2a4\ud2b8\uc5d0\ub294 \ub9e4\uc6b0 \ub9ce\uc740 \uc218\uc758 \uc88c\ud45c\uac00 \ub2f4\uae30\uac8c \ub429\ub2c8\ub2e4. \uc778\uc790\uac12\uc744 cv2.CHAIN_APPROX_NONE\ub85c \uc9c0\uc815\ud558\uba74 \ub4f1\uce58\uc120\uc744 \uad6c\uc131\ud558\ub294 \uc88c\ud45c\uc5d0 \ub300\ud55c \uadfc\uc0ac\uce58\ud654\ub97c \uc218\ud589\ud558\uc9c0 \uc54a\uace0, cv2.CHAIN_APPROX_SIMPLE\ub85c \uc9c0\uc815\ud558\uba74 \ub4f1\uce58\uc120\uc744 \uad6c\uc131\ud558\ub294 \uc88c\ud45c\ub4e4 \uc911 \uc9c1\uc120\uc744 \uad6c\uc131\ud558\ub294 \uad6c\uac04\uc5d0\uc11c \uc2dc\uc791\uc810\uacfc \ub05d\uc810\ub9cc\uc744 \ub0a8\uae30\uace0 \uadf8 \uc911\uac04 \uc88c\ud45c\ub4e4\uc740 \uc81c\uac70\uc2dc\ud0a4\ub294 \ubc29\uc2dd\uc785\ub2c8\ub2e4. \uc989 cv2.CHAIN_APPROX_NONE\ub85c \uc218\ud589\ud55c \ub4f1\uce58\uc120\uc758 \uc88c\ud45c \uac1c\uc218\uac00 \ub9e4\uc6b0 \ub9ce\uc740\ub370, \uc774\ub97c cv2.CHAIN_APPROX_SIMPLE\ub85c \ubcc0\uacbd\ud574 \uc9c0\uc815\ud568\uc73c\ub85c\uc368 \ub4f1\uce58\uc120\uc758 \uad6c\uc131 \uc88c\ud45c \uac1c\uc218\ub97c \ucd5c\uc801\ud654\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_imgproc\/py_contours\/py_contours_begin\/py_contours_begin.html#contours-getting-started \uc785\ub2c8\ub2e4. \ub4f1\uce58\uc120\uc774\ub780 \uc774\ubbf8\uc9c0\uc5d0\uc11c \ub3d9\uc77c\ud55c \uc0c9\uc774\ub098 \uac15\ub3c4\uac12\uc744 \uac00\uc9c0\ub294 \ud3ec\uc778\ud2b8\ub97c \uc5f0\uacb0\ud55c \ubaa8\ub4e0 \uc5f0\uc18d\ub41c \uc120\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4. \uc774 \ub4f1\uce58\uc120\uc740 \uac1d\uccb4 \uc778\uc2dd\uc774\ub098 \uc2dd\ubcc4\uc744 \uc704\ud55c \ubd84\uc11d\uc5d0 \ub9e4\uc6b0 \uc720\uc6a9\ud55c \ub3c4\uad6c\uc785\ub2c8\ub2e4. \ub4f1\uce58\uc120\uc744 \ubcf4\ub2e4 \ub354 \uc815\ud655\ud788 \ucd94\ucd9c\ud558\uae30 \uc704\ud574\uc11c \ubc14\uc774\ub108\ub9ac \uc774\ubbf8\uc9c0\ub97c \uc0ac\uc6a9\ud558\ub294\ub370, \uc774\ub97c \uc704\ud574\uc11c \uc774\ubbf8\uc9c0\uc5d0 \uc784\uacc4\uce58(Threshold) \uc801\uc6a9\uc774\ub098 Canny \uc678\uacfd\uc120 \uac80\ucd9c\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4. cv2.findCountors \ud568\uc218\uac00 \ub4f1\uce58\uc120\uc744 \ucd94\ucd9c\ud558\ub294 \ud568\uc218\uc778\ub370, \ub4f1\uce58\uc120 \ucd94\ucd9c \uacfc\uc815\uc5d0\uc11c \uc6d0\ubcf8 \uc774\ubbf8\uc9c0\uc5d0 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=6565\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Python\uacfc OpenCV \u2013 15 : \uc774\ubbf8\uc9c0\uc758 \ub4f1\uce58\uc120(Contours) &#8211; 1\/5&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130,131],"tags":[],"class_list":["post-6565","post","type-post","status-publish","format-standard","hentry","category-opencv","category-python"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6565"}],"version-history":[{"count":5,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6565\/revisions"}],"predecessor-version":[{"id":9470,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6565\/revisions\/9470"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6565"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}