it is my code and I'm trying to edge detection using the sobel method. But I'm getting neither error nor image.If I have a mistake, can you explain where it is?
import cv2
import numpy as np
img=cv2.imread("lena.jpg")
img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
m,n=img.shape
kernelx=np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])
kernely=np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
gx=np.zeros((m,n), dtype=np.int32)
gy=np.zeros((m,n), dtype=np.int32)
for x in range(1,m-1):
for y in range(1,n-1):
for a in range(3):
for b in range(3):
xn = x + a - 1
yn = y + b - 1
gx=gx+(kernelx[a][b]*img[xn][yn])
gy=gy+(kernely[a][b]*img[xn][yn])
final_image=np.sqrt(pow(gx,2.0)+pow(gy,2.0))
cv2.imshow("a",final_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
imshowthat displays any image (without trying to do edge detection on top)?