mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 02:13:33 +08:00
Remove OpenCV dependency from gz plugin gstreamer (#24519)
Co-authored-by: jmackay2 <jmackay2@gmail.com>
This commit is contained in:
@@ -34,7 +34,6 @@
|
|||||||
project(GstCameraSystem)
|
project(GstCameraSystem)
|
||||||
|
|
||||||
# Find required packages
|
# Find required packages
|
||||||
find_package(OpenCV REQUIRED)
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
|
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
|
||||||
pkg_check_modules(GSTREAMER_APP REQUIRED gstreamer-app-1.0)
|
pkg_check_modules(GSTREAMER_APP REQUIRED gstreamer-app-1.0)
|
||||||
@@ -49,7 +48,6 @@ target_link_libraries(${PROJECT_NAME}
|
|||||||
PUBLIC gz-plugin${GZ_PLUGIN_VERSION}::gz-plugin${GZ_PLUGIN_VERSION}
|
PUBLIC gz-plugin${GZ_PLUGIN_VERSION}::gz-plugin${GZ_PLUGIN_VERSION}
|
||||||
PUBLIC gz-sim${GZ_SIM_VERSION}::gz-sim${GZ_SIM_VERSION}
|
PUBLIC gz-sim${GZ_SIM_VERSION}::gz-sim${GZ_SIM_VERSION}
|
||||||
PUBLIC gz-transport${GZ_TRANSPORT_VERSION}::gz-transport${GZ_TRANSPORT_VERSION}
|
PUBLIC gz-transport${GZ_TRANSPORT_VERSION}::gz-transport${GZ_TRANSPORT_VERSION}
|
||||||
PUBLIC ${OpenCV_LIBS}
|
|
||||||
PUBLIC ${GSTREAMER_LIBRARIES}
|
PUBLIC ${GSTREAMER_LIBRARIES}
|
||||||
PUBLIC ${GSTREAMER_APP_LIBRARIES}
|
PUBLIC ${GSTREAMER_APP_LIBRARIES}
|
||||||
)
|
)
|
||||||
@@ -58,7 +56,6 @@ target_include_directories(${PROJECT_NAME}
|
|||||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
|
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
PUBLIC px4_gz_msgs
|
PUBLIC px4_gz_msgs
|
||||||
PUBLIC ${OpenCV_INCLUDE_DIRS}
|
|
||||||
PUBLIC ${GSTREAMER_INCLUDE_DIRS}
|
PUBLIC ${GSTREAMER_INCLUDE_DIRS}
|
||||||
PUBLIC ${GSTREAMER_APP_INCLUDE_DIRS}
|
PUBLIC ${GSTREAMER_APP_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -206,17 +206,11 @@ void GstCameraSystem::onImage(const gz::msgs::Image &msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the image data to OpenCV format
|
|
||||||
cv::Mat frame(msg.height(), msg.width(), CV_8UC3);
|
|
||||||
|
|
||||||
// Check pixel format and convert if necessary
|
// Check pixel format and convert if necessary
|
||||||
if (msg.pixel_format_type() == gz::msgs::PixelFormatType::RGB_INT8) {
|
if (msg.pixel_format_type() == gz::msgs::PixelFormatType::RGB_INT8) {
|
||||||
// Copy RGB data directly
|
|
||||||
memcpy(frame.data, msg.data().c_str(), msg.data().size());
|
|
||||||
|
|
||||||
// Process the frame
|
// Process the frame
|
||||||
std::lock_guard<std::mutex> lock(_frameMutex);
|
std::lock_guard<std::mutex> lock(_frameMutex);
|
||||||
frame.copyTo(_currentFrame);
|
_currentFrame = msg;
|
||||||
_newFrameAvailable = true;
|
_newFrameAvailable = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -412,7 +406,7 @@ void GstCameraSystem::gstThreadFunc()
|
|||||||
while (_running) {
|
while (_running) {
|
||||||
std::unique_lock<std::mutex> lock(_frameMutex);
|
std::unique_lock<std::mutex> lock(_frameMutex);
|
||||||
|
|
||||||
if (_newFrameAvailable && !_currentFrame.empty()) {
|
if (_newFrameAvailable) {
|
||||||
// Push RGB data directly - we configured the caps to accept RGB
|
// Push RGB data directly - we configured the caps to accept RGB
|
||||||
const guint size = _width * _height * 3; // RGB is 3 bytes per pixel
|
const guint size = _width * _height * 3; // RGB is 3 bytes per pixel
|
||||||
GstBuffer *buffer = gst_buffer_new_allocate(nullptr, size, nullptr);
|
GstBuffer *buffer = gst_buffer_new_allocate(nullptr, size, nullptr);
|
||||||
@@ -421,8 +415,8 @@ void GstCameraSystem::gstThreadFunc()
|
|||||||
GstMapInfo map;
|
GstMapInfo map;
|
||||||
|
|
||||||
if (gst_buffer_map(buffer, &map, GST_MAP_WRITE)) {
|
if (gst_buffer_map(buffer, &map, GST_MAP_WRITE)) {
|
||||||
// Copy RGB data directly from the OpenCV Mat
|
// Copy RGB data directly from the current frame
|
||||||
memcpy(map.data, _currentFrame.data, size);
|
memcpy(map.data, _currentFrame.data().c_str(), size);
|
||||||
gst_buffer_unmap(buffer, &map);
|
gst_buffer_unmap(buffer, &map);
|
||||||
|
|
||||||
// Add timing information for smoother playback
|
// Add timing information for smoother playback
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <opencv2/opencv.hpp>
|
|
||||||
|
|
||||||
#include <gz/sim/System.hh>
|
#include <gz/sim/System.hh>
|
||||||
#include <gz/transport/Node.hh>
|
#include <gz/transport/Node.hh>
|
||||||
@@ -82,7 +81,7 @@ private:
|
|||||||
gz::transport::Node _node;
|
gz::transport::Node _node;
|
||||||
|
|
||||||
// Image processing
|
// Image processing
|
||||||
cv::Mat _currentFrame;
|
gz::msgs::Image _currentFrame;
|
||||||
std::mutex _frameMutex;
|
std::mutex _frameMutex;
|
||||||
std::atomic<bool> _newFrameAvailable {};
|
std::atomic<bool> _newFrameAvailable {};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ This plugin provides GStreamer-based video streaming capabilities for cameras in
|
|||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- GStreamer 1.0 with development files
|
- GStreamer 1.0 with development files
|
||||||
- OpenCV with development files
|
|
||||||
- NVIDIA drivers and CUDA (optional, for hardware acceleration)
|
- NVIDIA drivers and CUDA (optional, for hardware acceleration)
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user