Hey,
In advance I will let you know that I not an expert in Computer Vision , that’s why there is a chance that my questions might look silly for you and for that I apologize .
So, I am trying to make a video with the following snippet code (testing now only).
import os
import cvb
import cv2
FPS = 25
CAMERA_WIDTH = 1920
CAMERA_HEIGHT = 1080
CAMERA_VERTICAL_OFFSET = 32
CAMERA_HORIZONTAL_OFFSET = 32
frameSize = (1920, 1080)
def deviceConfiguration(dev_node_map):
dev_node_map['Std::Width'].value = CAMERA_WIDTH
dev_node_map['Std::Height'].value = CAMERA_HEIGHT
# set the Frame rate in Hz
dev_node_map['Std::AcquisitionFrameRate'].value = FPS
dev_node_map['Std::OffsetX'].value = CAMERA_HORIZONTAL_OFFSET
dev_node_map['Std::OffsetY'].value = CAMERA_VERTICAL_OFFSET
dev_node_map['Cust::autoBrightnessMode'].value = "Active"
if __name__ == '__main__':
rate_counter = None
out = cv2.VideoWriter('recording.avi', cv2.VideoWriter_fourcc(*'DIVX'), 25, frameSize)
with cvb.DeviceFactory.open(cvb.install_path() + "/drivers/GenICam.vin", port=0) as device:
deviceConfiguration(device.node_maps["Device"])
device.node_maps["Device"]['Cust::timestampControlLatch'].execute()
stream = device.stream
rate_counter = cvb.RateCounter()
stream.start()
for i in range(10):
rate_counter.step()
image, status = stream.wait()
if status == cvb.WaitStatus.Ok:
np_image = cvb.as_array(image, copy=False)
# save the frames
out.write(np_image)
imageRawTimeStamp = "{:.0f}".format(float(image.raw_timestamp))
print("Acquired image: " + str(i) + " | Timestamp: " + str(imageRawTimeStamp))
print("Acquired with: " + str(rate_counter.rate) + " fps")
stream.abort()
I checked other examples for python to resolve this issue. But no sucess, even if I specify the FPS to be 25, I am getting Low FPS or even getting no fps at all. You can check the output “nan” or some frames I am getting 0 value with the rawtimestamp you can see the result below:
Acquired image: 0 | Timestamp: 1612365745947438848
Acquired with: nan fps
Acquired image: 1 | Timestamp: 1612365745987438848
Acquired with: nan fps
Acquired image: 2 | Timestamp: 1612365746027438848
Acquired with: 12.048192771084338 fps
Acquired image: 3 | Timestamp: 1612365746067439104
Acquired with: 13.333333333333334 fps
Acquired image: 4 | Timestamp: 1612365746107439104
Acquired with: 14.285714285714286 fps
Acquired image: 5 | Timestamp: 1612365746147439104
Acquired with: 14.925373134328359 fps
Acquired image: 6 | Timestamp: 1612365746187439104
Acquired with: 15.384615384615385 fps
Acquired image: 7 | Timestamp: 1612365746227439360
Acquired with: 15.873015873015873 fps
Acquired image: 8 | Timestamp: 1612365746267439360
Acquired with: 16.39344262295082 fps
Acquired image: 9 | Timestamp: 1612365746307439360
Acquired with: 16.666666666666668 fps
I know the issue is with writing video using openCV, if I comment out the code for openCV, than I getting 25 fps, exactly. Additionally, I change my code to save the Images directly instead of video with the following code:
if status == cvb.WaitStatus.Ok:
np_image = cvb.as_array(image, copy=False)
rgb_imag = cv2.cvtColor(np_image, cv2.COLOR_BGR2RGB)
cv2.imwrite(imageRawTimeStamp+".bmp",np_image)
For .png
format fps is also getting dropped, the best is for .bmp
. I am getting 25 FPS but the problem is that it has storage issue. I have 1 TB SSD even I ran out of the DISK space very quickly. I got this information regarding the performance for different formats from this post different-performance-when-saving-different-formats and also tested it locally with different samples programs provided by stemmer imaging https://help.commonvisionblox.com/NextGen/14.0/cvbpy/examples.html
Now, my questions are:
- How can I skip maybe 10 or 15 frames in the beginning before the actual acquisition?
- What is the best way to save a multiple videos for 1 hour like for example 6 videos without getting FPS dropped? Also is there any kind of a timer where I can make use to make 10 minutes video (I have checked cvb.StopWatch()) but no success, I am lost. I know that there movie2 for video recording but It does not support Linux.
- When movie2 will be supported in Linux?
- Can I get information like how many frames are dropped during the acquisition? I already enabled the option in device setting that not to resend packets but I am curious If I can log this kind of information.
Thanks in advance, any kind of help would be appreciated.
Aftab