参考文章1:opencv之读入一幅图像,显示图像以及如何保存一副图像,基础操作

参考文章2:python—OpenCV2中 cv2.VideoCapture(),read(),waitKey()的使用

参考文章3:asicll常用对照表

参考文章4:python opencv按照一定间隔保存视频帧

# -*- encoding: utf-8 -*-
"""
@File    : save_image.py
@Time    : 2019/10/23 14:44
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import pyrealsense2 as rs
import numpy as np
import cv2
import os
import time# Configure depth and color streams
pipeline = rs.pipeline()
# 创建 config 对象:
config = rs.config()
# config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)# Start streaming
pipeline.start(config)try:while True:# Wait for a coherent pair of frames(一对连贯的帧): depth and colorframes = pipeline.wait_for_frames()# depth_frame = frames.get_depth_frame()color_frame = frames.get_color_frame()if not color_frame:continuecolor_image = np.asanyarray(color_frame.get_data())# Show imagescv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('RealSense', color_image)c = cv2.waitKey(1)# 手动采集(空格键)# 敲击空格将图像保存(空格的ascii码是32)if c == 32:# 计算文件夹里jpg文件数量,以便于关闭软件后重新打开采集不会将已有图片覆盖count = 0for filename in os.listdir('../imgs/'):if filename.endswith('.jpg'):count += 1# print(count)# 保存图像,保存到上一层的imgs文件夹内,以1、2、3、4...为文件名保存图像cv2.imwrite('../imgs/{}.jpg'.format(count + 1), color_image)# 自动采集(回车键)# 如果按下回车键则自动采集(回车键ascii码是13)if c == 13:# 获取时间以在循环中判断是否经过了某段时间time0 = time.time()while True:# 之前卡死是因为进了这个循环出不去了了,没法wait_for_frames同时opencv窗口也没法waitKey刷新所以就卡死了,所以必须再把wait_for_frames和waitKey加进来# Wait for a coherent pair of frames(一对连贯的帧): depth and colorframes = pipeline.wait_for_frames()# depth_frame = frames.get_depth_frame()color_frame = frames.get_color_frame()if not color_frame:continuecolor_image = np.asanyarray(color_frame.get_data())# Show imagescv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('RealSense', color_image)c = cv2.waitKey(1)# 计算文件夹里jpg文件数量,以便于关闭软件后重新采集不会将已有图片覆盖count = 0for filename in os.listdir('../imgs/'):if filename.endswith('.jpg'):count += 1# 设置延时时间(单位:秒)time_delay = 1# 使用经过的时间差来对操作进行延时,这样可避免流停滞,但此方法不完全准确,特别是在我们的操作耗时较长的情况下,延时误差较大。当我们将操作的时间视为无穷小时,此方法准确if (time.time() - time0) > time_delay:# 可以看到,实际延时微微大于我们设置的延时时间print(time.time() - time0)# 1.0003252029418945# 1.0017242431640625# 1.0030531883239746# 1.004326343536377# 1.0044221878051758# 1.008774995803833# 1.005782127380371# 1.0061774253845215# 1.010535717010498# 保存图像,保存到上一层的imgs文件夹内,以1、2、3、4...为文件名保存图像cv2.imwrite('../imgs/{}.jpg'.format(count + 1), color_image)# 只让操作在某时间段内只执行一次,下次执行需在延时时间time_delay(秒)后time0 += time_delay# 延时一下,不然保存太快翻车咋办# 之前卡顿的原因是用了time.sleep函数,导致wait_for_frames变慢了,不能用sleep函数# time.sleep(1)if c == 27:break# 如果按下ESC则关闭窗口(ESC的ascii码为27),同时跳出循环if c == 27:cv2.destroyAllWindows()breakfinally:# Stop streamingpipeline.stop()


python opencv 从Intel Realsense D435 视频流中读取并显示帧,按下空格将图像保存到指定文件夹,按下回车自动以一定时间间隔保存图像至指定文件夹相关推荐

  1. Intel Realsense D435 奇怪的现象记录:帧卡住,但wait_for_frame()不报错

    如图,一号四号摄像头视频流显示卡住了,但流传输并未停止,使用目标检测发现,摄像头每次传过来的都是同样的一帧: 但也有可能是加了这句,导致空帧被跳过了: if not locals()['aligned ...

  2. python Intel Realsense D435 多线程资源分配问题(卡住、卡死)

    在使用python多线程调用Intel Realsense D435多个摄像头时,发现pyrealsense的例如pipeline.start().context.query_devices()函数会 ...

  3. Intel Realsense D435 python 实战(一)

    20200519 D435包含一个有源红外摄像头,有源红外摄像头旁边的两个能够输出黑白图像,应属于双目测距, 1战 2019年8月22日 公司的Intel Realsense D435摄像头的识别系统 ...

  4. python opencv cv.applyColorMap()函数(颜色映射)ColormapTypes【将Intel Realsense D435深度图的黑白图映射为彩色图】

    文章目录 API ColormapTypes 完整应用代码[将深度图的黑白图映射为彩色图] map原理 能否map CV_24UC3的? API def applyColorMap(src, colo ...

  5. Intel Realsense D435 在C/C++中表示的frame_set就是python中的frames?【wait_for_frames()】

    参考文章:Intel Realsense D435 (Python Wrapper)example03: Stream Alignment 流对齐 通过深度去除背景

  6. Intel Realsense d435 使用python对深度图进行预处理

    Intel Realsense d435 使用python对深度图进行预处理 本文中主要翻译一下一篇关于深度图预处理过滤器的内容,后面还会有关于距离测量的. 原文中的图像显示,是使用matplotli ...

  7. python如何拟合三维平面(拟合Intel Realsense D435深度数据点)

    文章目录 拟合Intel Realsense D435深度数据点 参考文章:[MQ笔记]超简单的最小二乘法拟合平面(Python) import numpy as np import matplotl ...

  8. Intel Realsense D435 python (Python Wrapper)examples 官方案例汇总

    From pypi/pyrealsense 1.Intel Realsense D435 python (Python Wrapper)example -1: quick start (快速开始) F ...

  9. Intel Realsense D435 python (Python Wrapper)example00: NumPy Integration 将深度帧数据转换为 Numpy 数组进行处理

    NumPy Integration: Librealsense frames support the buffer protocol. A numpy array can be constructed ...

最新文章

  1. 5分钟 搭建免费个人博客
  2. 设备物理像素、设备独立像素
  3. 熬夜与不熬夜,10年后差距到底有多大?惊了!
  4. mysql 释放错误连接_JSP连接MySQL后数据库链接释放的错误
  5. bugku ctf 杂项 啊哒 writeup || foremost的安装
  6. CPU缓存越大计算机的性能越好,CPU缓存真的越大越好?小心你的钱包
  7. 红橙Darren视频笔记 流式布局tagLayout measure layout方法学习 adapter使用 学习感悟
  8. 以太坊上已有十个DeFi协议的锁仓量超过10亿美元
  9. 机器学习课程笔记【三】广义线性模型(2)-构建广义线性模型
  10. matlab最佳拟合的指标是什么意思,Matlab拟合好坏常用指标
  11. 怎么将PDF转换成jpg图片?免费方法了解一下
  12. 计算机设置从光盘启动怎么办,[光盘启动]BIOS设置从光盘光驱启动教程
  13. 清除WKWebView cookies
  14. 李飞飞:如何教计算机理解图片
  15. ctfshow命令执行篇
  16. 【Qt】 Fractal Designer 5.2 Bug Report
  17. 内外网双网卡路由配置
  18. 【Java】第7章 Java 类和对象 头歌Educoder实训作业(七)
  19. AUTOSAR - WDGM认知过程(二):配置分析
  20. 浏览器中的主页图标不见了

热门文章

  1. 【学习笔记】Python - NumPy
  2. 【PM模块】故障维护简介
  3. ABAP 查询性能提高之我见
  4. LSMW批处理使用方法(12)_步骤16、17
  5. 加快LOOP嵌套循环的一个方法
  6. 调用BAPI_MATERIAL_SAVEDATA批量创建/修改物料
  7. MR21 VS MR22 对CKMLCP结果影响
  8. SAP 生产订单结算
  9. Download Excel
  10. 2021最新报告:一文洞察智慧金融发展现状