目前使用带有 Python 3.7 的 Windows 10 我尝试使用此代码运行,以使网络摄像头能够用于数字识别
def get_img_contour_thresh(img):
x, y, w, h = 0, 0, 300, 300
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
ret, thresh1 = cv2.threshold(blur, 175, 255, cv2.THRESH_BINARY_INV +
cv2.THRESH_OTSU)
thresh1 = thresh1[y:y + h, x:x + w]
contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)[-2:]
return img, contours, thresh1
def show_webcam(mirror=False):
# load json and create model
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
# load weights into new model …Run Code Online (Sandbox Code Playgroud)