本篇文章介绍了Opencv ROI截取 、设置、保存操作,感兴趣区(Region of Interest,ROIs) 是图像的一部分,它通过在图像上选择或使用诸如设定阈值(thresholding) 或者从其他文件(如矢量> 转换获得等方法生成。感趣区可以是点、线、面不规则的形状,通常用来作为图像分类的样本、掩膜、裁剪区或及其他操作。原理通过操作图像矩阵来获取或合并指定位置的图像。
import cv2
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
# 加载彩色图
img = cv2.imread('D:/Jupyter_Notebooks/2.jpg', 1)
img_car1 = img[150:300, 300:500]
cv2.imshow('image', img_car1)
cv2.imwrite('D:/Jupyter_Notebooks/3.jpg', img_car1)
# 等待时间,毫秒级,0表示任意键终止
cv2.waitKey(0)
cv2.destroyAllWindows()
其它文章: