fr/hogger.py

46 lines
821 B
Python
Raw Normal View History

2021-03-02 00:32:58 +05:30
from skimage.io import imread, imshow, imsave
2021-02-02 01:48:30 +05:30
from skimage.transform import resize
from skimage.feature import hog
from skimage import exposure
import matplotlib.pyplot as plt
import sys
2021-03-02 00:32:58 +05:30
import cv2
import numpy as np
2021-02-02 01:48:30 +05:30
def display_image(img):
plt.imshow(img)
plt.show()
2021-03-02 00:32:58 +05:30
2021-02-02 01:48:30 +05:30
if len(sys.argv) < 2:
print("no input image")
exit(1)
img = imread(sys.argv[1], as_gray=True)
print(img.shape)
##resizing to 1:2 aspect ratio for easier calc
2021-03-02 00:32:58 +05:30
# resized_img = resize(img,(1024,512))
resized_img = img
2021-02-02 01:48:30 +05:30
print(resized_img.shape)
2021-03-02 00:32:58 +05:30
# display_image(resized_img)
2021-02-02 01:48:30 +05:30
2021-03-02 00:32:58 +05:30
# calc hog
2021-02-02 01:48:30 +05:30
fd, hog_img = hog(resized_img,
2021-03-02 00:32:58 +05:30
orientations=8,
pixels_per_cell=(2,2),
cells_per_block=(1,1),
2021-02-02 01:48:30 +05:30
visualize=True,
multichannel=False )
2021-03-02 00:32:58 +05:30
# display_image(hog_img)
hog_img = np.array(hog_img, dtype='uint8')
imsave("hog_of" + sys.argv[1], hog_img)