import cv2 import numpy as np from matplotlib import pyplot as plt def cv_show(
neme, img): # cv2.namedWindow(neme, cv2.WINDOW_NORMAL) cv2.imshow(neme, img) cv2
.waitKey(0) cv2.destroyAllWindows() # first # Harris Corner detection cv2.cornerHarris() img =
cv2.imread('1.png') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = np.
float32(gray) # Input image must be float32, The last parameter is in 0.04 reach 0.05 between #
parameter : image , Area size to be considered in corner detection ,Sobel Window size used in derivation ,Harris Free parameters in corner detection equation , The value parameter is [0,04,0.06] dst =
cv2.cornerHarris(gray, 2, 3, 0.04) # result is dilated for marking the
corners, not important dst = cv2.dilate(dst, None) # Threshold for an optimal
value, it may vary depending on the image. img[dst > 0.01 * dst.max()] = [0, 255
, 0] cv_show("s", img) # the second # Corner points with sub-pixel accuracy cv2.cornerSubPix() # This is Harris Corner detection
Revised version of img = cv2.imread('1.png') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #
find Harris corners gray = np.float32(gray) dst = cv2.cornerHarris(gray, 2, 3,
0.04) dst = cv2.dilate(dst, None) ret, dst = cv2.threshold(dst, 0.01 * dst.max()
, 255, 0) dst = np.uint8(dst) # find centroids #
connectedComponentsWithStats(InputArray image, OutputArray labels, OutputArray
stats, # OutputArray centroids, int connectivity=8, int ltype=CV_32S) ret,
labels, stats, centroids = cv2.connectedComponentsWithStats(dst) # define the
criteria to stop and refine the corners criteria = (cv2.TERM_CRITERIA_EPS + cv2.
TERM_CRITERIA_MAX_ITER, 100, 0.001) # Python: cv2.cornerSubPix(image, corners,
winSize, zeroZone, criteria) # zeroZone – Half of the size of the dead region
in the middle of the search zone # over which the summation in the formula
below is not done. It is used sometimes # to avoid possible singularities of
the autocorrelation matrix. The value of (-1,-1) # indicates that there is no
such a size. # Returns an array of corner coordinates ( Not images ) corners = cv2.cornerSubPix(gray, np.float32
(centroids), (5, 5), (-1, -1), criteria) # Now draw them res = np.hstack((
centroids, corners)) # np.int0 Can be used to omit numbers after the decimal point ( Non four 㮼 Five entry ) res = np.int0(res) img[res[
:, 1], res[:, 0]] = [0, 0, 255] img[res[:, 3], res[:, 2]] = [0, 255, 0] cv_show(
"ss", img) # Third # Shi-Tomasi Corner detection & Image features suitable for tracking # cv2.goodFeaturesToTrack() use
Shi-Tomasi Method to obtain the image N The best corner img = cv2.imread('1.png') gray = cv2.cvtColor(img,
cv2.COLOR_BGR2GRAY) corners = cv2.goodFeaturesToTrack(gray, 25, 0.01, 10) #
The result returned is [[ 311. 250.]] Array of two-layer parentheses . corners = np.int0(corners) for i in corners: x,
y= i.ravel() cv2.circle(img, (x, y), 3, 255, -1) plt.imshow(img), plt.show()

Technology