我有一個影像,當我在其上應用二進制閾值時,它給出的結果與它在具有其他事物的影像中時不同。我不確定我是否錯誤地設定了閾值函式的引數,因為我從 OpenCV 檔案中獲取了示例。檔案鏈接:

#Reading in image1
img1 = cv2.imread("Templates/YellowBlocks/SS.png", cv2.IMREAD_COLOR)
#Reading in image2
img2 = cv2.imread("Test Program 1.png", cv2.IMREAD_COLOR)
#Converting image1 to grayscale
grayImg1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
#Converting image2 to grayscale
grayImg2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
#Applying a binary threshold on image1 to show text in black and white
ret1,thresh1 = cv2.threshold(grayImg1, 0, 255,cv2.THRESH_OTSU cv2.THRESH_BINARY)
#Applying a binary threshold on image2 to show text in black and white
ret2,thresh2 = cv2.threshold(grayImg2, 0, 255,cv2.THRESH_OTSU cv2.THRESH_BINARY)
#Displaying image1
cv2.imshow('img1', img1)
#Displaying thresholded image1
cv2.imshow('thresh1', thresh1)
#Displaying image2
cv2.imshow('img2', img2)
#Displaying thresholded image2
cv2.imshow('thresh2', thresh2)
cv2.waitKey(0)
uj5u.com熱心網友回復:
這是因為您使用了 OTSU。它設定了某種自動閾值。請參考以下鏈接
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/444630.html
