pycharmers.opencv.binary module¶
-
pycharmers.opencv.binary.
binarizer_creator
(method, maxval=255, thresh=127, thresholdType=0, blockSize=11, const=2)[source]¶ Returns a function which performs advanced morphological transformations.
- Parameters
method (str/int) – The identifier of binarization.
thresh (int) – Threshold value used in
"fixed"
binarizer.maxval (int) – The maximum value.
thresholdType (int) – Thresholding type.
blockSize (odd) – Size of a pixel neighborhood that is used to calculate a threshold value for the pixel:
3
,5
,7
, and so on.const (int) – Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.
- Returns
Binarizer.
- Return type
function
Examples
>>> import cv2 >>> from pycharmers.opencv import binarizer_creator, SAMPLE_LENA_IMG, vconcat_resize_min, cv2plot >>> from pycharmers.opencv.binary import OPENCV_BINARYZATIONS >>> gray = cv2.imread(SAMPLE_LENA_IMG, 0) >>> images = [gray] >>> images.extend([binarizer_creator(key)(gray) for key in OPENCV_BINARYZATIONS.keys()]) >>> ax = cv2plot(vconcat_resize_min(*images), cmap="binary", figkeywargs={"figsize": (10,10)})
-
pycharmers.opencv.binary.
findBiggestContour
(contours, eta=0.1)[source]¶ - Parameters
contours (list) – Contours. (e.g. The return of
cv2.findContours
)- Returns
Countour of the biggest area. max_area (int) : Area of the biggest area.
- Return type
biggest (np.ndarray)
Examples
>>> import cv2 >>> from pycharmers.opencv import findBiggestContour, SAMPLE_LENA_IMG >>> img_gray = cv2.imread(SAMPLE_LENA_IMG, 0) >>> img_th = cv2.Canny(img_gray, 100, 100) >>> contours, hierarchy = cv2.findContours(image=img_th, mode=cv2.RETR_EXTERNAL, method=cv2.CHAIN_APPROX_SIMPLE) >>> biggest, max_area = findBiggestContour(contours, eta=0.2) >>> max_area 0 # There is no closed countour.