I am trying to detect edges on this lane image. First blurred the image using Gaussian filter and applied Canny edge detection but it gives only blank image without detecting edges.
I have done like this:
JavaScript
x
17
17
1
#imports
2
import matplotlib.pyplot as plt
3
import numpy as np
4
import cv2
5
import matplotlib.image as mpimg
6
7
image= mpimg.imread("Screenshot from Lane Detection Test Video 01.mp4.png")
8
image = image[:,:,:3]
9
image_g = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
10
11
image_blurred = cv2.GaussianBlur(image_g, (3, 3), 0)
12
threshold_low = 50
13
threshold_high = 100
14
image_blurred = image_blurred.astype(np.uint8)
15
image_canny = cv2.Canny(image_blurred, threshold_low, threshold_high)
16
plt.imshow(image_canny,cmap='gray')
17
Advertisement
Answer
You should always examine your data. Simply running your script step by step and examining intermediate values shows what is going wrong: mpimg.imread
reads the image as a floating-point array with values between 0 and 1. After blurring, you cast it to uint8
, which sets almost all values to 0. Simply multiplying the image by 255 at some point before casting to uint8
solves your issue.