日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

python+opencv Canny边缘检测

發布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python+opencv Canny边缘检测 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Step1:高斯濾波(低通濾波,用高斯濾波器平滑圖像)

  • 卷積/卷積核(對應相乘再相加)
  • 原始圖片外圍加一圈0,為保證新圖片與原始圖片大小相同
  • 卷積核為3*3,外圍補一圈0;卷積核為5*5,外圍補兩圈0

?Step2:計算圖像梯度及梯度方向(圖像增強)

?Step3:非極大值抑制(閾值設置)

?Step4:雙閾值篩選邊緣

#---------------------------------邊緣檢測---------------------------------
import cv2class 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 npcover_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)

總結

以上是生活随笔為你收集整理的python+opencv Canny边缘检测的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。