-
Notifications
You must be signed in to change notification settings - Fork 0
enable preview for oak camera #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ DepthAI is fetched and built automatically via FetchContent. The first build tak | |
| cd IsaacTeleop | ||
|
|
||
| # Configure and build | ||
| cmake -B build | ||
| cmake -B build -DBUILD_PLUGIN_OAK_CAMERA=ON | ||
| cmake --build build --target camera_plugin_oak --parallel | ||
| ``` | ||
|
Comment on lines
+25
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Missing documentation for the new The README documents all CLI options but does not mention the new
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| #include "oak_camera.hpp" | ||
|
|
||
| #include "frame_sink.hpp" | ||
| #include "preview_stream.hpp" | ||
|
|
||
| #include <algorithm> | ||
| #include <iostream> | ||
|
|
@@ -42,18 +43,32 @@ OakCamera::OakCamera(const OakConfig& config, const std::vector<StreamConfig>& s | |
| for (const auto& [socket, name] : sensors) | ||
| std::cout << " Socket " << static_cast<int>(socket) << ": " << name << std::endl; | ||
|
|
||
| create_pipeline(config, streams, sensors); | ||
| if (sensors.find(dai::CameraBoardSocket::CAM_A) == sensors.end()) | ||
| throw std::runtime_error("Color sensor not found on CAM_A"); | ||
| auto color_sensor_name = sensors.find(dai::CameraBoardSocket::CAM_A)->second; | ||
| auto color_resolution = color_sensor_name == "OV9782" ? dai::ColorCameraProperties::SensorResolution::THE_800_P : | ||
| dai::ColorCameraProperties::SensorResolution::THE_1080_P; | ||
|
|
||
| m_device->startPipeline(*m_pipeline); | ||
| static constexpr const char* kPreviewStreamName = "ColorPreview"; | ||
|
|
||
| auto pipeline = create_pipeline(config, streams, color_resolution); | ||
|
|
||
| if (config.preview) | ||
| m_preview = PreviewStream::try_create(kPreviewStreamName, pipeline, color_resolution); | ||
|
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider logging when preview creation fails. If Proposed enhancement if (config.preview)
+ {
m_preview = PreviewStream::try_create(kPreviewStreamName, pipeline, color_resolution);
+ if (!m_preview)
+ std::cerr << "Warning: Preview requested but could not be initialized" << std::endl;
+ }🤖 Prompt for AI Agents |
||
|
|
||
| m_device->startPipeline(pipeline); | ||
|
|
||
| for (const auto& s : streams) | ||
| { | ||
| m_queues[s.camera] = m_device->getOutputQueue(core::EnumNameStreamType(s.camera), 8, false); | ||
| } | ||
|
|
||
| if (m_preview) | ||
| m_preview->setOutputQueue(m_device->getOutputQueue(kPreviewStreamName, 4, false)); | ||
|
|
||
| std::cout << "OAK camera pipeline started" << std::endl; | ||
| } | ||
|
|
||
| OakCamera::~OakCamera() = default; | ||
|
|
||
| dai::DeviceInfo OakCamera::find_device(const std::string& device_id) | ||
| { | ||
| auto devices = dai::Device::getAllAvailableDevices(); | ||
|
|
@@ -83,27 +98,27 @@ dai::DeviceInfo OakCamera::find_device(const std::string& device_id) | |
| // Pipeline construction | ||
| // ============================================================================= | ||
|
|
||
| void OakCamera::create_pipeline(const OakConfig& config, | ||
| const std::vector<StreamConfig>& streams, | ||
| const std::unordered_map<dai::CameraBoardSocket, std::string>& sensors) | ||
| dai::Pipeline OakCamera::create_pipeline(const OakConfig& config, | ||
| const std::vector<StreamConfig>& streams, | ||
| dai::ColorCameraProperties::SensorResolution color_resolution) | ||
| { | ||
| m_pipeline = std::make_shared<dai::Pipeline>(); | ||
| dai::Pipeline pipeline; | ||
|
|
||
| bool need_color = has_stream(streams, core::StreamType_Color); | ||
| bool need_mono_left = has_stream(streams, core::StreamType_MonoLeft); | ||
| bool need_mono_right = has_stream(streams, core::StreamType_MonoRight); | ||
|
|
||
| auto create_h264_output = [&](dai::Node::Output& source, const char* stream_name) | ||
| { | ||
| auto enc = m_pipeline->create<dai::node::VideoEncoder>(); | ||
| auto enc = pipeline.create<dai::node::VideoEncoder>(); | ||
| enc->setDefaultProfilePreset(config.fps, dai::VideoEncoderProperties::Profile::H264_BASELINE); | ||
| enc->setBitrate(config.bitrate); | ||
| enc->setQuality(config.quality); | ||
| enc->setKeyframeFrequency(config.keyframe_frequency); | ||
| enc->setNumBFrames(0); | ||
| enc->setRateControlMode(dai::VideoEncoderProperties::RateControlMode::CBR); | ||
|
|
||
| auto xout = m_pipeline->create<dai::node::XLinkOut>(); | ||
| auto xout = pipeline.create<dai::node::XLinkOut>(); | ||
| xout->setStreamName(stream_name); | ||
|
|
||
| source.link(enc->input); | ||
|
|
@@ -113,16 +128,9 @@ void OakCamera::create_pipeline(const OakConfig& config, | |
| // ---- Color camera ---- | ||
| if (need_color) | ||
| { | ||
| auto it = sensors.find(dai::CameraBoardSocket::CAM_A); | ||
| if (it == sensors.end()) | ||
| throw std::runtime_error("Color stream requested but no sensor found on CAM_A"); | ||
|
|
||
| auto resolution = it->second == "OV9782" ? dai::ColorCameraProperties::SensorResolution::THE_800_P : | ||
| dai::ColorCameraProperties::SensorResolution::THE_1080_P; | ||
|
|
||
| auto camRgb = m_pipeline->create<dai::node::ColorCamera>(); | ||
| auto camRgb = pipeline.create<dai::node::ColorCamera>(); | ||
| camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A); | ||
| camRgb->setResolution(resolution); | ||
| camRgb->setResolution(color_resolution); | ||
| camRgb->setFps(config.fps); | ||
| camRgb->setColorOrder(dai::ColorCameraProperties::ColorOrder::BGR); | ||
|
|
||
|
|
@@ -132,7 +140,7 @@ void OakCamera::create_pipeline(const OakConfig& config, | |
| // ---- Mono cameras ---- | ||
| if (need_mono_left) | ||
| { | ||
| auto monoLeft = m_pipeline->create<dai::node::MonoCamera>(); | ||
| auto monoLeft = pipeline.create<dai::node::MonoCamera>(); | ||
| monoLeft->setBoardSocket(dai::CameraBoardSocket::CAM_B); | ||
| monoLeft->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P); | ||
| monoLeft->setFps(config.fps); | ||
|
|
@@ -142,13 +150,15 @@ void OakCamera::create_pipeline(const OakConfig& config, | |
|
|
||
| if (need_mono_right) | ||
| { | ||
| auto monoRight = m_pipeline->create<dai::node::MonoCamera>(); | ||
| auto monoRight = pipeline.create<dai::node::MonoCamera>(); | ||
| monoRight->setBoardSocket(dai::CameraBoardSocket::CAM_C); | ||
| monoRight->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P); | ||
| monoRight->setFps(config.fps); | ||
|
|
||
| create_h264_output(monoRight->out, core::EnumNameStreamType(core::StreamType_MonoRight)); | ||
| } | ||
|
|
||
| return pipeline; | ||
| } | ||
|
|
||
| // ============================================================================= | ||
|
|
@@ -182,6 +192,9 @@ void OakCamera::update() | |
| m_sink->on_frame(frame); | ||
| ++m_frame_counts[type]; | ||
| } | ||
|
|
||
| if (m_preview) | ||
| m_preview->update(); | ||
| } | ||
|
|
||
| // ============================================================================= | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
🧩 Analysis chain
🌐 Web query:
SDL2 2.30.11 release date latest version💡 Result:
Sources:
[1] https://libsdl.org/release/ (SDL2-2.30.11 files dated 2025-01-01)
[2] https://discourse.libsdl.org/t/sdl-updated-to-version-2-30-11-for-release/56485 (commit/update for 2.30.11 on 01 Jan 2025)
[3] https://libsdl.org/release/ (SDL2-2.32.10 files dated 2025-09-01)
Consider updating to SDL2 2.32.10 or document the reason for pinning to 2.30.11.
SDL2 2.30.11 is available from libsdl.org, but version 2.32.10 was released in September 2025 and is currently the latest stable release. If remaining on 2.30.11 is intentional, add a comment explaining the rationale; otherwise, consider upgrading to the latest version.
🤖 Prompt for AI Agents