Advertisement
shalivitalya

Untitled

Apr 9th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.65 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. import threading
  7. from threading import Thread
  8. ans = list()
  9. URL = 'https://api.arstand-lab.ru'
  10.  
  11. token = 'Token 581314b5dc6db4dd928dc249bf390affbec4df75'
  12. HEADERS = {'Authorization': token,
  13.            'Content-Type': 'application/json'}
  14. z=0
  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.     z = 0
  42.     for t in range(len(test['markers'])):
  43.         rows = test['markers'][t].shape[0]
  44.         circles = cv2.HoughCircles(test['markers'][t], cv2.HOUGH_GRADIENT, 1, rows / 8,
  45.                                        param1=80, param2=30,
  46.                                        minRadius=1, maxRadius=40)
  47.         r = 0
  48.         if circles is not None:
  49.             circles = np.uint16(np.around(circles))
  50.             for i in circles[0, :]:
  51.                 center = (i[0], i[1])
  52.                     # circle center
  53.                     # circle outline
  54.                 radius = i[2]
  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.         (h, w) = test['markers'][t].shape[:2]
  64.         center = (w / 2, h / 2)
  65.         M = cv2.getRotationMatrix2D(center, r, 1.0)
  66.         rotated = cv2.warpAffine(test['markers'][t], M, (w, h))
  67.         s1 = 0
  68.         id = 0
  69.         ret, im_bw1 = cv2.threshold(cv2.medianBlur(rotated, 9), 127, 255, 0)
  70.         for g in range(7):
  71.             s = 0
  72.             # im_bw1 = cv2.medianBlur(data['data'][i],5)
  73.             # ret, im_bw1 = cv2.threshold(im_bw1, 110, 255, 0)
  74.             ret, im_bw2 = cv2.threshold(cv2.medianBlur(data['data'][g], 9), 127, 255, 0)
  75.             s = np.sum(np.equal(im_bw1,im_bw2))
  76.             if s > s1:
  77.                 s1 = s
  78.                 id = data['ids'][g]
  79.         ans.append([test['coords'][t][0], test['coords'][t][1], id])
  80. print('POST ids successful: ', post_ids())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement