在python opencv中实现用于边缘检测的Robert边缘算子

2024-09-30 14:38:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须使用Robert算子进行边缘检测。我正在使用Python+OpenCV

这是我想出的代码,我不确定这是否正确

img = cv2.imread('image_path/image.jpg', 0)

kernelx = np.array([[1, 0], [0, -1]])
kernely = np.array([[0, 1], [-1, 0]])

img_robertx = cv2.filter2D(img, -1, kernelx)
img_roberty = cv2.filter2D(img, -1, kernely)
prewitt = cv2.add(img_robertx, img_roberty)

cv2.imshow(prewitt)

正如DrYuanShenghai所建议的:

kernelx = np.array([[1, 0], [0, -1]])
kernely = np.array([[0, 1], [-1, 0]])
img_robertx = cv2.filter2D(blured_img, -1, kernelx)
img_roberty = cv2.filter2D(blured_img, -1, kernely)
grad = cv2.addWeighted(img_robertx, 0.5, img_roberty, 0.5, 0)

Tags: imageimgnparraycv2robert边缘算子