'track detection in OpenCV 4.2.0 python
I am trying to detect the outer lines of a rc racetrack viewed from above. This is the original picture: Racetrack
I have tried to load the picture in greyscale and make a Canny transformation. After that I tried to find contours using the findContours module. then I displayed the contours on a black picture which looks like that: result
I have also tried it with threshholding but This doesn't detect all white lines because of a shadow on the picture.
Here is the code:
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('/path/to/image/Rennstrecke.jpg', 0)
dimensions = img.shape
cv.imshow('image', img)
cv.waitKey(0)
cv.destroyAllWindows()
edges = cv.Canny(img,100,200)
ret,th1 = cv.threshold(img,180,255,cv.THRESH_BINARY)
contours, hierachy = cv.findContours(edges,2,1)
print("number of contours " +str(len(contours)))
img1 = np.zeros((img.shape[0],img.shape[1],3), np.uint8)
cv.drawContours(img1, contours, -1, (200,200,100),3)
cv.imshow('image', img1)
cv.waitKey(0)
cv.destroyAllWindows()
print(cv.__version__)
I have also tried it with HoughlinesP, but this doesn't detect the curved lines.
Generally speaking I want to make a diagram of the racetrack and make a path in the middle, where a rc car should drive and the rc car should be detected, but this is another topic. At the moment my main priorites are to filter out the actual white lines of the track, make a diagram and process the center line of the track. I already searched for methods of filtering out contours, but I haven't found anything what suits my problem. I am new to openCV , so I apologize for things I might have overseen.
Does anyone have an idea how I can filter out the other contours?
I hope somebody can help me with this problem.
Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
