Advertisement
shalivitalya

Untitled

Apr 8th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. import requests
  2. import numpy as np
  3. import cv2
  4.  
  5.  
  6. URL = 'https://api.arstand-lab.ru'
  7.  
  8. token = 'Token 581314b5dc6db4dd928dc249bf390affbec4df75'
  9. HEADERS = {'Authorization': token,
  10.            'Content-Type': 'application/json'}
  11.  
  12.  
  13. def get_markers():
  14.     res = requests.get(f'{URL}/api/0/marker/get_markers/', headers=HEADERS)
  15.     if res.ok:
  16.         with open('file.npz', 'wb') as f:
  17.             f.write(res.content)
  18.         return True
  19.     else:
  20.         return False
  21.  
  22.  
  23. def post_rotation():
  24.     global Points
  25.     content = {'markers': str(Points)}
  26.     res = requests.post(f'{URL}/api/0/marker/check_markers/rotation/',
  27.                         headers=HEADERS,
  28.                         json=content)
  29.     print(res.content)
  30.     if res.ok:
  31.         return True
  32.     else:
  33.         return False
  34.  
  35.  
  36. if __name__ == '__main__':
  37.     print('GET successful: ', get_markers())
  38.     Points = list()
  39.     a = np.load("file.npz")
  40.     for t in range(len(a['markers'])):
  41.         im_bw = cv2.medianBlur(a['markers'][t], 5)
  42.         rows = im_bw.shape[0]
  43.         circles = cv2.HoughCircles(im_bw, cv2.HOUGH_GRADIENT, 1, rows / 8,
  44.                                    param1=100, param2=30,
  45.                                    minRadius=1, maxRadius=40)
  46.         if circles is not None:
  47.             circles = np.uint16(np.around(circles))
  48.             for i in circles[0, :]:
  49.                 center = (i[0], i[1])
  50.                 # circle center
  51.                 cv2.circle(im_bw, center, 1, (0, 100, 100), 3)
  52.                 # circle outline
  53.                 radius = i[2]
  54.                 cv2.circle(im_bw, center, radius, (255, 0, 255), 3)
  55.             if center[0] > 150 and center[1] > 150:
  56.                 r = 180
  57.             elif center[0] < 150 and center[1] > 150:
  58.                 r = 270
  59.             elif center[0] < 150 and center[1] < 150:
  60.                 r = 0
  61.             else:
  62.                 r = 90
  63.             Points.append(list((a['coords'][t][0], a['coords'][t][1], r)))
  64.     content = {'markers': str(Points)}
  65.     res = requests.post(f'{URL}/api/0/marker/check_markers/rotation/',
  66.                                 headers=HEADERS,
  67.                                 json=content)
  68.     print(Points)
  69.     print(res.content)
  70.     if res.ok:
  71.         print(True)
  72.     else:
  73.         print(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement