简体   繁体   English

Opencv 线长检测

[英]Opencv Line Length Detection

我需要一个示例代码的帮助,该代码使用 python 语言来获取上传图像的垂直和水平线的长度。

Didn't got your question correctly.没有正确回答你的问题。 But here is something according to my understanding.但根据我的理解,这里有一些东西。 First, detect the lines: Line detection using OpenCV Second, use the formula to calculate the distance between two points: length = norm(p2 - p1) where p1(x1,y1) and p2(x2,y2) Note: It will calculate length in pixels.首先,检测线: 使用OpenCV检测线其次,使用公式计算两点之间的距离:length = norm(p2 - p1) where p1(x1,y1) and p2(x2,y2) 注意:它会计算以像素为单位的长度。

You can use cv2.findContours and cv2.approxPolyDP.您可以使用 cv2.findContours 和 cv2.approxPolyDP。 This will get you a list of rectangles, then you can analyse if they are vertical or horizontal.这将为您提供一个矩形列表,然后您可以分析它们是垂直的还是水平的。

Some info: https://docs.opencv.org/3.1.0/d4/d73/tutorial_py_contours_begin.html https://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html一些信息: https : //docs.opencv.org/3.1.0/d4/d73/tutorial_py_contours_begin.html https://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM