How do I detect the curvy lines in OpenCV?
I am new in OpenCV and I would like to detect the curvy lines in an image. I tried Hough Transformation, but it detects only the straight line. I want to detect a line something similar to this, but not as curvy as this
Thank you very much!
Regards
EDIT 1:
import numpy as np
import cv2
# Read the main image
inputImage = cv2.imread("input.png")
# Convert it to grayscale
inputImageGray = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
# Line Detection
edges = cv2.Canny(inputImageGray,100,200,apertureSize = 3)
minLineLength = 500
maxLineGap = 5
lines = cv2.HoughLinesP(edges,1,np.pi/180,90,minLineLength,maxLineGap)
for x in range(0, len(lines)):
for x1,y1,x2,y2 in lines[x]:
cv2.line(inputImage,(x1,y1),(x2,y2),(0,128,0),2)
cv2.putText(inputImage,"Tracks Detected", (500,250), font, 0.5, 255)
# Show result
cv2.imshow("Trolley_Problem_Result", inputImage)
This is my code, and the output of this code is (the green line in the image is the result):
As you can see, the curved tracks are not detected properly. If I increase the threshold value, it detects the lines on the tram (it's detecting now too) and also on the humans.
What do you suggest, so that I can improve the code and detect the curved tracks as well?
Thanks a lot :)
Regards
a curve is not a line. an there's nothing builtin specially to detect curves.
is it always the same curve ? you have to tell us more about the constraints.
Skeletonization (thinning) will give you a single-pixel-wide version of the curved line. Is that what you're looking for?
See: http://answers.opencv.org/question/18...
@berak: It's not always the same curve, but in general curves (what I mean it is always not a straight line). I want to detect the lines given in the image (http://nymag.com/selectall/2016/08/tr...). It's called Trolley Problem
detect always means: "something specific".
you still have to be more clear.
I want to detect the line given in the link (http://nymag.com/selectall/2016/08/tr...).
Use
cv2.HoughLinesP
. Then applycv2.HOUGH_PROBABILISTIC
.Hi @supra56, thank you very much. It almost works. I applied cv2.HoughLinesP, but I don't get it what you mean by cv2.HOUGH_PROBABILISTIC? It is one of the methods of cv2.houghlines, isn't it?
@Riya208. I used this for detected road lane.
lines = cv2.HoughLinesP(thresh, cv2.HOUGH_PROBABILISTIC, np.pi/180, 90, minLineLength = 50, maxLineGap = 2)
Don't usecv2.houghlines
For better result usecv2.polylines
.import numpy as np import cv2
@supra56 Thanks a ton!