Ask Your Question
0

Extract and detect line

asked Apr 20 '19

colx gravatar image

I need to extract a red laser line on an object from an image with python. I want to use the shape of the line to determine if the object is flat or tapered, and if it's tapered, on which side. In what way can I do it, can you post some example code?

laser line image

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Apr 24 '19

OpenCV has great tools to solve this. Extract the red channel from the color image (2nd image below). Threshold this image with a threshold value of about 220 (3rd image below). Do a couple rounds of dilation to fill in holes left by threshold (4th image below) After this, get the contours and pick out the top one (smallest center y value). Divide this top contour in half to get 2 contours - a left side and a right side. Then look at the aspect ratios of these 2 contours. A flat line will have a larger wd/ht ratio.

image description

Preview: (hide)

Comments

Thank you very much, I'm going to do code tests in python, I post it when I have an advance

colx gravatar imagecolx (Apr 24 '19)edit

Do you have python code for this

Raghunath gravatar imageRaghunath (May 28 '19)edit

No, these results came from another, larger c++ program

Chris gravatar imageChris (May 31 '19)edit

Chris Here is my python code Could you share c++ program so that i will convert to python if anything missing. I know c++ opencv too

Raghunath gravatar imageRaghunath (May 31 '19)edit

Question Tools

1 follower

Stats

Asked: Apr 20 '19

Seen: 2,729 times

Last updated: Apr 24 '19