赞
踩
Step1:高斯滤波(低通滤波,用高斯滤波器平滑图像)
Step2:计算图像梯度及梯度方向(图像增强)
Step3:非极大值抑制(阈值设置)
Step4:双阈值筛选边缘
- #---------------------------------边缘检测---------------------------------
- import cv2
-
- class MainWindow():
-
- def __init__(self):
- super().__init__()
- img = cv2.imread("D:/Users/xuyf2/Desktop/cp1635564192.jpg")
- print('img_shape', img.shape)
- src0 = cv2.resize(img, (640, 480))
-
- # src1 = src0[0:480, 365:515] # 裁切需要的部分
- scr1 = cv2.medianBlur(src0, 5) # 中值滤波
- self.line_detect_possible_demo(scr1)
-
- def line_detect_possible_demo(self,image): # 检测出可能的线段
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- edges = cv2.Canny(gray, 200,610, apertureSize=3)
- print('edges_shape', edges.shape)
- cv2.imshow("Canny", edges)
-
- if __name__ == '__main__':
-
- mainWindow = MainWindow()
- cv2.waitKey(0)
- cv2.destroyAllWindows()
-

- import cv2
- import numpy as np
-
- cover_path = "D:/Users/xuyf2/Desktop/lego_jier/cp1622130065.jpg"
- im1 = cv2.imread(cover_path) # 读取图片
- im2 = cv2.resize(im1,(640,480),) # 缩放图片
- img = im2[0:400, 80:300] # 裁剪图片
- scr1 = cv2.medianBlur(img, 5) # 中值滤波
-
- gray = cv2.cvtColor(scr1, cv2.COLOR_BGR2GRAY) # 灰度处理
- edges = cv2.Canny(gray, 150,400, apertureSize=3) # 灰度处理
- cv2.imshow("Canny", edges) # 边缘检测
- gra = np.float32(edges)
- # 角点坐标
- corners = cv2.goodFeaturesToTrack(gra, 50, 0.1, 50)
- corners = np.int0(corners)
-
- for i in corners: # 降维
- x, y = i.ravel()
- print([x,y]) # 打印角点坐标
- cv2.circle(img, (x, y), 6, (0, 0, 255), -1)
-
- cv2.imwrite('jiaodian.jpg', img)
- cv2.imshow('jiaodian', img)
- cv2.waitKey(0)
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。