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

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

為什么自適應閾值圖像小于原始圖像?

為什么自適應閾值圖像小于原始圖像?

炎炎設計 2022-07-26 16:55:19
我正在嘗試在最終將用于形狀檢測的實時流上使用adapativeThreshold。常規閾值沒有顯示足夠的我想看到的。當我使用下面的代碼時,常規閾值按預期出現,但由于某種原因自適應閾值比原來的要薄得多,我在視圖中看不到任何東西。好像有什么事情發生了,但我不知道是什么。關于如何使自適應閾值窗口全尺寸的任何想法?這是我在每個窗口中運行程序時看到的:#import packagesfrom documentscanner.pyimagesearch.transform import four_point_transformfrom pyimagesearch.shapedetector import ShapeDetectorfrom skimage.filters import threshold_localimport numpy as npimport cv2import imutilsdef draw_Contours(screen, points):    cv2.drawContours(screen, [points], -1, (0, 255, 0), 2)    cv2.imshow("Outline", screen)def nothing(x):    #any operation    pass#access video cameracap = cv2.VideoCapture(0)cv2.namedWindow('Trackbars')cv2.createTrackbar('min_edge', 'Trackbars', 75, 100, nothing)cv2.createTrackbar('max_edge', 'Trackbars', 110,300, nothing)while True:    _, frame = cap.read()       #read video camera data    minedge = cv2.getTrackbarPos('min_edge', 'Trackbars')    maxedge = cv2.getTrackbarPos('max_edge', 'Trackbars')    #convert image to gray scale    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)    gray = cv2.GaussianBlur(gray, (5, 5), 0)    #blur = cv2.GaussianBlur(frame, (5, 5), 0)    #edged = cv2.Canny(gray, minedge, maxedge)    #threshhold instead of edging    thresh = cv2.threshold(gray, 60, 255, cv2.THRESH_BINARY)[1]    thresh2 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\                                    cv2.THRESH_BINARY, 11, 2)[1]    thresh3 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,\                                    cv2.THRESH_BINARY, 11, 2)[1]    #find contours in edges image, keeping the largest ones, and initialize the screen contour/shapedetect    cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)    cnts = imutils.grab_contours(cnts)    sd = ShapeDetector()    cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]
查看完整描述

1 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

而不是使用


thresh2 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\

                                cv2.THRESH_BINARY, 11, 2)[1]

thresh3 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,\

                                cv2.THRESH_BINARY, 11, 2)[1]

在沒有 numpy 索引的情況下使用它,然后就不會發生此錯誤。


thresh2 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\

                                cv2.THRESH_BINARY, 11, 2) # don't use [1] 

thresh3 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,\

                                cv2.THRESH_BINARY, 11, 2)

這是因為正常閾值處理返回兩個值,而自適應閾值處理只返回一個值。


查看完整回答
反對 回復 2022-07-26
  • 1 回答
  • 0 關注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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