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

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