python怎么让图片旋转45度_python-在图像中仅显示45度线

好了,通过您在问题中提供的代码,我们获得了除我们想要获得的那些行之外的其他行.因此,我们可以将其放大并填充线条.

img = cv2.imread('lines.png')

kernel = np.array([[0, -1, 0],

[1, 0, 1],

[0, -1, 0]])

dst = cv2.filter2D(img, -1, kernel)

kernel = np.ones((5, 5), np.uint8)

dilated = cv2.dilate(dst, kernel, iterations = 1)

然后,我们需要以45度去除线条上方的点,因此我们为此使用了形态学开口,并对图像进行阈值处理以将所有线条转换为像素值= 255.

kernel = np.ones((7, 7), np.uint8)

opening = cv2.morphologyEx(dilated, cv2.MORPH_OPEN, kernel)

_,thresh = cv2.threshold(opening,10,255,cv2.THRESH_BINARY)

然后使用原始图像的cv2.bitwise_and和获得的阈值的cv2.bitwise_not,我们获得了线.

res = cv2.bitwise_and(img, cv2.bitwise_not(thresh))

我们获得了线条,但需要删除中间的圆圈.为此,我们在原始图像上使用cv2.erode仅获得中间圆,对其设置阈值,然后再次使用cv2.bitwise_and和cv2.bitwise_not将其从res中删除.

kernel = np.ones((7, 7), np.uint8)

other = cv2.erode(img, kernel, iterations = 1)

_,thresh = cv2.threshold(other,10,255,cv2.THRESH_BINARY)

result = cv2.bitwise_and(res, cv2.bitwise_not(thresh))

cv2.imshow("Image", result)

cv2.waitKey(0)

cv2.destroyAllWindows()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值