简体   繁体   English

使用opencv查找水平线和垂直线

[英]Finding horizontal and vertical lines using opencv

I am trying to pull the horizontal and vertical lines out of an image, to use them to find the points at which they intersect.我试图从图像中拉出水平线和垂直线,用它们来找到它们相交的点。 I am using this page as a reference, but I think the problem is with the opencv object that I am not understanding.我使用这个页面作为参考,但我认为问题出在我不理解的 opencv 对象上。 This reference is written in C++ but I am doing it in Python.该参考文献是用 C++ 编写的,但我是用 Python 编写的。 When I display the horizontal image, I just have a completely black screen, although I should have an image of only the horizontal lines.当我显示水平图像时,我只有一个全黑的屏幕,尽管我应该只有水平线的图像。 Would anyone know what I am doing incorrectly?有谁知道我做错了什么?

Reference: https://docs.opencv.org/3.2.0/d1/dee/tutorial_moprh_lines_detection.html参考: https : //docs.opencv.org/3.2.0/d1/dee/tutorial_moprh_lines_detection.html

Code:代码:

import cv2
import numpy as np
img = cv2.imread('msss.png')
blur_img = cv2.GaussianBlur(img, (5, 5), 0)
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('image', gray_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
height, width = gray_img.shape
horizontal = gray_img.copy()
horizontal_size = int(width/30)
horizontal_struct = cv2.getStructuringElement(cv2.MORPH_RECT, 
                                             (horizontal_size, 1))
horizontal = cv2.erode(horizontal, horizontal, horizontal_struct, (-1, -1))
horizontal = cv2.dilate(horizontal, horizontal, horizontal_struct, (-1, -1))
cv2.imshow('image', horizontal)
cv2.waitKey(0)
cv2.destroyAllWindows()

Humm, seems that you are looking for how to identify corners.嗯,看来您正在寻找如何识别角落。 If yes you could try this reference already in python:如果是,你可以在 python 中尝试这个参考:

http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_shi_tomasi/py_shi_tomasi.html http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_shi_tomasi/py_shi_tomasi.html

Obs.: the link you provided is about morphological transformations.观察:您提供的链接是关于形态变换的。 What they say "extract" is a reference for change the image such way those lines disappear without providing any reference of the lines coordinates.他们所说的“提取”是更改图像的参考,使这些线条消失而不提供任何线条坐标参考。 Usually these transformations are useful to make the image less noisily and help the next steps, like image segmentation, more easy.通常,这些变换有助于降低图像的噪声,并帮助后续步骤(如图像分割)更容易。

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

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