python opencv3 直線檢測

來源:互聯網
上載者:User

標籤:min   opencv3   canny   角度   inline   compute   閾值   data   .com   

git:https://github.com/linyi0604/Computer-Vision

 1 # coding:utf8 2  3 import cv2 4 import numpy as np 5  6  7 # 讀入映像 8 img = cv2.imread("../data/line1.png") 9 # 轉為灰階映像10 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)11 # Canny邊緣檢測12 edges = cv2.Canny(gray, 50, 100)13 """14 canny邊緣檢測:15 有五個步驟:16         1 高斯濾波器降噪17         2 計算梯度18         3 邊緣上使用非最大抑制 nms19         4 邊緣上使用雙閾值去除假陽性20         5 分析所有邊緣串連 消除不明顯的邊緣21 """22 23 minLineLength = 2024 maxLineGap = 525 lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100, minLineLength, maxLineGap)26 """27 cv2.HoughLinesP28     作用:標準霍夫線變換, 找到映像中的所有直線29     參數:30         1 二值圖31         2 半徑精度32         3 角度精度33         4 最短檢測長度34         5 允許的最大缺口35     返回:36         一個列表,每一項是一個四元組,分別是直線兩個端點的座標37 """38 for line in lines:39     for x1, y1, x2, y2 in line:40         # 在圖片上畫直線41         cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)42 43 cv2.imshow("edges", edges)44 cv2.imshow("lines", img)45 cv2.waitKey()46 cv2.destroyAllWindows()

 

python opencv3 直線檢測

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.