我必须使用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)
目前没有回答
相关问题 更多 >
编程相关推荐