xdenisx

Descriptors

Apr 24th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Tests the various feature detector algorithms in OpenCV 2.4 on one image
  5.  
  6. @SINCE: Thu Sep 13 23:01:23 2012
  7. @VERSION: 0.1
  8.  
  9. @REQUIRES: OpenCV 2.4 (I used 2.4.0), matplotlib
  10.  
  11. @AUTHOR: Ripley6811
  12. @ORGANIZATION: National Cheng Kung University, Department of Earth Sciences
  13. """
  14. __author__ = 'Ripley6811'
  15. __copyright__ = ''
  16. __license__ = ''
  17. __date__ = 'Thu Sep 13 23:01:23 2012'
  18. __version__ = '0.1'
  19.  
  20.  
  21.  
  22. import matplotlib.pyplot as plt  # plt.plot(x,y)  plt.show()
  23. import cv2
  24. import time
  25.  
  26.  
  27.  
  28. def test_feature_detector(detector, imfname):
  29.     image = cv2.imread(imfname)
  30.     forb = cv2.FeatureDetector_create(detector)
  31.     # Detect crashes program if image is not greyscale
  32.     t1 = time.time()
  33.     kpts = forb.detect(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY))
  34.     t2 = time.time()
  35.     print detector, 'number of KeyPoint objects', len(kpts), '(time', t2-t1, ')'
  36.  
  37.     return kpts
  38.  
  39.  
  40. def main():
  41.     imfname = r'_______.bmp'
  42.  
  43.  
  44.     detector_format = ["","Grid","Pyramid"]
  45.     # "Dense" and "SimpleBlob" omitted because they caused the program to crash
  46.     detector_types = ["FAST","STAR","SIFT","SURF","ORB","MSER","GFTT","HARRIS"]
  47.  
  48.  
  49.     for form in detector_format:
  50.         for detector in detector_types:
  51.             kpts = test_feature_detector(form + detector, imfname)
  52.  
  53.             # KeyPoint class: angle, class_id, octave, pt, response, size
  54.             plt.figure(form + detector)
  55.             for k in kpts:
  56.                 x,y = k.pt
  57.                 plt.plot(x,-y,'ro')
  58.             plt.axis('equal')
  59.  
  60.     plt.show()
  61.  
  62.  
  63. if __name__ == '__main__':
  64.     main()
Advertisement
Add Comment
Please, Sign In to add comment