OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

identify lanes on 4 way traffic junction with opencv

  • Thread starter Thread starter Mohammed Fadil
  • Start date Start date
M

Mohammed Fadil

Guest
original image on the right and result on the left.I am in a computer vision project and I need to segment or divide the image of a 4 way traffic junction. I have tried but not getting an excellent result as I want the lanes to be identified and differentiated. This will help me in. The code snippet down is what I have. I need help please.

I am using Canny and Hough transform parameters. Below is my code:

Code:
import cv2
import numpy as np 

#Load the image
image = cv2.imread(r"C:\Users\NJOYA\Desktop\ROBOCOPS\4 lane 2.jpg")
#convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#apply edge detection
edges = cv2.Canny(gray, 100, 200)
edges = cv2.Canny(gray, 100, 200)
edges = cv2.Canny(gray, 150, 250)

#Trying different Hough tranform parameters 
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 30, minLineLength=50, maxLineGap=10)
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 50, minLineLength=100, maxLineGap=10)
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 70, minLineLength=150, maxLineGap=5)

#draw the detected lines on the original image
lane_regions = []
for line in lines:
    x1, y1, x2, y2, = line[0]
    cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0),2)
    lane_regions.append([(x1, y1), (x2, y2)])

num_lanes = len(lane_regions)
print(f"Number of lanes detected:{num_lanes}")

#display the resulting image
cv2.imshow("Lanes Detected", image)
cv2.waitKey(0)
cv2.destroyAllWindows
<p><a href="https://i.sstatic.net/pzkyOpfg.png" rel="nofollow noreferrer">original image on the right and result on the left.</a><a href="https://i.sstatic.net/oNgykwA4.png" rel="nofollow noreferrer"></a>I am in a computer vision project and I need to segment or divide the image of a 4 way traffic junction. I have tried but not getting an excellent result as I want the lanes to be identified and differentiated. This will help me in. The code snippet down is what I have. I need help please.</p>
<p>I am using Canny and Hough transform parameters. Below is my code:</p>
<pre><code>import cv2
import numpy as np

#Load the image
image = cv2.imread(r"C:\Users\NJOYA\Desktop\ROBOCOPS\4 lane 2.jpg")
#convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#apply edge detection
edges = cv2.Canny(gray, 100, 200)
edges = cv2.Canny(gray, 100, 200)
edges = cv2.Canny(gray, 150, 250)

#Trying different Hough tranform parameters
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 30, minLineLength=50, maxLineGap=10)
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 50, minLineLength=100, maxLineGap=10)
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 70, minLineLength=150, maxLineGap=5)

#draw the detected lines on the original image
lane_regions = []
for line in lines:
x1, y1, x2, y2, = line[0]
cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0),2)
lane_regions.append([(x1, y1), (x2, y2)])

num_lanes = len(lane_regions)
print(f"Number of lanes detected:{num_lanes}")

#display the resulting image
cv2.imshow("Lanes Detected", image)
cv2.waitKey(0)
cv2.destroyAllWindows
</code></pre>
 

Latest posts

M
Replies
0
Views
1
MOHAMED AMIIN ABDI AADAN
M
Top