1.canny边缘检测

# coding=utf-8

import cv2
import numpy as np filename = 'woman.JPEG' #读入图像,以灰度格式
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) canny1 = cv2.Canny(img,200,300)
#200:最小阈值 300:最大阈值
#灰度梯度高于maxVal被认为是边界
#低于minVal抛弃 cv2.imshow("canny",canny1)
cv2.waitKey()
cv2.destroyAllWindows()

day4 边缘检测Canny-LMLPHP

2.pyplot 应用

#-*- coding:utf-8 -*-

import cv2
import numpy as np
from matplotlib import pyplot as plt filename = 'woman.JPEG' img = cv2.imread(filename,0) canny1 = cv2.Canny(img,200,300) #plt.subplot(121),plt.imshow(img,cmap='woman')
plt.subplot(121),plt.imshow(img,cmap='gray') #必须是gray #1行2列 第2个图像
plt.subplot(122), plt.imshow(canny1,'gray')
plt.title('Edge Image') #标题
plt.xticks([]), plt.yticks([]) #去除x y 轴
plt.xlim([0,500]) #图像y轴 0-500 plt.show()

day4 边缘检测Canny-LMLPHP

05-23 09:36