您当前的位置: 首页 >  Python

Python opencv边缘提取

发布时间:2021-03-11 14:09:54 ,浏览量:5

题目描述 利用opencv或其他工具编写程序实现图像的边缘提取。

实现过程

import cv2 import numpy as np # imread()两个参数: # 1、图片路径。 # 2、读取图片的形式(1:默认值,加载彩色图片。 0:加载灰度图片。 -1:加载原图片) img = cv2.imread(r"C:\Users\pc\Desktop\test1.bmp") cv2.imshow('img', img) ret, thresh1 = cv2.threshold(img, 80, 255, cv2.THRESH_BINARY) # 阈值分割,黑白二值 ret, thresh2 = cv2.threshold(thresh1, 80, 255, cv2.THRESH_BINARY_INV) # (黑白二值反转) cv2.imshow('img1', thresh1) cv2.imshow('img2', thresh2) # Canny算子是双阈值,所以需要指定两个阈值,阈值越小,边缘越丰富。 img3 = cv2.Canny(img, 80, 255) # 对img3图像进行反转 img4 = cv2.bitwise_not(img3) cv2.imshow('img4', img4) cv2.waitKey() # 关闭窗口并取消分配任何相关的内存使用 cv2.destroyAllWindows() 

运行结果 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述

关注
打赏
1688896170
查看更多评论

暂无认证

  • 5浏览

    0关注

    115984博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0500s