简体   繁体   English

检查两个端点之间是否有线,opencv

[英]Check if there is line between two end points or not, opencv

I am using opencv to detect shapes, I have to detect a shape like this 我正在使用opencv检测形状,我必须检测这样的形状 在此处输入图片说明

this will be a hand drawn picture, and i am using kinect to detect the picture by checking on frames. 这将是一幅手绘图片,我正在使用kinect通过检查帧来检测图片。 Now I get 6 points for these kind of pictures, by removing noise, edge detection, finding contours and than approxDP, now I am not able to detect the shape is right faced, left face, down or up. 现在,通过去除噪声,边缘检测,找到轮廓以及比大约DP,这些图片得到6分,而现在我无法检测到形状是右面,左面,向下还是向上。 As the points location change for each picture. 随着点位置的变化,每张图片都会改变。

So I want to know given two points, how can I check if there is a line segment between the points or not. 所以我想知道给定的两个点,如何检查两个点之间是否有线段。 After getting there two points, I can calculate from remaining points position that where is the shape pointing. 在到达两个点之后,我可以从剩余点位置计算出形状指向的位置。

If anyone has better solution, please share. 如果有人有更好的解决方案,请分享。

Assume you have two endpoints, and your line segment have pixel value greater than zero(in the above image you may need to use threshold binary inverted). 假设您有两个端点,并且线段的像素值大于零(在上图中,您可能需要使用阈值二进制倒置)。

  1. Create a mask image by drawing the line with thickness=1 pixel. 通过绘制粗细为1像素的线来创建蒙版图像。

  2. Copy the source image to new Mat using above Mask. 使用上面的蒙版将源图像复制到新的Mat。

  3. Now count non-zero pixel in the resultant Mat, 现在计算结果Mat中的非零像素,

    • if it is zero there is no line between the points, 如果为零,则点之间没有线,
    • and if the count non-zero gives a value you can cross-check it by comparing with the length of line you drawn in mask. 如果非零计数给出一个值,您可以通过与在蒙版中绘制的线的长度进行比较来进行交叉检查。

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

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