{"id":6765,"date":"2019-04-24T10:31:48","date_gmt":"2019-04-24T01:31:48","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=6765"},"modified":"2020-05-28T12:18:02","modified_gmt":"2020-05-28T03:18:02","slug":"python%ea%b3%bc-opencv-28-harris-corner-detection","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=6765","title":{"rendered":"Python\uacfc OpenCV \u2013 31 : Harris Corner Detection"},"content":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_feature2d\/py_features_harris\/py_features_harris.html \uc785\ub2c8\ub2e4.<\/p>\n<p>\uc774\ubbf8\uc9c0\uc758 \ud2b9\uc9d5\uc810\uc778 \uadc0\ud241\uc774(Corner) \uc9c0\uc810\uc744 \ucd94\ucd9c\ud558\ub294 \uc54c\uace0\ub9ac\uc998 \uc911 \ud558\ub098\uc778 Harris Corner Detection\uc5d0 \ub300\ud55c \uc608\uc81c\ub97c \uc0b4\ud3b4 \ubd05\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\n\r\nfilename = '.\/data\/blox.jpg'\r\nimg = cv2.imread(filename)\r\ngray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\r\n\r\ngray = np.float32(gray)\r\ndst = cv2.cornerHarris(gray,2,3,0.04)\r\n\r\nimg[dst>0.01*dst.max()]=[0,0,255]\r\n\r\ncv2.imshow('dst',img)\r\ncv2.waitKey(0)\r\ncv2.destroyAllWindows()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4. \uc785\ub825 \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud574 Corner\ub85c \uc778\uc2dd\ub418\ub294 \ubd80\ubd84\uc5d0 \ube68\uac04\uc0c9 \uc810 \ud45c\uc2dc\uac00 \ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/04\/HarrisCornerDet1.png\" alt=\"\" width=\"259\" height=\"289\" class=\"aligncenter size-full wp-image-6769\" \/><\/p>\n<p>cv2.cornerHarris() \ud568\uc218\uc758 \uc778\uc790\ub97c \uc0b4\ud3b4\ubcf4\uba74, \uccab\ubc88\uc9f8\ub294 \uc785\ub825 \uc774\ubbf8\uc9c0\ub85c\uc368 \ub2e8\uc77c \ucc44\ub110 \uc774\ubbf8\uc9c0(Grayscale)\uc5ec\uc57c \ud558\uba70 \ub370\uc774\ud130 \ud0c0\uc785\uc740 float32\uc785\ub2c8\ub2e4. \ub450\ubc88\uc9f8\ub294 Corner \uac80\ucd9c\uc744 \uc704\ud55c \uc54c\uace0\ub9ac\uc998 \uc218\ud589 \uc911 \uac80\uc0ac\ud560 \uc774\uc6c3 \ud53d\uc140\uc758 \ud06c\uae30\uc785\ub2c8\ub2e4. \uc138\ubc88\uc9f8\ub294 \ub0b4\ubd80\uc801\uc73c\ub85c \uc801\uc6a9\ud560 Sobel \ud544\ud130\ub9c1\uc5d0 \ub300\ud55c \uc778\uc790(Apeture Parameter)\uc785\ub2c8\ub2e4. \ub05d\uc73c\ub85c \ub124\ubc88\uc9f8\ub294 \ubc29\uc801\uc2dd\uc758 Harris Detector\uc758 \uc790\uc720\ubcc0\uc218\uc785\ub2c8\ub2e4. cv2.corenrHarris() \ud568\uc218\uc758 \uacb0\uacfc\ub85c \uc785\ub825 \uc774\ubbf8\uc9c0\uc640 \ub3d9\uc77c\ud55c \ud06c\uae30\uc758 2\ucc28\uc6d0 \ubc30\uc5f4\uc774 \uc0dd\uc131\ub418\ub294\ub370, Corner \uc9c0\uc810\uc740 \uc774 \ubc30\uc5f4\uc758 \uac12\ub4e4 \uc911 \ucd5c\ub300\uac12\uc758 0.01 \ubc30 \uc774\uc0c1\uc778 \uc9c0\uc810\ub9cc\uc744 \ud45c\uc2dc\ud558\uae30 \uc704\ud574 11\ubc88 \ucf54\ub4dc\uac00 \uc0ac\uc6a9\ub429\ub2c8\ub2e4.<\/p>\n<p>Corner\ub97c cv2.corenrHarris \ud568\uc218\ub97c \ud1b5\ud574 \ucd94\ucd9c\ud55c \ub4a4, \uc774 \ucd94\ucd9c \uacb0\uacfc\ub97c \uc774\uc6a9\ud574 \ub2e4\uc2dc \uc880\ub354 \uc815\ubc00\ud55c \uadc0\ud241\uc774\ub97c \ucd94\ucd9c\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub97c SubPixel Accuraacy\ub97c \uac00\uc9c0\ub294 Corner\uc774\ub77c\uace0 \ud569\ub2c8\ub2e4. \uc608\uc81c\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\n\r\nfilename = '.\/data\/blox.jpg'\r\nimg = cv2.imread(filename)\r\ngray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\r\n\r\n# find Harris corners\r\ngray = np.float32(gray)\r\ndst = cv2.cornerHarris(gray,2,3,0.04)\r\ndst = cv2.dilate(dst,None)\r\nret, dst = cv2.threshold(dst,0.01*dst.max(),255,0)\r\ndst = np.uint8(dst)\r\n\r\n# find centroids\r\nret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst)\r\n\r\n# define the criteria to stop and refine the corners\r\ncriteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001)\r\ncorners = cv2.cornerSubPix(gray,np.float32(centroids),(5,5),(-1,-1),criteria)\r\n\r\n# Now draw them\r\nres = np.hstack((centroids,corners))\r\nres = np.int0(res)\r\nimg[res[:,1],res[:,0]] = [0,0,255]\r\nimg[res[:,3],res[:,2]] = [0,255,0]\r\n\r\ncv2.imshow('dst',img)\r\ncv2.waitKey(0)\r\ncv2.destroyAllWindows()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/04\/HarrisCornerDet2.png\" alt=\"\" width=\"259\" height=\"289\" class=\"aligncenter size-full wp-image-6772\" \/><\/p>\n<p>\ud53d\uc140\uc774 \uc791\uc544 \ub208\uc5d0 \ubcf4\uae30 \ud798\ub4e4 \uc218 \uc788\uc9c0\ub9cc, \ube68\uac04\uc0c9\uc758 \ud53d\uc140\uc774 \uc55e\uc11c \uc5b8\uae09\ud55c cv2.cornerHarris \ud568\uc218\ub97c \ud1b5\ud574 \ucd94\ucd9c\ud55c Corner\uc774\uace0 \ucd08\ub85d\uc0c9\uc758 \ud53d\uc140\uc774 cv2.cornerHarris \ud568\uc218\ub97c \ud1b5\ud574 \uc5bb\uc740 \uacb0\uacfc\ub97c \ud65c\uc6a9\ud574 cv2.cornerSubPix \ud568\uc218\ub97c \uc801\uc6a9\ud574 \uc880\ub354 \uc815\ud655\ud55c Corenr\uc758 \uc704\uce58\ub97c \ucd94\ucd9c\ud55c \uacb0\uacfc\uc785\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_feature2d\/py_features_harris\/py_features_harris.html \uc785\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc758 \ud2b9\uc9d5\uc810\uc778 \uadc0\ud241\uc774(Corner) \uc9c0\uc810\uc744 \ucd94\ucd9c\ud558\ub294 \uc54c\uace0\ub9ac\uc998 \uc911 \ud558\ub098\uc778 Harris Corner Detection\uc5d0 \ub300\ud55c \uc608\uc81c\ub97c \uc0b4\ud3b4 \ubd05\ub2c8\ub2e4. import cv2 import numpy as np filename = &#8216;.\/data\/blox.jpg&#8217; img = cv2.imread(filename) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) gray = np.float32(gray) dst = cv2.cornerHarris(gray,2,3,0.04) img[dst>0.01*dst.max()]=[0,0,255] cv2.imshow(&#8216;dst&#8217;,img) cv2.waitKey(0) cv2.destroyAllWindows() \uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4. \uc785\ub825 \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud574 Corner\ub85c \uc778\uc2dd\ub418\ub294 \ubd80\ubd84\uc5d0 \ube68\uac04\uc0c9 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=6765\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Python\uacfc OpenCV \u2013 31 : Harris Corner Detection&#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-6765","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\/6765","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=6765"}],"version-history":[{"count":9,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6765\/revisions"}],"predecessor-version":[{"id":9442,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6765\/revisions\/9442"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6765"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}