Queue for stream name doesn't exist
Describe the bug When I am trying to use the ColorCamera Node to display a simple preview I get the error:
libc++abi: terminating due to uncaught exception of type std::runtime_error:
Queue for stream name 'camera' doesn't exist
Minimal Reproducible Example (link is dead) For my IDE I use CLion 2024.2 with C++23. My CMake File looks like this:
cmake_minimum_required(VERSION 3.29)
project(sarcat-oak-firmware)
set(CMAKE_CXX_STANDARD 23)
add_executable(sarcat-oak-firmware
src/main.cpp
src/sarcatOakFirmware.cpp)
include_directories(include)
find_package(depthai CONFIG REQUIRED)
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
target_link_libraries(sarcat-oak-firmware PRIVATE depthai::opencv ${OpenCV_LIBS})
target_include_directories(sarcat-oak-firmware PRIVATE ${OpenCV_INCLUDE_DIRS})
I am currently writing a library that serves the purpose of outputting a video stream from the device and implementing a yolov8 network. Currently I am struggling with the video stream.
main.cpp
#include "sarcatOakFirmware.hpp"
sarcatOakFirmware::Oak oak;
int main() {
oak.start();
sarcatOakFirmware::Camera camera(640, 640, "camera");
camera.setVideoStream(true);
std::cout << camera.display() << std::endl;
return 0;
}
sarcatOakFirmware.hpp
#ifndef SARCAT_OAK_FIRMWARE_SARCATOAKFIRMWARE_HPP
#define SARCAT_OAK_FIRMWARE_SARCATOAKFIRMWARE_HPP
#include "depthai/depthai.hpp"
#include "opencv2/opencv.hpp"
#include <string>
#include <vector>
#include <memory>
using ERROR = int;
namespace internal {
extern std::unique_ptr<dai::Pipeline> pipeline;
extern std::unique_ptr<dai::Device> device;
extern bool _camera;
}
namespace internal::camera {
extern std::shared_ptr<dai::node::ColorCamera> _camera;
extern std::shared_ptr<dai::node::XLinkOut> _cameraOutput;
extern int _width;
extern int _height;
extern std::string _streamName;
extern bool _isStreamingVideo;
extern bool _isRecordingVideo;
}
namespace sarcatOakFirmware {
class Oak {
public:
ERROR start();
};
class Camera {
public:
Camera(int width, int height, const std::string& streamName);
ERROR setVideoStream(bool enaabled = false);
ERROR setRecordVideo(bool enabled = false);
ERROR display();
};
}
#endif // SARCAT_OAK_FIRMWARE_SARCATOAKFIRMWARE_HPP
sarcatOakFirmware.cpp
#include "sarcatOakFirmware.hpp"
namespace internal {
std::unique_ptr<dai::Pipeline> pipeline;
std::unique_ptr<dai::Device> device;
bool _camera = false;
}
namespace internal::camera{
std::shared_ptr<dai::node::ColorCamera> _camera;
std::shared_ptr<dai::node::XLinkOut> _cameraOutput;
int _width = 0;
int _height = 0;
std::string _streamName;
bool _isStreamingVideo = false;
bool _isRecordingVideo = false;
}
ERROR sarcatOakFirmware::Oak::start() {
internal::pipeline = std::make_unique<dai::Pipeline>();
internal::device = std::make_unique<dai::Device>(*internal::pipeline, dai::UsbSpeed::HIGH);
return 0;
}
sarcatOakFirmware::Camera::Camera(int width, int height, const std::string& streamName) {
if (!internal::pipeline) {
internal::pipeline = std::make_unique<dai::Pipeline>();
}
internal::camera::_camera = internal::pipeline->create<dai::node::ColorCamera>();
internal::camera::_cameraOutput = internal::pipeline->create<dai::node::XLinkOut>();
internal::camera::_camera->setPreviewSize(width, height);
internal::camera::_camera->setBoardSocket(dai::CameraBoardSocket::CAM_A);
internal::camera::_camera->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
internal::camera::_camera->setInterleaved(true);
internal::camera::_camera->setColorOrder(dai::ColorCameraProperties::ColorOrder::RGB);
internal::camera::_cameraOutput->setStreamName(streamName);
internal::camera::_camera->preview.link(internal::camera::_cameraOutput->input);
internal::camera::_width = width;
internal::camera::_height = height;
internal::camera::_streamName = streamName;
internal::camera::_isStreamingVideo = false;
internal::camera::_isRecordingVideo = false;
}
ERROR sarcatOakFirmware::Camera::display() {
if (internal::camera::_isStreamingVideo) {
if (!internal::device) {
std::cerr << "Device not initialized!" << std::endl;
return -1;
}
std::cout << "Stream Started, press ESC to Exit!" << std::endl;
auto cameraQueue = internal::device->getOutputQueue(internal::camera::_cameraOutput->getStreamName(), 8, false);
while (true) {
cv::Mat frame = cameraQueue->get<dai::ImgFrame>()->getCvFrame();
cv::imshow(internal::camera::_streamName, frame);
if (cv::waitKey(1) == 27) {
break;
}
}
return 0;
}
else {
return -1;
}
}
ERROR sarcatOakFirmware::Camera::setVideoStream(bool enabled) {
internal::camera::_isStreamingVideo = enabled;
return 0;
}
Expected behavior I should get a window that outputs a 640x640 preview of the Oak Camera.
Screenshots
Pipeline Graph
Couldn't figure out how to use the tool with c++
@maupwastaken thanks for the issue report!
Would you mind trying to do a simpler MRE where the code would be in a single file?