Python+OpenCV 零基础学习笔记(6):ROI

文章目录

相关链接

【2022B站最好的OpenCV课程推荐】OpenCV从入门到实战 全套课程

CSDN标题里个括号对应视频的分P

OpenCV+Python CSDN专栏
Gitee 项目地址

运行环境

  • Python:3.11.5
  • Anaconda:23.7.4
  • IDE:vscode
  • 运行环境:Windows
  • OpenCV:4.8.1

Python+OpenCV 零基础学习笔记(1-3):anaconda+vscode+jupyter环境配置

前言

ROI简单来说就是截取区域。本章来了解以下OpenCV如何简单的截取ROI。

ROI

ROI就是局部图像处理

python 复制代码
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np

input_img={}

input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
cv2.imshow('roi',input_img['roi'])
cv2.waitKey(0)

运行结果

颜色区域分割

python 复制代码
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np

input_img={}

input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
# cv2.imshow('roi',input_img['roi'])

# 截取颜色通道
b,g,r = cv2.split(input_img['rgb'])
# 将RGB更新到字典中
input_img.update({
    'r':r,
    'g':g,
    'b':b
})
# 展示BGR画面
cv2.imshow('b',input_img['b'])
cv2.imshow('g',input_img['g'])
cv2.imshow('r',input_img['r'])

cv2.waitKey(0)
cv2.destroyAllWindows()

颜色通道合并

python 复制代码
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np

input_img={}

input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
# cv2.imshow('roi',input_img['roi'])

# 截取颜色通道
b,g,r = cv2.split(input_img['rgb'])
# 将RGB更新到字典中
input_img.update({
    'r':r,
    'g':g,
    'b':b
})
# 展示BGR画面
# cv2.imshow('b',input_img['b'])
# cv2.imshow('g',input_img['g'])
# cv2.imshow('r',input_img['r'])

# 将BGR合并
input_img['merge']= cv2.merge((input_img['b'],input_img['g'],input_img['r']))

print(input_img['merge'])
cv2.imshow('merge',input_img['merge'])


cv2.waitKey(0)
cv2.destroyAllWindows()
相关推荐
金銀銅鐵12 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup1117 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0019 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵21 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent
copyer_xyf1 天前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf1 天前
Agent 记忆管理
后端·python·agent
星云穿梭2 天前
用Python写一个带图形界面的学生管理系统——完整教程
python