变换前:

变换后:

import cv2
import matplotlib.pyplot as plt
import numpy as np
# 图像预处理
def detect_img(img):
# BGR 转 RGB
rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 获取图像尺寸
H, W = rgb_img.shape[0:2]
# 裁剪目标区域
split_img = rgb_img[410:620, 1020:1330]
# 图像尺寸重制
new_img = cv2.resize(split_img, (W // 4, H // 4))
# RGB 转 Gray
gray = cv2.cvtColor(new_img, cv2.COLOR_RGB2GRAY)
# 图像阈值分割
ret, thresh = cv2.threshold(gray, 60, 255, cv2.THRESH_BINARY)
return H, W, rgb_img, split_img, gray, new_img, thresh
# 图像轮廓提取
def img_cnt(thresh):
# 图像开运算
kernel = np.ones((11, 11), np.uint8)
open_img = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
# 图像轮廓查

最低0.47元/天 解锁文章
1014

被折叠的 条评论
为什么被折叠?



