I have a ZED Box Orin NX 16GB
1x ZED X
1x ZED X Mini
I noticed that If i have 2 cameras running different FPS it causes frame drops:
Occasionally my test app works fine and i can have 1 camera running at 30 FPS while the other at 15FPS with minimal to no frame drops but almost 9 times out of 10 i get this odd scenario where the camera set to 30FPS actually only runs at 15~ FPS its as though its being throttled / blocked internally..
Please find attached my little test sample app:
#include <sl/Camera.hpp>
#include <iostream>
#include <thread>
#include <vector>
#include <atomic>
#include <chrono>
using namespace sl;
static const int FPS[] = {30,15}; //Change to 30,15
std::atomic<bool> running(true);
void runCamera(int id, uint32_t serial)
{
bool getImage = true;
bool getObjects = true;
bool getPoints = true;
bool getPosition = true;
bool getSensors = true;
std::cout << "RUNNING CAMERA " << id << " SN:" << serial << " FPS:" << FPS[id] << std::endl;
Camera zed;
InitParameters init;
#ifdef _WIN32
init.camera_resolution = RESOLUTION::HD720;
init.input.setFromCameraID(id);
#else
init.camera_resolution = RESOLUTION::SVGA;
init.input.setFromCameraID(id);
#endif
init.depth_mode = DEPTH_MODE::NEURAL_LIGHT;
init.coordinate_units = UNIT::METER;
init.camera_fps = FPS[id % 2];
init.depth_minimum_distance = 0;
init.depth_maximum_distance = 20;
init.depth_stabilization = 0;
auto status = zed.open(init);
std::cout << "Configured FPS: " << zed.getCameraInformation().camera_configuration.fps << std::endl;
if (status != ERROR_CODE::SUCCESS)
{
std::cout << "Failed to open camera: " << status << std::endl;
return;
}
PositionalTrackingParameters tracking;
tracking.mode = POSITIONAL_TRACKING_MODE::GEN_3;
tracking.enable_imu_fusion = true;
tracking.enable_pose_smoothing = false;
tracking.enable_area_memory = false;
tracking.set_floor_as_origin = false;
tracking.set_gravity_as_origin = true;
zed.enablePositionalTracking(tracking);
ObjectDetectionParameters obj_params;
obj_params.detection_model = OBJECT_DETECTION_MODEL::MULTI_CLASS_BOX_FAST;
obj_params.enable_tracking = true;
obj_params.enable_segmentation = false;
zed.enableObjectDetection(obj_params);
RuntimeParameters runtime;
runtime.confidence_threshold = 95;
runtime.measure3D_reference_frame = REFERENCE_FRAME::CAMERA;
Resolution res(960, 600);
Mat leftImage;
Mat pointCloud;
Pose pose;
Objects objects;
SensorsData sensors;
uint64_t frame = 0;
auto blockStart = std::chrono::high_resolution_clock::now();
double grabTimeSum = 0;
while (running)
{
auto grabStart = std::chrono::high_resolution_clock::now();
auto err = zed.grab(runtime);
auto grabEnd = std::chrono::high_resolution_clock::now();
double grabMs =
std::chrono::duration<double, std::milli>(grabEnd - grabStart).count();
grabTimeSum += grabMs;
if (err != ERROR_CODE::SUCCESS)
{
std::cout << "Grab failed: " << err << std::endl;
continue;
}
frame++;
if (getPosition)
zed.getPosition(pose, REFERENCE_FRAME::CAMERA);
if (getObjects)
zed.retrieveObjects(objects);
if (getImage)
zed.retrieveImage(leftImage, VIEW::LEFT, MEM::CPU, res);
if (getPoints)
zed.retrieveMeasure(pointCloud, MEASURE::XYZ, MEM::CPU, res);
if (getSensors)
zed.getSensorsData(sensors, TIME_REFERENCE::CURRENT);
if (frame % 50 == 0)
{
auto now = std::chrono::high_resolution_clock::now();
double elapsed =
std::chrono::duration<double>(now - blockStart).count();
double fps = 50.0 / elapsed;
double avgGrab = grabTimeSum / 50.0;
uint32_t dropped = zed.getFrameDroppedCount();
std::cout
<< "[" << serial << "]-[" << frame << "] "
<< "Dropped: " << dropped
<< " Avg FPS: " << fps
<< " Avg Grab: " << avgGrab << " ms"
<< std::endl;
blockStart = now;
grabTimeSum = 0;
}
}
zed.close();
}
int main()
{
auto devices = Camera::getDeviceList();
if (devices.empty())
{
std::cout << "No ZED cameras detected" << std::endl;
return 0;
}
std::vector<std::thread> cameraThreads;
for (int i = 0; i < devices.size(); i++)
{
auto sn = devices[i].serial_number;
std::cout << "Found camera: " << sn << std::endl;
cameraThreads.emplace_back(runCamera, i, sn);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
std::cout << "Press ENTER to stop..." << std::endl;
std::cin.get();
running = false;
for (auto &t : cameraThreads)
t.join();
return 0;
}
Regards,
David
