cv2.imshow('Original Image', image) # 显示切割后的图片 cv2.imshow('Cut Image', cut_image) # 等待按键后关闭窗口 cv2.waitKey(0) cv2.destroyAllWindows() # 如果需要,也可以将切割后的图片保存到文件 # cv2.imwrite('cut_example.jpg', cut_image)
# cv2.CHAIN_APPROX_SIMPLE压缩水平方向,垂直方向,对角线方向的元素,只保留该方向的终点坐标,例如一个矩形轮廓只需4个点来保存轮廓信息 # cv2.findContours()函数返回两个值,一个是轮廓本身,还有一个是每条轮廓对应的属性。cv2.findContours()函数返回第一个值是list,list中每个元素都是图像中的一个轮廓,用numpy中...
importcv2importnumpyasnpimportmatplotlib.pyplotaspltfromskimage.segmentationimportslicimporttensorflowastf# 读取图像并转换为灰度img = cv2.imread('image.jpg',0)# 1. 阈值分割ret, thresh = cv2.threshold(img,127,255, cv2.THRESH_BINARY) plt.imshow(thresh, cmap='gray') plt.title('Thresholding') plt....
img = cv2.imread(path) height = img.shape[0] # The size of each input image width = img.shape[1] heightBlock = int(height / heightCutNum) # The size of block that you want to cut widthBlock = int(width / widthCutNum) for i in range(0, heightCutNum): for j in range(0, ...
cv.waitKey(0)# 基于边缘defcutImage(sourceDir):# 读取图片img = cv.imread(sourceDir)# 灰度化gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)# 高斯模糊处理:去噪(效果最好)blur = cv.GaussianBlur(gray, (9,9),0)# Sobel计算XY方向梯度gradX = cv.Sobel(gray, ddepth=cv.CV_32F, dx=1, dy=0)...
OpenCV2获取轮廓主要是用cv2.findContours import numpy as np import cv2 image = cv2.imread('test.jpg') imgray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) ret,thresh = cv2.threshold(imgray,127,255,0) #image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)...
importcv2 img=cv2.imread("./data/cut/thor.jpg")print(img.shape)cropped=img[0:128,0:512]# 裁剪坐标为[y0:y1,x0:x1]cv2.imwrite("./data/cut/cv_cut_thor.jpg",cropped) 这里,我们先用imread方法读取待裁剪的图片,然后查看它的shape,shape的输出是(1080, 1920, 3),输出的顺序的是高度、宽度、...
# 导入需要使用到的库importtimeimportcv2importosfromtkinterimportfiledialog# 获取视频路径folder=filedialog.askdirectory()# 获取视频路径os.chdir(folder)#更改视频路径,如果不更改,需要对路径进行拼接。# 初始化的一些全局变量image_folder="cut"# 设置存图的目录all_image_process=0# 统计所有图片的进度vodeo_proce...
dstPath =r"./testCut"3.我们打开视频文件:cap = cv2.VideoCapture("test.mp4")如果视频打开失败,...
using opencv-python cv2.grabCut to cut image interactively - GitHub - zihangJiang/GrabCut: using opencv-python cv2.grabCut to cut image interactively