python版本个人常用的
import cv2
import numpy as np
def show_img(name="", img="", x=0, y=0):
cv2.namedWindow(name, 0) # 创建图像显示窗口
cv2.moveWindow(name, x, y) # 设置窗口的位置,不然多张图像显示重叠
cv2.imshow(name, img) # 显示图像
img_src = cv2.imread("1.jpg", 1) # 读图
cv2.medianBlur(img_src, 5) # 滤波
show_img(name="src_img", img=img_src, x=0, y=0)
img_src = cv2.resize(img_src, (400, 400), cv2.INTER_AREA) # 图像大小缩放
h_flip = cv2.flip(img_src, 1) # 翻转 1:水平 0:竖直 -1:0&1
show_img(name="flip_img", img=h_flip, x=0, y=400)
img_black = np.zeros(img_src.shape, np.uint8) # 创建黑图 np.uint8
img_src = cv2.cvtColor(img_src, cv2.COLOR_BGR2GRAY) # 颜色空间转化
_, img_bin = cv2.threshold(img_src, 200, 255, cv2.THRESH_BINARY) # 阈值分割
show_img(name="bin_img", img=img_bin, x=800, y=0)
kernel = np.on