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.

58 lines
1.1 KiB

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