質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

2153閲覧

.bagファイルのサイズを圧縮し再生する方法について

reiya_123

総合スコア57

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2021/11/18 01:44

前提・実現したいこと

https://qiita.com/nataly510/items/c676a28a1119907a560d
上記のサイトをみて、realsenseを使い動画を保存し再生しました。
しかし、かなり動画のサイズが大きく困っています。
「rosbag compress」圧縮コマンドを使っても圧縮したまま再生はできていません。
圧縮したままpythonコード(下記2つ目のコード)で実行する方法をありますでしょうか。
宜しくお願い致します。

保存する

python3.8

1import pyrealsense2 as rs 2import numpy as np 3import cv2 4import time 5# Configure depth and color streams 6config = rs.config() 7config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) 8config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) 9config.enable_record_to_file('d435data.bag') 10# Start streaming 11pipeline = rs.pipeline() 12pipeline.start(config) 13start = time.time() 14frame_no = 1 15try: 16 while True: 17 # Wait for a coherent pair of frames: depth and color 18 frames = pipeline.wait_for_frames() 19 color_frame = frames.get_color_frame() 20 ir_frame = frames.get_infrared_frame() 21 fps = frame_no / (time.time() - start) 22 print(fps) 23 frame_no = frame_no+1 24 if not ir_frame or not color_frame : 25 ir_image = np.asanyarray(ir_frame .get_data()) 26 color_image = np.asanyarray(color_frame.get_data()) 27 28finally: 29 pipeline.stop()

再生する

import pyrealsense2 as rs import numpy as np import cv2 # ストリーム(Color/Depth/Infrared)の設定 config = rs.config() # ↓ ここでファイル名設定 config.enable_device_from_file('d435data.bag') config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # ストリーミング開始 pipeline = rs.pipeline() profile = pipeline.start(config) try: while True: # フレーム待ち(Color & Depth) frames = pipeline.wait_for_frames() ir_frame = frames.get_infrared_frame() depth_frame = frames.get_depth_frame() color_frame = frames.get_color_frame() if not depth_frame or not color_frame or not ir_frame : continue # Convert images to numpy arrays ir_image = np.asanyarray(ir_frame .get_data()) depth_image = np.asanyarray(depth_frame.get_data()) color_image = np.asanyarray(color_frame.get_data()) # Show images cv2.namedWindow('ir_image', cv2.WINDOW_AUTOSIZE) cv2.imshow('ir_image', ir_image2) cv2.namedWindow('color_image', cv2.WINDOW_AUTOSIZE) cv2.imshow('color_image', color_image) cv2.namedWindow('depth_image', cv2.WINDOW_AUTOSIZE) cv2.imshow('depth_image', depth_image) cv2.waitKey(1) finally: # Stop streaming pipeline.stop()

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問