1 import sys
2 import cv2
3 import numpy as np
4 import math as m
5 def line_solver(m1, m3, point1, point2):
6 x1, y1 = point1
7 x3, y3 = point2
8 x = (m3 * x3 - m1 * x1 + y1 - y3) / (m3 - m1)
9 y = (m3 * y1 - m1 * y3 + m1 * m3 * (x3 - x1)) / (m3 - m1)
10 return x, y
11 def those_point(diag, sorted_details):
12 for file in diag:
13 slope = file[0]
14 for i in range(1, 3):
15 x1, y1 = file[i]
16 count = 0
17 for j in range(0, 4):
18 for k in range(1, 3):
19 x, y = sorted_details[j][k]
20 val = slope * (y) + x - slope * (y1) - x1
21 if val > 0:
22 count = count + 1
23 elif val < 0:
24 count = count - 1
25 if count == 8 or count == -8:
26 return [(x1, y1), file]
27 def arrow_sep_bycolor(source):
28 hsv = cv2.cvtColor(source, cv2.COLOR_BGR2HSV)
29 lower_hsv = np.array([0, 0, 160])
30 upper_hsv = np.array([40, 255, 255])
31 mask = cv2.inRange(hsv, lower_hsv, upper_hsv)
32 result = cv2.bitwise_and(hsv, hsv, mask=mask)
33 re = cv2.cvtColor(result, cv2.COLOR_HSV2BGR)
34 return re