Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import numpy as np
- import cv2
- import random
- import matplotlib.pyplot as plt
- ans = list()
- URL = 'https://api.arstand-lab.ru'
- token = 'Token 581314b5dc6db4dd928dc249bf390affbec4df75'
- HEADERS = {'Authorization': token,
- 'Content-Type': 'application/json'}
- z=0
- def get_markers():
- res = requests.get(f'{URL}/api/0/marker/get_markers/', headers=HEADERS)
- if res.ok:
- with open('file.npz', 'wb') as f:
- f.write(res.content)
- return True
- else:
- return False
- def post_ids():
- global ans
- content = {'markers': str(ans)}
- res = requests.post(f'{URL}/api/0/marker/check_markers/ids/',
- headers=HEADERS,
- json=content)
- if res.ok:
- return True
- else:
- return False
- if __name__ == '__main__':
- print('GET successful: ', get_markers())
- data = np.load('ss.npz')
- test = np.load("file.npz")
- for t in range(len(test['markers'])):
- # im_bw = cv2.medianBlur(test['markers'][t],5)
- # ret, im_bw = cv2.threshold(im_bw, 110, 255, 0)
- # im_bw = cv2.medianBlur(test['markers'][t], 7)
- # ret, im_bw = cv2.threshold(im_bw, 110, 255, 0)
- if z<35:
- rows = test['markers'][t].shape[0]
- circles = cv2.HoughCircles(test['markers'][t], cv2.HOUGH_GRADIENT, 1, rows / 8,
- param1=80, param2=30,
- minRadius=1, maxRadius=40)
- r = 0
- if circles is not None:
- circles = np.uint16(np.around(circles))
- for i in circles[0, :]:
- center = (i[0], i[1])
- # circle center
- # circle outline
- radius = i[2]
- if center[0] > 150 and center[1] > 150:
- r = 180
- elif center[0] < 150 and center[1] > 150:
- r = 270
- elif center[0] < 150 and center[1] < 150:
- r = 0
- else:
- r = 90
- (h, w) = test['markers'][t].shape[:2]
- center = (w / 2, h / 2)
- M = cv2.getRotationMatrix2D(center, r, 1.0)
- rotated = cv2.warpAffine(test['markers'][t], M, (w, h))
- s1 = 0
- id = 0
- for g in range(7):
- s = 0
- # im_bw1 = cv2.medianBlur(data['data'][i],5)
- # ret, im_bw1 = cv2.threshold(im_bw1, 110, 255, 0)
- ret, im_bw1 = cv2.threshold(cv2.medianBlur(rotated,9), 127, 255, 0)
- ret, im_bw2 = cv2.threshold(cv2.medianBlur(data['data'][g],9), 127, 255, 0)
- for y in np.equal(im_bw1 ,im_bw2):
- for j in y:
- s += int(j)
- if s > s1:
- s1 = s
- id = data['ids'][g]
- z+=1
- else:
- id = 5
- ans.append([test['coords'][t][0],test['coords'][t][1],id])
- print(len(ans))
- print('POST ids successful: ', post_ids())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement