Advertisement
shalivitalya

Untitled

Apr 9th, 2020
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. import math
  4. import matplotlib.pyplot as plt
  5. import requests
  6.  
  7. URL = 'https://api.arstand-lab.ru'
  8. token = 'Token 581314b5dc6db4dd928dc249bf390affbec4df75'
  9. HEADERS = {'Authorization': token}
  10.  
  11.  
  12. def get_field():
  13.     res = requests.get(f'{URL}/api/0/task/get_task/field_projection',
  14.                        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.         print(res)
  21.         return False
  22.  
  23.  
  24. def post_field(file_path):
  25.     files = {'answer': open(file_path, 'rb')}
  26.     res = requests.post(f'{URL}/api/0/task/check_task/field_projection',
  27.                         headers=HEADERS, files=files)
  28.     if res.ok:
  29.         return True
  30.     else:
  31.         print(res)
  32.         return False
  33.  
  34.  
  35. def getPoint(x,y,z,x1,y1,z1):
  36.     t = math.sqrt((x-x1)**2 + (y-y1)**2 + (z-z1)**2)
  37.     l = (x1 - x)/t
  38.     m = (y1 - y)/t
  39.     n = (z1 - z)/t
  40.     return -1*z*l/n, -1*z*m/n, 0
  41.  
  42.  
  43. dst = 's'
  44. arr = np.empty([3000, 240])
  45.  
  46. p = []
  47. Points = []
  48. MetaPoints = []
  49. if __name__ == '__main__':
  50.     loaded = np.load('file.npz')
  51.     x, y, z = loaded["projector"]
  52.     step = 5
  53.     for i in range(len(loaded['xyz_faces'])):
  54.         Points = list()
  55.         for j in range(4):
  56.             kekes = list()
  57.             np.save('example_1', loaded['xyz_faces'][i][j])
  58.             b = np.load('example_1.npy')
  59.             for v in range(len(b)):
  60.                 # print(b[v][0], b[v][1], b[v][2])
  61.                 x2, y2 = loaded['ij_coords'][i]
  62.                 print((x2 * step) + (step/2) + b[v][0], (y2 * step) + (step / 2) + b[v][1], b[v][2])
  63.                 print(x,y,z)
  64.                 x1, y1, z1 = getPoint(x, y, z, (x2 * step) + (step/2) + b[v][0], (y2 * step) + (step / 2) + b[v][1], b[v][2])
  65.  
  66.                 print(x1,y1,z1)
  67.                 b[v] = x1+20, y1+25, z1
  68.                 kekes.append(b[v])
  69.             Points.append(kekes)
  70.         MetaPoints.append(Points)
  71.     # print(MetaPoints)
  72.     for i in range(len(MetaPoints)):
  73.         for j in range(4):
  74.             # plt.imshow(loaded["face_img"][i][j])
  75.             # plt.show()
  76.             # loaded["img_coords"][i][j] = [i*60 for i in loaded["img_coords"][i][j]]
  77.             # print([[MetaPoints[i][j][1][0]*60,abs(MetaPoints[i][j][1][1]*60)],
  78.             # [MetaPoints[i][j][2][0]*60,abs(MetaPoints[i][j][2][1]*60)]])
  79.             # (h, w) = loaded["face_img"][i][j].shape[:2]
  80.             pts1 = np.float32(
  81.                 [loaded["img_coords"][i][j][0], loaded["img_coords"][i][j][1], loaded["img_coords"][i][j][2]])
  82.             pts2 = np.float32([[MetaPoints[i][j][0][0] * 60, abs(MetaPoints[i][j][0][1] * 60)],
  83.                                [MetaPoints[i][j][1][0] * 60, abs(MetaPoints[i][j][1][1] * 60)],
  84.                                [MetaPoints[i][j][2][0] * 60, abs(MetaPoints[i][j][2][1] * 60)]])
  85.             M = cv2.getAffineTransform(pts1, pts2)
  86.             if dst == 's':
  87.                 dst = cv2.warpAffine(np.array(loaded["face_img"][i][j], dtype='uint8'), M, (2400, 3000))
  88.             else:
  89.                 dst += cv2.warpAffine(np.array(loaded["face_img"][i][j], dtype='uint8'), M, (2400, 3000))
  90.             p.append(dst)
  91. np.savez("field_answer.npz", answer=dst)
  92. print('POST successful: ', post_field('field_answer.npz'))
  93. # (h, w) = loaded["face_img"][i][j].shape[:2]
  94. # pts1 = np.float32([[50,50],[200,50],[50,200]])
  95. # pts2 = np.float32([[10,100],[200,50],[100,250]])
  96.  
  97. # M = cv2.getAffineTransform(pts1,pts2)
  98. # dst = cv2.warpAffine(np.array(loaded["face_img"][i][j],dtype='uint8'),M,(h,w))
  99.  
  100. # PUT YOUR CODE HERE
  101. # print('POST successful: ', post_faces_projections_npz('/tmp/field_answer.npz'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement