小编Ale*_*ing的帖子

打开 Cv 错误: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

目前使用带有 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)

python-3.x cv2

6
推荐指数
1
解决办法
8158
查看次数

标签 统计

cv2 ×1

python-3.x ×1