|
@@ -10,12 +10,20 @@ def calcY(p3y, A, B, L): |
|
|
b = (A * A) + (B * B) |
|
|
b = (A * A) + (B * B) |
|
|
return int((a / math.sqrt(b)) + p3y) |
|
|
return int((a / math.sqrt(b)) + p3y) |
|
|
|
|
|
|
|
|
|
|
|
def calcCollinearX(line, p3y): |
|
|
|
|
|
p1x, p1y, p2x, p2y = line |
|
|
|
|
|
return int(((p3y - p2y) * p1x + (p1y - p3y) * p2x) / (p1y - p2y)) |
|
|
|
|
|
|
|
|
|
|
|
def calcCollinearY(line, p3x): |
|
|
|
|
|
p1x, p1y, p2x, p2y = line |
|
|
|
|
|
return int(((p3x - p1x) * p2y + (p2x - p3x) * p1y) / (p2x - p1x)) |
|
|
|
|
|
|
|
|
img = np.zeros((600, 600, 3), dtype = int) |
|
|
img = np.zeros((600, 600, 3), dtype = int) |
|
|
img = np.array(img,dtype='uint8') |
|
|
img = np.array(img,dtype='uint8') |
|
|
|
|
|
|
|
|
point1 = (100,230) |
|
|
|
|
|
point2 = (520,320) |
|
|
|
|
|
point3 = (500,200) |
|
|
|
|
|
|
|
|
point1 = (100,100) |
|
|
|
|
|
point2 = (500,500) |
|
|
|
|
|
point3 = (360,320) |
|
|
|
|
|
|
|
|
cv2.line(img, point1, point2, (0,0,255), 1) |
|
|
cv2.line(img, point1, point2, (0,0,255), 1) |
|
|
cv2.circle(img, point3, 3, (0,255,0), -1) |
|
|
cv2.circle(img, point3, 3, (0,255,0), -1) |
|
@@ -27,10 +35,23 @@ p3x, p3y = point3 |
|
|
|
|
|
|
|
|
A = p1x - p2x |
|
|
A = p1x - p2x |
|
|
B = p1y - p2y |
|
|
B = p1y - p2y |
|
|
|
|
|
L = 100 |
|
|
|
|
|
|
|
|
y = calcY(p3y, A, B, 400) |
|
|
|
|
|
|
|
|
y = calcY(p3y, A, B, L) |
|
|
x = calcX(p3x, p3y, A, B, y) |
|
|
x = calcX(p3x, p3y, A, B, y) |
|
|
cv2.line(img, point3, (x, y), (255, 0, 0), 1) |
|
|
|
|
|
|
|
|
point4 = (x, y) |
|
|
|
|
|
cv2.circle(img, point4, 3, (255,255,0), -1) |
|
|
|
|
|
cv2.line(img, point3, point4, (255, 0, 0), 1) |
|
|
|
|
|
|
|
|
|
|
|
n3_y = point3[1] |
|
|
|
|
|
n3_x = calcCollinearX((*point1, *point2), n3_y) |
|
|
|
|
|
n4_x = point4[0] |
|
|
|
|
|
n4_y = calcCollinearY((*point1, *point2), n4_x) |
|
|
|
|
|
cv2.circle(img, (n3_x, n3_y), 3, (0,255,0), -1) |
|
|
|
|
|
cv2.circle(img, (n4_x, n4_y), 3, (255,255,0), -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv2.imshow('img2', img) |
|
|
cv2.imshow('img2', img) |
|
|
|
|
|
|
|
|
cv2.waitKey(0) |
|
|
cv2.waitKey(0) |