SURF&HOG
SURF&HOG
import numpy as np
from skimage.feature import hog
from skimage import exposure
import matplotlib.pyplot as plt
image_path = 'gtx.jpg'
image = cv2.imread(image_path)
if image is None:
raise FileNotFoundError(f"Image not found at path: {image_path}")
hog_image_rescaled = exposure.rescale_intensity(hog_image,
in_range=(0, 10))
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title("Original Image")
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(hog_image_rescaled, cmap='gray')
plt.title("HOG Visualization")
plt.axis('off')
plt.tight_layout()
plt.show()
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('gtx.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Draw keypoints
img_with_kp = cv2.drawKeypoints(img, keypoints, None, (255, 0, 0),
4)
# Show result
plt.figure(figsize=(10, 8))
plt.imshow(cv2.cvtColor(img_with_kp, cv2.COLOR_BGR2RGB))
plt.title('SURF Keypoints')
plt.axis('off')
plt.show()
else:
print("xfeatures2d module is not available. Check if opencv-
contrib-python is properly installed.")
----------------------------------------------------------------------
-----
AttributeError Traceback (most recent call
last)
<ipython-input-8-06816cfe00d0> in <cell line: 0>()
9 if hasattr(cv2, 'xfeatures2d'):
10 # Create SURF detector object
---> 11 surf = cv2.xfeatures2d.SURF_create(hessianThreshold=400)
12
13 # Detect keypoints and compute descriptors