I am in a situation where cv2.THRESH_TRUNC
suits me well and I want to apply as adaptive threshold but I am facing an unknown error. Here is my basic code:
from PIL import Image
import pytesseract
import cv2
image = cv2.imread("/home/anees/Desktop/passport.png",0)
thresh =cv2.adaptiveThreshold(image,170,
cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_TRUNC, 3, 5)
ERROR that I am getting is below:
openCV(4.5.2) /tmp/pip-req-build-yw7uvgqm/opencv/modules/imgproc/src/thresh.cpp:1723: error: (-206:Bad flag (parameter or structure field)) Unknown/unsupported threshold type in function 'adaptiveThreshold'
Here is the documentation of the
cv2.adaptiveThreshold()
method, accessible by calling the built-inhelp()
method:Focusing on this part:
So you'll simply have to change your
cv2.THRESH_TRUNC
to one ofcv2.THRESH_BINARY
orcv2.THRESH_BINARY_INV
.The
help()
method to is great tool to get the more information on methods without having to go online!