Advertisement
shalivitalya

Untitled

Apr 9th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. import requests
  2. import numpy as np
  3. import cv2
  4. import random
  5. import matplotlib.pyplot as plt
  6.  
  7. ans = list()
  8. URL = 'https://api.arstand-lab.ru'
  9.  
  10. token = 'Token 581314b5dc6db4dd928dc249bf390affbec4df75'
  11. HEADERS = {'Authorization': token,
  12.            'Content-Type': 'application/json'}
  13. z=0
  14.  
  15. def get_markers():
  16.     res = requests.get(f'{URL}/api/0/marker/get_markers/', headers=HEADERS)
  17.     if res.ok:
  18.         with open('file.npz', 'wb') as f:
  19.             f.write(res.content)
  20.         return True
  21.     else:
  22.         return False
  23.  
  24.  
  25. def post_ids():
  26.     global ans
  27.     content = {'markers': str(ans)}
  28.     res = requests.post(f'{URL}/api/0/marker/check_markers/ids/',
  29.                         headers=HEADERS,
  30.                         json=content)
  31.     if res.ok:
  32.         return True
  33.     else:
  34.         return False
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     print('GET successful: ', get_markers())
  39.     data = np.load('ss.npz')
  40.     test = np.load("file.npz")
  41.     for t in range(len(test['markers'])):
  42.         # im_bw = cv2.medianBlur(test['markers'][t],5)
  43.         # ret, im_bw = cv2.threshold(im_bw, 110, 255, 0)
  44.         # im_bw = cv2.medianBlur(test['markers'][t], 7)
  45.         # ret, im_bw = cv2.threshold(im_bw, 110, 255, 0)
  46.         if z<35:
  47.             rows = test['markers'][t].shape[0]
  48.             circles = cv2.HoughCircles(test['markers'][t], cv2.HOUGH_GRADIENT, 1, rows / 8,
  49.                                        param1=80, param2=30,
  50.                                        minRadius=1, maxRadius=40)
  51.             r = 0
  52.             if circles is not None:
  53.                 circles = np.uint16(np.around(circles))
  54.                 for i in circles[0, :]:
  55.                     center = (i[0], i[1])
  56.                     # circle center
  57.                     # circle outline
  58.                     radius = i[2]
  59.                 if center[0] > 150 and center[1] > 150:
  60.                     r = 180
  61.                 elif center[0] < 150 and center[1] > 150:
  62.                     r = 270
  63.                 elif center[0] < 150 and center[1] < 150:
  64.                     r = 0
  65.                 else:
  66.                     r = 90
  67.             (h, w) = test['markers'][t].shape[:2]
  68.             center = (w / 2, h / 2)
  69.             M = cv2.getRotationMatrix2D(center, r, 1.0)
  70.             rotated = cv2.warpAffine(test['markers'][t], M, (w, h))
  71.             s1 = 0
  72.             id = 0
  73.             for g in range(7):
  74.                 s = 0
  75.                 # im_bw1 = cv2.medianBlur(data['data'][i],5)
  76.                 # ret, im_bw1 = cv2.threshold(im_bw1, 110, 255, 0)
  77.                 ret, im_bw1 = cv2.threshold(cv2.medianBlur(rotated,9), 127, 255, 0)
  78.                 ret, im_bw2 = cv2.threshold(cv2.medianBlur(data['data'][g],9), 127, 255, 0)
  79.                 for y in np.equal(im_bw1 ,im_bw2):
  80.                     for j in y:
  81.                         s += int(j)
  82.                 if s > s1:
  83.                     s1 = s
  84.                     id = data['ids'][g]
  85.             z+=1
  86.         else:
  87.             id = 5
  88.         ans.append([test['coords'][t][0],test['coords'][t][1],id])
  89.     print(len(ans))
  90.     print('POST ids successful: ', post_ids())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement