简体   繁体   中英

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 在此处输入图片说明

this will be a hand drawn picture, and i am using kinect to detect the picture by checking on frames. 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. 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.

  2. Copy the source image to new Mat using above Mask.

  3. Now count non-zero pixel in the resultant 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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