当前位置:网站首页>opencv 读取图片详解
opencv 读取图片详解
2022-06-28 16:17:00 【Da_Shan_】
最近在做深度学习目标检测中,用opencv读图,做翻转等等操作,发现自己之前对于opencv读取图片的数据存储理解不够全面,现在特做总结如下:
opencv读取图片是从左边第一个像素点开始读取,由于是彩色RGB图片,所以每个像素点处会有三个值,(opencv是按照 BRG 的顺序读取像素值),依次遍历每一行,每一行都分别是一个 (width, 3) 的numpy格式的二维数组,最后将每一行的这个二维数组都添加到一个大数组中,形成一个三个数组,也就会最后 img.shape 输出的 (height, width, 3) 这么一个三维数组
将opencv读取的图片转为正常的 RGB 模式:
img_path = '000001.jpg'
img = cv2.imread(img_path)
# opencv自带的 imshow 函数可以正常显示 BGR 格式的图像
cv2.imshow('res', img)
cv2.waitKey(0)
# 将 BGR 转成 RGB,用 plt 显示
img_rgb = img[:, :, ::-1] # 用numpy数组将最后一维进行转换
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 用cv自带的转换函数
plt.imshow(img_rgb)
plt.show()
水平镜像翻转
img_flip = cv2.flip(img, 1)
img_flip = img[:, ::-1, :]
img_combine = np.hstack((img, img_flip))
cv2.imshow('res', img_combine)
cv2.waitKey(0)
垂直镜像翻转
img_flip = cv2.flip(img, 0)
img_flip = img[::-1, :, :]
img_combine = np.hstack((img, img_flip))
cv2.imshow('res', img_combine)
cv2.waitKey(0)
边栏推荐
- 2019 CSP J2 entry group csp-s2 improvement group round 2 video and question solution
- 媒体数据处理V2版本(VPC)图像缩放内容解析
- 浅谈 SAP 软件里的价格折扣设计原理
- 【杂谈】2021/01/31 哦豁
- [MySQL] official website document learning query statement SQL precautions
- Yesterday, yuancosmos | meta's "yuancosmos" Department lost $2.96 billion in the first quarter, and Liufu jewelry issued Digital Collections
- MySQL self connection query "suggestions collection"
- China energy integration and Tianyi cloud create an "energy brain"
- 从入门到精通|Yalmip+Cplex在电力系统中的应用(超棒,看不懂算我输,没有收获也算我输)
- [high concurrency foundation] MySQL index optimization
猜你喜欢

Briefly introduce the conversion between tensorflow and pytorch (mainly tensorflow to pytorch)

Csp-j1 csp-s1 preliminary training plan and learning points in summer and September 2022

【Hot100】4. Find the median of two positive arrays

Cross cluster deployment of helm applications using karmada

Why MySQL table connection is faster than subquery

使用Karmada实现Helm应用的跨集群部署

Introduction to reverse commissioning PE structure details 02/07

FS2K人脸素描属性识别

QQ出现大规模盗号,为什么会这样?就没有解决方法了吗?
![[tcapulusdb knowledge base] tcapulusdb technical support introduction](/img/ae/9295c8ae642cde632d06966c28d342.png)
[tcapulusdb knowledge base] tcapulusdb technical support introduction
随机推荐
AI落地的新范式,就“藏”在下一场软件基础设施的重大升级里
On the design principle of price discount in SAP software
如何清除 WordPress 中的缓存
Gartner announces five privacy trends from today to 2024
[high concurrency foundation] MySQL index optimization
[laravel] about the composer installation of laravel8
LDD 知识整理
【TcaplusDB知识库】TcaplusDB技术支持介绍
MySQL self connection query "suggestions collection"
【TcaplusDB知识库】TcaplusDB限制条件介绍
机器学习之卷积神经网络使用cifar10数据集和alexnet网络模型训练分类模型,安装labelimg,以及报错ERROR
中能融合携手天翼云打造“能源大脑”
Solve the problem that subcomponents will not be destroyed through setTimeout
A 24-year-old bald programmer teaches you how to continuously integrate and deliver microservice delivery. You can't learn how to cut me off
昨日元宇宙| 沃尔玛成立探索元宇宙和Web3的创新部门,Dior发布元宇宙展览
leetcode:22. bracket-generating
Convolutional neural network for machine learning uses cifar10 data set and alexnet network model to train classification model, install labelimg, and report error
CODING DevOps 助力中化信息打造新一代研效平台,驱动“线上中化”新未来
【Redis】2021/01/31 Redis的简单归纳 No.01
A simple reflective XSS operation and idea