|
|
@@ -0,0 +1,36 @@ |
|
|
|
import cv2 |
|
|
|
import numpy as np |
|
|
|
import math |
|
|
|
|
|
|
|
def calcX(p3x, p3y, A, B, y): |
|
|
|
return int(p3x - ((p3y - y) * A / B)) |
|
|
|
|
|
|
|
def calcY(p3y, A, B, L): |
|
|
|
a = L * B |
|
|
|
b = (A * A) + (B * B) |
|
|
|
return int((a / math.sqrt(b)) + p3y) |
|
|
|
|
|
|
|
img = np.zeros((600, 600, 3), dtype = int) |
|
|
|
img = np.array(img,dtype='uint8') |
|
|
|
|
|
|
|
point1 = (100,230) |
|
|
|
point2 = (520,320) |
|
|
|
point3 = (500,200) |
|
|
|
|
|
|
|
cv2.line(img, point1, point2, (0,0,255), 1) |
|
|
|
cv2.circle(img, point3, 3, (0,255,0), -1) |
|
|
|
cv2.imshow('img1', img) |
|
|
|
|
|
|
|
p1x, p1y = point1 |
|
|
|
p2x, p2y = point2 |
|
|
|
p3x, p3y = point3 |
|
|
|
|
|
|
|
A = p1x - p2x |
|
|
|
B = p1y - p2y |
|
|
|
|
|
|
|
y = calcY(p3y, A, B, 400) |
|
|
|
x = calcX(p3x, p3y, A, B, y) |
|
|
|
cv2.line(img, point3, (x, y), (255, 0, 0), 1) |
|
|
|
cv2.imshow('img2', img) |
|
|
|
|
|
|
|
cv2.waitKey(0) |