-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast.py
More file actions
39 lines (27 loc) · 1.32 KB
/
fast.py
File metadata and controls
39 lines (27 loc) · 1.32 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
import cv2
import matplotlib.pyplot as plt
import numpy as np
image = cv2.imread('./fisheye1.png')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
fx, plots = plt.subplots(1, 2, figsize=(20,10))
plots[0].set_title("Orignal Image")
plots[0].imshow(image)
plots[1].set_title("Gray Image")
plots[1].imshow(gray, cmap="gray")
fast = cv2.FastFeatureDetector_create()
keypoints_with_nonmax = fast.detect(gray, None)
fast.setNonmaxSuppression(False)
keypoints_without_nonmax = fast.detect(gray, None)
image_with_nonmax = np.copy(image)
image_without_nonmax = np.copy(image)
cv2.drawKeypoints(image, keypoints_with_nonmax, image_with_nonmax, color=(0,255,0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.drawKeypoints(image, keypoints_without_nonmax, image_without_nonmax, color=(0,255,0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
fx, plots = plt.subplots(1, 2, figsize=(20,10))
plots[0].set_title("With non max suppression")
plots[0].imshow(image_with_nonmax)
plots[1].set_title("Without non max suppression")
plots[1].imshow(image_without_nonmax)
print("Number of Keypoints Detected In The Image With Non Max Suppression: ", len(keypoints_with_nonmax))
print("Number of Keypoints Detected In The Image Without Non Max Suppression: ", len(keypoints_without_nonmax))
plt.show()