image_output_1.png
import cv2

import matplotlib.pyplot as plt

import numpy as np

path = '/kaggle/input/sports-image-dataset/data/badminton/00000052.jpg'
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.axis('off')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plt.axis('off')

canny = cv2.Canny(gray, 100, 200)
plt.axis('off')

edges = cv2.Canny(gray, 100, 200, apertureSize=3)
lines = cv2.HoughLines(edges, rho=1, theta=np.pi / 180, threshold=150)
for line in lines:
    rho, theta = line[0]
    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), (255, 255, 0), 3)
plt.imshow(img)
plt.axis('off')
plt.show()