. , .
NB. OpenCV 2.4.x, 3.x.
0
.
img = cv2.imread('paper.jpg',0)
1
, .
-.
dilated_img = cv2.dilate(img, np.ones((7,7), np.uint8))
2
.
, / .
bg_img = cv2.medianBlur(dilated_img, 21)
3
, . , , ( 0 ), ( ).
, .
diff_img = 255 - cv2.absdiff(img, bg_img)
4
, .
norm_img = diff_img.copy()
cv2.normalize(diff_img, norm_img, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
5
. .
_, thr_img = cv2.threshold(norm_img, 230, 0, cv2.THRESH_TRUNC)
cv2.normalize(thr_img, thr_img, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
...
, ;) , -, .
. , (16+ int float) , .