当前位置:网站首页>学习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()
边栏推荐
- Q_04_05 使用Qubits
- LeetCode 37. Solve Sudoku
- 七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
- pytest 之 allure报告
- 从房产中介到程序员--80后张江男
- offset、client、scroll、window.pageYOffset比较
- glibc memory management model freeing C library memory cache
- 2.微服务'黑话'集锦及Eureka注册中心相关概念
- 【瑞吉外卖】day05:增、删、改、查分类以及公共字段自动填充
- 蓝桥历届真题-跑步锻炼
猜你喜欢

RTSP协议讲解

render解析

kustomize entry example and basic syntax instructions

GIN Bind模式获取参数和表单验证

Periodic sharing of Alibaba Da Tao system model governance

gin's middleware and routing grouping

剑指offer,剪绳子2

5G China unicom repeater network management protocol real-time requirements

RobotFramework 之 RF变量与标准库关键字使用

GIN初探,环境安装
随机推荐
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
Standing wave ratio calculation method
eslint语法规则报错
kustomize entry example and basic syntax instructions
Final assignment of R language data analysis in a university
The FPGA - work summary recently
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 15 Homework
Come and throw eggs.
NC7 买卖股票的最好时机(一)
面试攻略系列(三)-- 高级开发工程师面试问些啥?
JZ7 重建二叉树
【瑞吉外卖】day05:增、删、改、查分类以及公共字段自动填充
Record the system calls and C library functions used in this project-2
Clock frequency and baud rate count for serial communication in FPGA
RobotFramework 之 资源文件
GIN a preliminary study, the environment is installed
客户端连接rtsp的步骤
IDEA Gradle 常遇问题(一)
七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)