Home>

I want to perform adaptive threshold processing using the cv2.adaptiveThreshold function, but I get an error and cannot process it.
I'm not sure what the error is, so please let me know.

-------------------------------------------------- -------------------------
ValueError Traceback (most recent call last)
<ipython-input-15-c24bc2230a3b>in<module>
     11
     12
--->13 plt.show (th3)
~ \ anaconda3 \ lib \ site-packages \ matplotlib \ pyplot.py in show (* args, ** kw)
    270 "" "
    271 global _show
->272 return _show (* args, ** kw)
    273
    274
~ \ anaconda3 \ lib \ site-packages \ ipykernel \ pylab \ backend_inline.py in show (close, block)
     47 # only call close ('all') if any to close
     48 # close triggers gc.collect, which can be slow
--->49 if close and Gcf.get_all_fig_managers ():
     50 matplotlib.pyplot.close ('all')
     51
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any () or a.all ()
<Figure size 432x288 with 0 Axes>
Corresponding source code
import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.gray ()
img = cv2.imread ('g_2.4flat09944.jpg', 0)
img = cv2.medianBlur (img, 5)
th3 = cv2.adaptiveThreshold (img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, \
            cv2.THRESH_BINARY, 11,2)

plt.show (th3)
What I tried

I don't know what the error is, so I haven't done anything in particular.
For binarization using the cv2.adaptiveThreshold function, refer to the following site.

Image threshold processing