亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

cv2.approxPolyDP() , cv2.arcLength() 這些是如何工作的

cv2.approxPolyDP() , cv2.arcLength() 這些是如何工作的

qq_笑_17 2023-01-04 11:08:02
這些功能如何工作?我正在使用 Python3.7 和 OpenCv 4.2.0。提前致謝。approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True)
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

如果您正在尋找一個示例片段,下面是一個:


import cv2

import imutils


# edged is the edge detected image

cnts = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

cnts = imutils.grab_contours(cnts)

cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]

# loop over the contours

for c in cnts:

    # approximate the contour

    peri = cv2.arcLength(c, True)

    approx = cv2.approxPolyDP(c, 0.02 * peri, True)

    # if our approximated contour has four points, then we

    # can assume that we have found our screen

    if len(approx) == 4:

        screenCnt = approx

        break

在上面的代碼片段中,首先它從檢測到邊緣的圖像中找到輪廓,然后對輪廓進行排序以找到五個最大的輪廓。最后它遍歷輪廓并使用cv2.approxPolyDP函數來平滑和近似四邊形。cv2.approxPolyDP適用于文檔邊界等輪廓中有銳邊的情況。


查看完整回答
反對 回復 2023-01-04
  • 1 回答
  • 0 關注
  • 228 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號