python cv2剪切图片
时间: 2023-10-03 13:08:25 浏览: 90
要使用Python的OpenCV库(cv2)进行图片的剪切,可以使用以下代码示例:
```python
import cv2
# 读取图片
img = cv2.imread("./cut/1.jpg")
# 定义裁剪范围坐标
y0, y1 = 0, 800
x0, x1 = 88, 712
# 进行图片剪切
cropped = img[y0:y1, x0:x1]
# 保存剪切后的图片
cv2.imwrite("./out/1_o.jpg", cropped)
```
以上代码首先使用`cv2.imread()`函数读取指定路径的图片文件,然后定义了裁剪的范围坐标`[y0:y1, x0:x1]`,接着使用这个坐标范围对图片进行剪切得到剪切后的图片,最后使用`cv2.imwrite()`函数保存剪切后的图片到指定路径的文件中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [【python】裁剪图片为指定大小,按位置截取,cv2(批量制作主图)](https://blog.csdn.net/weixin_43289135/article/details/107645007)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [python cv2图片剪裁](https://blog.csdn.net/FormatFa/article/details/80353235)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Python实战项目2-图片处理](https://download.csdn.net/download/weixin_72543266/88229121)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文