From 78e145123ebfb2cdf66ad6a852776ed51c1d3471 Mon Sep 17 00:00:00 2001 From: lipeng Date: Fri, 7 Aug 2020 19:48:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BB=8F=E8=BF=87=E5=B7=B2?= =?UTF-8?q?=E7=9F=A5=E7=82=B9A=E4=B8=8E=E5=B7=B2=E7=9F=A5=E7=BA=BF?= =?UTF-8?q?=E6=AE=B5L=E5=B9=B3=E8=A1=8C=E7=9A=84=E7=BA=BF=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pythoncv_learn/calc_parallel_lines.py | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 图像识别CV/pythoncv_learn/calc_parallel_lines.py diff --git a/图像识别CV/pythoncv_learn/calc_parallel_lines.py b/图像识别CV/pythoncv_learn/calc_parallel_lines.py new file mode 100644 index 0000000..895c9f7 --- /dev/null +++ b/图像识别CV/pythoncv_learn/calc_parallel_lines.py @@ -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)