Python + OpenCV 直接上代码
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
img=cv2.imread('0002.jpg') #读取图片,装换为可运算的数组
GrayImage=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #将BGR图转为灰度图
ret,thresh1=cv2.threshold(GrayImage,130,255,cv2.THRESH_BINARY) #将图片进行二值化(130,255)之间的点