基于opencv的图像自适应处理
import cv2 image = cv2.imread(rE:OpenCVPython OpenCV codePython OpenCVslhuan1.jpg) image = cv2.resize(image,None, fx=1/2,fy=1/2) image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) t1, dst1 = cv2.threshold(image_gray, 127, 255, cv2.THRESH_BINARY) # dst1 = cv2.resize(dst1, None, fx=3/, fy=1/2) t2, dst2 = cv2.threshold(image_gray, 127, 255, cv2.THRESH_BINARY_INV) # dst2 = cv2.resize(dst2, None, fx=1/4, fy=1/2) t3, dst3 = cv2.threshold(image_gray, 127, 255, cv2.THRESH_TOZERO) # dst3 = cv2.resize(dst3, None, fx=1/2, fy=1/2) t4, dst4 = cv2.threshold(image_gray, 127, 255, cv2.THRESH_TOZERO_INV) # dst4 = cv2.resize(dst4, None, fx=1/2, fy=1/2) t5, dst5 = cv2.threshold(image_gray, 127, 255, cv2.THRESH_TRUNC) dst5 = cv2.resize(dst5, None, fx=1/2, fy=1/2) cv2.imwrite(./01.jpg, dst1) cv2.imwrite(./02.jpg, dst2) cv2.imwrite(./03.jpg, dst3) cv2.imwrite(./04.jpg, dst4) cv2.imwrite(./05.jpg, dst5) cv2.imshow(BINARY, dst1) cv2.imshow(BINARY_INV, dst2) cv2.imshow(TOZERO, dst3) cv2.imshow(TOZERO_INV, dst4) cv2.imshow(TRUNC, dst5) cv2.waitKey() cv2.destroyAllWindows()
只需更改路径就可获得你需要的图片,路径一定要是英文的。
