CV2 Import
Import numpy NP AS
path = "_holefill.jpg"
IMG = cv2.imread (path)
Gray = cv2.cvtColor (IMG, cv2.COLOR_BGR2GRAY) # is converted into grayscale
ret, thresh = cv2.threshold (gray, 50 , 250, cv2.THRESH_BINARY_INV) # grayscale converted into a binary image
thresh_not = cv2.bitwise_not (complement thresh) # binary image
kernel = cv2.getStructuringElement (cv2.MORPH_ELLIPSE, (3,3 )) # 3 × 3 structure element
"" "
construction of the array F, and writes the boundary value F thresh_not
" ""
F. = np.zeros (thresh.shape, np.uint8)
F. [:, 0] = thresh_not [:, 0]
F. [ :, -1] = thresh_not [:, -1]
F [0,:] = thresh_not [0,:]
F [-1,:] = thresh_not [-1,:]
"" "
loop iterations to be F expansion operation, and the operation result performed thresh_not
"" "
for I in Range (200 is):
= Cv2.dilate F_dilation (F., Kernel, Iterations =. 1)
F. = Cv2.bitwise_and (F_dilation, thresh_not)
Result = cv2.bitwise_not (F.) For a result of performing # Not
# Display results
cv2.imshow ( 'p', result)
cv2.imshow ( 'R & lt', Thresh)
cv2.waitKey (0)
python + opnencv achieve hole filling image
Guess you like
Origin www.cnblogs.com/er-gou-zi/p/11831222.html
Recommended
Ranking