opencv_traindata_rejector.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import cv2
00004 import sys
00005 import os
00006 
00007 def waitKeyInput():
00008     while True:
00009         k = cv2.waitKey(33)
00010         if k == 110:                      #n
00011             return False
00012         elif k == 121:                    #y
00013             return True
00014 
00015 def main():
00016     info = sys.argv[1]
00017     output = sys.argv[2]
00018     if not os.path.exists(info):
00019         raise Exception("failed to find %s" % info)
00020     with open(info, "r") as input_f:
00021         lines = input_f.readlines()
00022         cv2.namedWindow("image")
00023         results = []
00024         for line in lines:
00025             try:
00026                 (fname, num, x, y, width, height) = [c for c in line.split() 
00027                                                      if c and c.strip("\n ")]
00028                 x = int(x)
00029                 y = int(y)
00030                 width = int(width)
00031                 height = int(height)
00032                 if os.path.exists(fname):
00033                     print "Opening " + fname
00034                     img = cv2.imread(fname)
00035                     cv2.rectangle(img, (x, y), 
00036                                   (x + width, y + height),
00037                                   (0, 0, 255), 3)
00038                     cv2.imshow("image", img)
00039                     usep = waitKeyInput()
00040                     if usep:
00041                         results.append((fname, num, x, y, width, height))
00042             except:
00043                  pass
00044         with open(output, "w") as output_f:
00045              for result in results:
00046                  output_f.write("%s %d %d %d %d %d\n" % (result[0],
00047                                                          1,
00048                                                          result[2],
00049                                                          result[3],
00050                                                          result[4],
00051                                                          result[5]))
00052             
00053 if __name__ == "__main__":
00054     main()
00055     


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Sun Oct 8 2017 02:43:23