opencv_traindata_rejector.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import cv2
4 import sys
5 import os
6 
8  while True:
9  k = cv2.waitKey(33)
10  if k == 110: #n
11  return False
12  elif k == 121: #y
13  return True
14 
15 def main():
16  info = sys.argv[1]
17  output = sys.argv[2]
18  if not os.path.exists(info):
19  raise Exception("failed to find %s" % info)
20  with open(info, "r") as input_f:
21  lines = input_f.readlines()
22  cv2.namedWindow("image")
23  results = []
24  for line in lines:
25  try:
26  (fname, num, x, y, width, height) = [c for c in line.split()
27  if c and c.strip("\n ")]
28  x = int(x)
29  y = int(y)
30  width = int(width)
31  height = int(height)
32  if os.path.exists(fname):
33  print("Opening " + fname)
34  img = cv2.imread(fname)
35  cv2.rectangle(img, (x, y),
36  (x + width, y + height),
37  (0, 0, 255), 3)
38  cv2.imshow("image", img)
39  usep = waitKeyInput()
40  if usep:
41  results.append((fname, num, x, y, width, height))
42  except:
43  pass
44  with open(output, "w") as output_f:
45  for result in results:
46  output_f.write("%s %d %d %d %d %d\n" % (result[0],
47  1,
48  result[2],
49  result[3],
50  result[4],
51  result[5]))
52 
53 if __name__ == "__main__":
54  main()
55 


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Mon May 3 2021 03:03:27