test_feature.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. import matplotlib.pyplot as plt
  3. import hogsvm
  4. import cv2 as cv
  5. import numpy as np
  6. bin_n = 16 # Number of bins
  7. def hog(img):
  8. gx = cv.Sobel(img, cv.CV_32F, 1, 0)
  9. gy = cv.Sobel(img, cv.CV_32F, 0, 1)
  10. mag, ang = cv.cartToPolar(gx, gy)
  11. bins = np.int32(bin_n*ang/(2*np.pi)) # quantizing binvalues in (0...16)
  12. bin_cells = bins[:10,:10], bins[10:,:10], bins[:10,10:], bins[10:,10:]
  13. mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
  14. hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
  15. hist = np.hstack(hists) # hist is a 64 bit vector
  16. return hist
  17. ## [hog]
  18. if __name__ == '__main__':
  19. img_filename = "/var/www/html/fire/labelme_samples/000366_37.jpg"
  20. img = cv.imread(img_filename)
  21. if img is None:
  22. raise Exception("Error: file {0} is not image".format(img_filename))
  23. # print(img)
  24. fea = hogsvm.feature_vector(img)
  25. # fea = hog(img)
  26. print(fea)
  27. # print(fea.shape)
  28. # fea2 = color_hist(img)
  29. # print(fea2)
  30. # print(fea2.shape)