当前位置:网站首页>学习opencv-基础应用
学习opencv-基础应用
2022-08-09 13:07:00 【论一个测试的养成】
一,对图片的操作
【1】读取并显示图片
【1-1】读取图片有3中参数
flags:
cv2.IMREAD_COLOR:读取一副彩色图片,图片的透明度会被忽略,默认为该值,实际取值为1;
cv2.IMREAD_GRAYSCALE;以灰度模式读取一张图片,实际取值为0
cv2.IMREAD_UNCHANGED:加载一副彩色图像,透明度不会被忽略 2。
import cv2
img = cv2.imread("demo4.png",flags=cv2.IMREAD_UNCHANGED) #读取彩图片
#img = cv2.imread("demo4.png",2) #读取灰度图
cv2.imshow('image', img) #窗口显示 第一个参数是窗口名,自适应图片的大小不能缩放
cv2.waitKey(0) # 等待键盘输入,在执行后面操作。如果没有这一步,图片会一闪而过
cv2.destroyAllWindows()#删除建立的全部窗口
【2】图片缩放 resize
mport cv2
img = cv2.imread('1.png')
img = cv2.resize(img,(200,200)) #整个图片缩放成200*200大小
cv2.imshow('ll',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
【3】图像分割 split
import cv2
img = cv2.imread('1.png')
B,G,R = cv2.split(img) #函数分离得到各个通道的灰度值(单通道图像)
print(B,G,R)
【4】图像直方图 calcHist
【5】shape 获取图片的宽高颜色
import cv2
img = cv2.imread('1.png')
h,w = img.shape[:2] #获取图片的高宽
【6】画框
import cv2
img = cv2.imread('1.png')
cv2.rectangle(img,(100,100),(300,200),(0,245,243),2)
cv2.imshow('aa',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
[7] 按照图片大小显示
import cv2
image = cv2.imread('test.png)
w, h, r = image.shape
cv2.namedWindow('input_image', 0)
cv2.resizeWindow('input_image', h, w)
cv2.imshow('input_image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
边栏推荐
- Microsoft 10/11 命令行打开系统设置页(WUAP,!WIN32)
- GIN a preliminary study, the environment is installed
- Professor Chen Qiang the machine learning and R application course chapter 18 assignments
- NC40 链表相加(二)
- 蓝桥历届真题-既约分数
- FFmpeg多媒体文件处理(FFMPEG日志系统)
- Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project
- 音频基础学习——声音的本质、术语与特性
- R language kaggle game data exploration and visualization
- 为什么文字不贴合边
猜你喜欢
19、学习MySQL 索引
[极客大挑战 2019]Upload
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
How to solve the 0x80070005 error when the computer is reinstalled and the system is restored
Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
蓝桥历届真题-蛇形填数
gin的中间件和路由分组
kustomize entry example and basic syntax instructions
PO、DO、TO、VO、DO、DTO、DAO、POJO都是什么?
puzzle(016.5)逻辑电路
随机推荐
JS动画函数封装
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
音视频录入的pts和dts问题
NC192 二叉树的后序遍历
JS轮播图实现
海康设备获取YV12图像-不用rtsp
RobotFramework 之 Evaluate
Q_04_05 使用Qubits
RTSP协议的实现
The sword refers to Offer 56 - II. Number of occurrences of a number in an array II (bit operation)
蓝桥历届真题-既约分数
RTP打包发送H.264
乐东消防救援大队应邀为干部开展消防安全培训
javscript基础易错点集合
面试攻略系列(三)-- 高级开发工程师面试问些啥?
jenkins api create custom pipeline
RobotFramework 之 库与关键字
ArcEngine(八) 选择要素并高亮显示
glibc memory management model freeing C library memory cache
X264性能优化