fr/hogger.py

52 lines
1.0 KiB
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-03-02 18:34:59 +05:30
import ntpath
2021-02-02 01:48:30 +05:30
def display_image(img):
plt.imshow(img)
plt.show()
2021-03-02 18:34:59 +05:30
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
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)
2021-03-02 18:34:59 +05:30
if len(sys.argv) < 3:
print("no output folder")
exit(1)
op_path = sys.argv[2]
2021-02-02 01:48:30 +05:30
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 18:34:59 +05:30
orientations=9,
2021-03-02 00:32:58 +05:30
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')
2021-03-02 18:34:59 +05:30
imsave( op_path + "/hog_of" + path_leaf(sys.argv[1]), hog_img)