-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureHenris.py
More file actions
63 lines (44 loc) · 1.42 KB
/
Copy pathFeatureHenris.py
File metadata and controls
63 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import cv2
import numpy as np
filename1 ='Lena.jpg'
filename2 = 'Lena.jpg'
img1 = cv2.imread(filename1)
img2 = cv2.imread(filename2)
#Single precision float: sign bit, 8 bit exp, 23 bit mantissa
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
gray1 = np.float32(gray1)
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
gray2 = np.float32(gray2)
# img - input image, grayscale and float32
#blocksize - It is the size of neighbourhood considered for corner detection
#ksize - Aperture parameter of Sobel derivate used
#k - Harris detector free paramter in the equation.
dst1 = cv2.cornerHarris(gray1,4,3,0.04)
dst2 = cv2.cornerHarris(gray2,4,3,0.04)
#result is dilated for making the corners , not important
dst1 =cv2.dilate(dst1 , None)
dst2 = cv2.dilate(dst2 , None)
#Threshold for an optimal value, it may very depending on the image
i = 0
x= 0
for n1 in dst1:
i = i+1
print(i)
for n2 in dst2:
x =x+1
for pixel1 in n1:
for pixel2 in n2:
if (pixel1 > 0.08) & (pixel1 == pixel2):
print('True')
pixel1 = pixel1*10
pixel2 = pixel2*10
img1[dst1>0.08*dst1.max()]=[0,0,255]
img2[dst2>0.08*dst2.max()]=[0,0,255]
cv2.imshow('prova1',img1)
cv2.imshow('prova2',img2)
k = cv2.waitKey(0)
if k==27:
cv2.destroyAllWindows()
#TO DO
#Mathcing 2 images (report on pY)
#using distance metric