How can I detect the white lines alone from the above image using opencv python? which method can I use? or is there any inbuilt function available for this purpose?
Hough's didn't work well on this case.
The final output should like these:

How can I detect the white lines alone from the above image using opencv python? which method can I use? or is there any inbuilt function available for this purpose?
Hough's didn't work well on this case.
The final output should like these:

It seems like Hough's does actually do a good job. I took the example shown here and introduced only a small modification for the extraction of edges:
Load image and convert to grayscale:
import numpy as np
import cv2
import scipy.ndimage as ndi
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Then I applied a median filter to get rid of some high frequency edges/noise like the net in the image:
smooth = ndi.filters.median_filter(gray, size=2)
Then I applied a simple threshold to extract the white lines. Alternatively, you could apply e.g. a Laplace filter to extract edges, however, simple thresholding will neglect e.g. the horizontal line at the back of the tennis court:
edges = smooth > 180
Then perform the Hough line transform similar to this example.
lines = cv2.HoughLines(edges.astype(np.uint8), 0.5, np.pi/180, 120)
for rho,theta in lines[0]:
print(rho, theta)
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
# Show the result
cv2.imshow("Line Detection", img)
You can play around with the accuracies and modify the result. I ended up choosing the parameters 0.5 and 120. Overall result: