You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import cv2
  2. import time
  3. import argparse
  4. parser = argparse.ArgumentParser(description='Test yolo data.')
  5. parser.add_argument('-i', help='Image', dest='img', required=True)
  6. parser.add_argument('-t', help='Yolo text file', dest='txt',required=True)
  7. args = parser.parse_args()
  8. frame = cv2.imread(args.img)
  9. cv2.namedWindow("f", cv2.WINDOW_NORMAL);
  10. coordinates = []
  11. with open(args.txt, "r") as lines:
  12. for line in lines:
  13. hT, wT, cT = frame.shape
  14. coordinates = line.rstrip('\n').split(' ')
  15. idx = coordinates[0]
  16. x1, y1,w2,h2 = float(coordinates[1]), float(coordinates[2]), float(coordinates[3]), float(coordinates[4])
  17. print(x1,y1,w2,h2)
  18. w, h = int(w2 * wT), int(h2 * hT)
  19. x, y = int((x1 * wT) - w / 2), int((y1 * hT) - h / 2)
  20. # # 0 1 2 3 x1 - центр по x в процентах y1- центр по y в процентах w2- центр по w в процентах h2- центр по h в процентах
  21. cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,255), 2)
  22. cv2.putText(frame,str(idx), (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (128, 0, 255), 2)
  23. cv2.imshow("f", frame)
  24. cv2.waitKey(0)
  25. # import cv2
  26. # import time
  27. # import argparse
  28. # import numpy as np
  29. # import matplotlib.pyplot as plt
  30. # parser = argparse.ArgumentParser(description='Test yolo data.')
  31. # parser.add_argument('-i', help='Image', dest='img', required=True)
  32. # parser.add_argument('-t', help='Yolo text file', dest='txt',required=True)
  33. # parser.add_argument('-l', help='labels txt file', dest='label',required=True)
  34. # args = parser.parse_args()
  35. # frame = cv2.imread(args.img)
  36. # cv2.namedWindow("f", cv2.WINDOW_NORMAL);
  37. # coordinates = []
  38. # with open(args.txt, "r") as lines:
  39. # for line in lines:
  40. # hT, wT, cT = frame.shape
  41. # coordinates = line.rstrip('\n').split(' ')
  42. # idx = coordinates[0]
  43. # x1, y1,w2,h2 = float(coordinates[1]), float(coordinates[2]), float(coordinates[3]), float(coordinates[4])
  44. # print(x1,y1,w2,h2)
  45. # cmap = plt.get_cmap('tab20b')
  46. # colors = [cmap(i)[:3] for i in np.linspace(0, 1, 20)]
  47. # color = colors[int(idx) % len(colors)]
  48. # color = [i * 255 for i in color]
  49. # w, h = int(w2 * wT), int(h2 * hT)
  50. # x, y = int((x1 * wT) - w / 2), int((y1 * hT) - h / 2)
  51. # with open(args.label, "r") as labels:
  52. # classNames = labels.read().rstrip('\n').split('\n')
  53. # # # 0 1 2 3 x1 - центр по x в процентах y1- центр по y в процентах w2- центр по w в процентах h2- центр по h в процентах
  54. # cv2.rectangle(frame, (x,y), (x+w, y+h), color,3)
  55. # print(len(classNames[1]))
  56. # cv2.rectangle(frame, (x,y-30), (x+len(classNames[int(idx)]*15), y), color,-1)
  57. # cv2.putText(frame,str(classNames[int(idx)]), (x+4, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
  58. # cv2.imshow("f", frame)
  59. # cv2.waitKey(0)