Author:XuLiu
Time:20211105
Function:使用OpenCV截取图片,命名id_c0022.jpg
Input:
1.txt文件
| id | x | y | w | h |
|---|---|---|---|---|
| 5673 | 573 | 98 | 94 | 69 |
2.一张大图片
Output:

命名为id_c_.jpg的截图
import cv2
import os
import codecs
def image_cut_save(path, x, y, w, h, save_path):
"""
所截区域图片保存
:param path: 图片路径
:param x: 区块左上角位置的像素点离图片左边界的距离
:param y:区块左上角位置的像素点离图片上边界的距离
:param x+w:区块右下角位置的像素点离图片左边界的距离
:param y+h:区块右下角位置的像素点离图片上边界的距离
:param save_path: 所截图片保存位置
"""
img = cv2.imread(path) # 打开图像
cropped = img[y:y+h, x:x+w]
cv2.imwrite(save_path, cropped)
# embed()
if __name__ == '

最低0.47元/天 解锁文章
1763

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



