cornerData.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os
  2. import cv2
  3. import numpy as np
  4. import utils
  5. def argsProcessor():
  6. import argparse
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument("-i", "--dataPath", help="DataPath")
  9. parser.add_argument("-o", "--outputFiles", help="outputFiles", default="bar")
  10. return parser.parse_args()
  11. args = argsProcessor()
  12. output_dir = args.outputFiles
  13. if (not os.path.isdir(output_dir)):
  14. os.mkdir(output_dir)
  15. dir = args.dataPath
  16. import csv
  17. with open(output_dir+"/gt.csv", 'a') as csvfile:
  18. spamwriter_1 = csv.writer(csvfile, delimiter=',',
  19. quotechar='|', quoting=csv.QUOTE_MINIMAL)
  20. for image in os.listdir(dir):
  21. if image.endswith("jpg"):
  22. if os.path.isfile(dir+"/"+image+".csv"):
  23. with open(dir+"/"+image+ ".csv", 'r') as csvfile:
  24. spamwriter = csv.reader(csvfile, delimiter=' ',
  25. quotechar='|', quoting=csv.QUOTE_MINIMAL)
  26. img = cv2.imread(dir +"/"+ image)
  27. print (image)
  28. gt= []
  29. for row in spamwriter:
  30. gt.append(row)
  31. # img = cv2.circle(img, (int(float(row[0])), int(float(row[1]))), 2,(255,0,0),90)
  32. gt =np.array(gt).astype(np.float32)
  33. # print gt
  34. gt = gt / (img.shape[1], img.shape[0])
  35. gt = gt * (1080, 1080)
  36. img = cv2.resize(img, ( 1080,1080))
  37. # for a in range(0,4):
  38. # img = cv2.circle(img, tuple((gt[a].astype(int))), 2, (255, 0, 0), 9)
  39. # cv2.imwrite("asda.jpg", img)
  40. # 0/0
  41. for angle in range(0,271,90):
  42. img_rotate, gt_rotate = utils.rotate(img, gt, angle)
  43. for random_crop in range(0,16):
  44. img_list, gt_list = utils.getCorners(img_rotate, gt_rotate)
  45. for a in range(0,4):
  46. print (gt_list[a])
  47. gt_store = list(np.array(gt_list[a])/(300,300))
  48. img_store = cv2.resize(img_list[a], (64,64))
  49. print (tuple(list(np.array(gt_store)*64)))
  50. # cv2.circle(img_store, tuple(list((np.array(gt_store)*64).astype(int))), 2, (255, 0, 0), 2)
  51. cv2.imwrite( output_dir+"/"+image + str(angle) +str(random_crop) + str(a) +".jpg", img_store)
  52. spamwriter_1.writerow(( image + str(angle) +str(random_crop) + str(a) +".jpg", tuple(gt_store)))