Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # cut nasal pattern
- def cutNasalPattern(linha, image):
- linha = linha.split(",")
- if len(linha) == 9:
- x1 = int(linha[1])
- y1 = int(linha[2])
- w1 = int(linha[3])
- h1 = int(linha[4])
- x2 = int(linha[5])
- y2 = int(linha[6])
- w2 = int(linha[7])
- h2 = int(linha[8])
- x_esq = min(x1 + w1, x2 + w2)
- x_dir = max(x1, x2)
- ye = y1+0.4*h1
- yd = y2+0.4*h2
- if x1 > x2:
- ye, yd = yd, ye
- # rotacao
- if abs(ye-yd) > 5:
- v1 = [1, 0]
- v2 = [x_dir-x_esq, yd-ye]
- dim = int(np.linalg.norm(v2))
- v2 = v2/np.linalg.norm(v2)
- theta = np.arctan2(np.linalg.norm(np.cross(v1, v2)), np.dot(v1,v2))
- if yd < ye:
- theta = -theta
- ct = np.cos(theta)
- st = np.sin(theta)
- M = np.array([[ct, st, (1-ct)*x_esq - st*ye],
- [-st, ct, st*x_esq + (1-ct)*ye]])
- sy, sx = np.shape(image)[:2]
- image = cv2.warpAffine(image, M, dsize=(sx, sy))
- y_top = int(ye)
- y_bot = y_top+dim
- x_dir = x_esq+dim
- else:
- dim = x_dir - x_esq
- y_top = int((y1 + 0.4 * h1 + y2 + 0.4 * h2) / 2)
- y_bot = y_top + dim
- if y_top < y_bot and x_esq < x_dir:
- roi = image[y_top : y_bot, x_esq : x_dir]
- cv2.imwrite("results/YOLO_nasalpattern/" + linha[0], roi)
- coords_file.write("%s,%d,%d,%d,%d\n" % (linha[0], x_esq, y_top, x_dir, y_bot))
Advertisement
Add Comment
Please, Sign In to add comment