0

// 1.what's purpose for using _,

import cv2 as cv
import numpy as np

img = cv.imread('sudoku.png',0)


 _,th1 =cv.threshold(img,127,255,cv.THRESH_BINARY)  

// 2. What does 2nd value(255), 5th (11), 6th (2) for ? What will happen if we change each of them?

 th2=cv.adaptiveThreshold
(img,255,cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,11,2)

 cv.imshow("Image",img)
 cv.imshow("th1",th1)
 cv.imshow("th2",th2)

 cv.waitKey(0)
 cv.destroyAllWindows()

// 3. What will happened if we do not use " cv.destroyAllWindows()"?

Roshan
  • 664
  • 5
  • 23
Etsuka
  • 45
  • 7
  • 1.: _ means you ignore the first output argument. – WiseDev Jun 25 '19 at 14:53
  • regarding `_` see https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python, regarding your other questions did you read the docs? – EdChum Jun 25 '19 at 14:54
  • You can find all these answers very easiliy be reading the openCV docs. – WiseDev Jun 25 '19 at 14:54
  • Hi, everyone. I did read the document doe openCV, but I'm still confused what if we change it or do not use it? Appreciate for all answers! – Etsuka Jun 25 '19 at 15:07

1 Answers1

0

The second value (255) is the value that is used for the maximum.

_,th1 =cv.threshold(img,127,255,cv.THRESH_BINARY)
np.max(th1)

will return 255. If you set it to something else like this

_,th2 =cv.threshold(img,127,200,cv.THRESH_BINARY)
np.max(th2)

It will return 200

The other two parameters are nicely explained here: OpenCV 2.4 docs

But the 5h value is the block size which is used as a neighborhood for the different adaptive thresholds.

The 6th value is a constant value that is subtracted from the mean or wighted mean.

Julian
  • 909
  • 8
  • 21