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.

56 lines
1.1 KiB

  1. import cv2
  2. import json
  3. rects = []
  4. im = cv2.imread("parking_images/main.jpg")
  5. if __name__ == '__main__' :
  6. while(True):
  7. scale_percent = 50
  8. width = int(im.shape[1] * scale_percent / 100)
  9. height = int(im.shape[0] * scale_percent / 100)
  10. # Select ROI
  11. fromCenter = False
  12. r = cv2.selectROI(cv2.resize(im,(width,height)))
  13. # Crop image
  14. if(r == (0,0,0,0)):
  15. cv2.destroyAllWindows()
  16. break
  17. imCrop = im[int(r[1]*100/scale_percent):int(r[1]*100/scale_percent+r[3]*100/scale_percent), int(r[0]*100/scale_percent):int(r[0]*100/scale_percent+r[2]*100/scale_percent)]
  18. # Display cropped image
  19. cv2.imshow("Image", imCrop)
  20. cv2.waitKey(0)
  21. cv2.destroyAllWindows()
  22. rects.append([])
  23. print(rects[len(rects)-1])
  24. for i in r:
  25. rects[len(rects)-1].append(int(i)*int(100/scale_percent))
  26. print(rects)
  27. locs = {}
  28. for i in range(len(rects)):
  29. loc = rects[i]
  30. locs[str(i)] = {
  31. "x1": loc[0],
  32. "y1": loc[1],
  33. "x2": loc[0]+loc[2],
  34. "y2": loc[1]+loc[3],
  35. "priority":i
  36. }
  37. with open("databases/locations.json","w") as f:
  38. f.write(json.dumps(locs,indent=4))