0
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

画像のコーナー検出

Last updated at Posted at 2021-05-05

はじめに

OpenCVでコーナーの検出を行います。方法は主にHarris Corner Detection MethodgoodFeaturesToTrack Detection Methodの2つがあります。

使用する画像は次の画像です。Rectangles.pngとして保存して使用します。

Rectangles.png

Harris Corner Detection Method

はじめにHarris Corner Detection Methodを試します。

harris.py
import cv2
import numpy as np


image= cv2.imread('Rectangles.png')
gray= cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

gray= np.float32(gray)

harris_corners= cv2.cornerHarris(gray, 3, 3, 0.05)

kernel= np.ones((7,7), np.uint8)

harris_corners= cv2.dilate(harris_corners, kernel, iterations= 2)


image[harris_corners > 0.025 * harris_corners.max()]= [255,127,127]

cv2.imwrite('Corner_detected_rectangles.png', image)
cv2.imshow('Harris Corners', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
  • 処理後

Corner_detected_rectangles.png

goodFeaturesToTrack Detection Method

次にgoodFeaturesToTrack Detection Methodを試します。

goodReatures.py
import cv2

img= cv2.imread('Rectangles.png')
gray= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

corners= cv2.goodFeaturesToTrack(gray, 100, 0.01, 50)

for corner in corners:
    x,y= corner[0]
    x= int(x)
    y= int(y)
    cv2.rectangle(img, (x-10,y-10),(x+10,y+10),(255,0,0),-1)


cv2.imwrite('Corner_detected_rectangles.png', img)
cv2.imshow("goodFeaturesToTrack Corner Detection", img)
cv2.waitKey()
cv2.destroyAllWindows()
  • 処理後

Corner_detected_rectangles.png

参考

0
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?