- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for my poor English.
I want to record only RGB video with PyRealsense2 and opencv-python, the config is below:
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 60)
But when I replayed the video I've recorded, I found that the number of frames is smaller than 60*the_time_I_spent_recording_in_seconds, in other words, the FPS is smaller than 60 (just 30 to 33).
My USB port is 3.2 and I prefer recording video with Python rather than Realsense Viewer.
Thnak you in advance for your apply.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, ElizaD_Intel,
I recorded a video with 30 FPS.
It received 1800 frames in 60.38 seconds (29.81FPS), so I think 30FPS works well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your reply, but I don't want to use Realsense Viewer cause the size of bag file is too big.
I prefer using Python code to record 60FPS video with Pyrealsense2 and opencv.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, ElizaD_Intel,
I tried that approach a few days ago, the drawback of this approach is that you can increase the FPS but can't control the FPS to be stable.
According to the datasheet of D435 (https://www.mouser.com/pdfdocs/Intel_D400_Series_Datasheet.pdf), D435 should support 60FPS well on resolution 640*480.
Thank you,
SHuan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, sahira,
I use Pyrealsense2 to get rgb frames and use opencv-python to write these frames into a video.
30 fps works well, but I fail to get rgb frames in 60 fps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's my code.
I run it on Jupyter Notebook. After running the code, you can see the RGB stream, press 'R' will start recording, and the stream will freeze, and press 'Q' will store the video.
**********************
import pyrealsense2 as rs
import numpy as np
import cv2
import datetime as dt
import threading as th
import multiprocessing as mp
import time
import os
class RGBRecordingClass(th.Thread):
def __init__(self, out, queue):
super(RGBRecordingClass, self).__init__()
self.stop_flag = th.Event()
self.stop_flag.set()
self.out = out
self.queue = queue
def run(self):
while self.stop_flag.isSet():
if not self.queue.empty():
self.out.write(self.queue.get())
print('RGB Thread Exitted')
def stop(self):
self.stop_flag.clear()
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
pipeline.start(config)
directory_path = '0429'
if not os.path.exists(directory_path):
os.mkdir(directory_path)
rgb_queue = mp.Queue()
frame_count=0
start_record = False
rgb_video_name = directory_path+'/rgb.avi'
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(rgb_video_name, fourcc, 30, (640, 480))
rgb_thd = RGBRecordingClass(out, rgb_queue)
rgb_thd.start()
try:
while True:
# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()
if not color_frame:
print('not ready')
# Convert images to numpy arrays
color_image = np.asanyarray(color_frame.get_data())
if start_record:
rgb_queue.put(color_image)
frame_count+=1
# Show images
if not start_record:
cv2.imshow('frame', color_image)
if cv2.waitKey(10) & 0xFF == ord('r'):
start_record = True
print('start recording...')
print(str(dt.datetime.now()))
if cv2.waitKey(10) & 0xFF == ord('q'):
break
finally:
# Stop streaming
print('end')
print('file saved')
print(frame_count)
print(str(dt.datetime.now()))
cv2.destroyAllWindows()
out.release()
pipeline.stop()
rgb_thd.stop()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I use RealSense Viewer to do streaming, 30 and 60 FPS both work well on 640*480 resolution, whether it's recording a bag file or not.
But the bag file is really too big, so it's excluded from my consideration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Supplement for the code above:
frame_count is the number of frames recorded, and it will show the time starting recording and finishing recording.
I calculate FPS by frame_count/(end time-start time)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's strange that when I enable auto exposure, the fps can reach 60 fps.
When I turn off auto exposure, the fps will drop to 32 fps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Besides, may you teach me how to set auto exposure with Pyrealsense2 (Python code)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jesus G.,
I've tried both opening and closing auto exposure,
but the fps still stuck at about 32.
Also, whether I set rs.option.auto_exposure_priority to 0 or 1, the fps still can't rise to 60.
I really want to record a video in 60fps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The file format I record the RGB video is .avi, so it can't be replayed with RS viewer.
The way how I count average FPS is (The number of frames catched)/(Total recording time).
I pasted the code 10 days ago above, replying to sahira.rizvi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
![](/skins/images/4399995709D76C02984DDB9A1DB96C28/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page