def contrast_image(image, thresh1=180, thresh2=200, show=False):
image = imutils.resize(image, height=scale_factor)
# convert it to grayscale, and blur it slightly
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray2 = cv2.GaussianBlur(gray, (5, 5), 0)
# threshold the image, then perform a series of erosions + dilations to remove any small regions of noise
thresh = cv2.threshold(gray2, thresh1, thresh2, cv2.THRESH_BINARY)[1]
thresh2 = cv2.erode(thresh, None, iterations=2)
thresh3 = cv2.dilate(thresh2, None, iterations=2)
if show is True: #this is for debugging puposes
cv2.imshow("Contrast", thresh3)
cv2.waitKey(0)
cv2.destroyAllWindows()
return thresh
评论列表
文章目录