-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
[gz] optical flow support #23456
Closed
Closed
[gz] optical flow support #23456
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
ROMFS/px4fmu_common/init.d-posix/airframes/4014_gz_x500_mono_cam_down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
# | ||
# @name Gazebo x500 mono cam | ||
# | ||
# @type Quadrotor | ||
# | ||
|
||
PX4_SIM_MODEL=${PX4_SIM_MODEL:=x500_mono_cam_down} | ||
|
||
. ${R}etc/init.d-posix/airframes/4001_gz_x500 | ||
|
||
param set-default EKF2_OF_CTRL 1 | ||
param set-default EKF2_RNG_A_VMAX 3 | ||
|
||
echo "disabling Sim GPS sats" | ||
param set-default SIM_GPS_USED 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule gz
updated
16 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
############################################################################ | ||
# | ||
# Copyright (c) 2019 PX4 Development Team. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in | ||
# the documentation and/or other materials provided with the | ||
# distribution. | ||
# 3. Neither the name PX4 nor the names of its contributors may be | ||
# used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
############################################################################ | ||
|
||
find_package(gz-transport NAMES gz-transport13) | ||
find_package(OpenCV REQUIRED) | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_Add(OpticalFlow | ||
GIT_REPOSITORY https://github.com/PX4/PX4-OpticalFlow.git | ||
GIT_TAG master | ||
PREFIX ${CMAKE_BINARY_DIR}/OpticalFlow | ||
INSTALL_DIR ${CMAKE_BINARY_DIR}/OpticalFlow/install | ||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> | ||
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/OpticalFlow/install/lib/libOpticalFlow.so | ||
) | ||
|
||
ExternalProject_Get_Property(OpticalFlow install_dir) | ||
|
||
message(WARNING "OpticalFlow install dir: ${install_dir}") | ||
|
||
set(OpticalFlow_INCLUDE_DIRS ${install_dir}/include) | ||
|
||
# If Harmonic not found, look for GZ Garden libraries | ||
if(NOT gz-transport_FOUND) | ||
find_package(gz-transport NAMES gz-transport12) | ||
endif() | ||
|
||
if(gz-transport_FOUND) | ||
|
||
add_compile_options(-frtti -fexceptions) | ||
|
||
set(GZ_TRANSPORT_VER ${gz-transport_VERSION_MAJOR}) | ||
|
||
if(GZ_TRANSPORT_VER GREATER_EQUAL 12) | ||
set(GZ_TRANSPORT_LIB gz-transport${GZ_TRANSPORT_VER}::core) | ||
else() | ||
set(GZ_TRANSPORT_LIB ignition-transport${GZ_TRANSPORT_VER}::core) | ||
endif() | ||
|
||
px4_add_library(gz_camera | ||
gz_camera.hpp | ||
gz_camera.cpp | ||
) | ||
|
||
set(OpticalFlow_LIBS ${install_dir}/lib/libOpticalFlow.so) | ||
|
||
target_compile_options(gz_camera PRIVATE ${MAX_CUSTOM_OPT_LEVEL}) | ||
target_include_directories(gz_camera PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${OpenCV_INCLUDE_DIRS} ${OpticalFlow_INCLUDE_DIRS}) | ||
target_link_libraries(gz_camera PRIVATE ${GZ_TRANSPORT_LIB} ${OpenCV_LIBS} ${OpticalFlow_LIBS}) | ||
|
||
add_dependencies(gz_camera OpticalFlow) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "gz_camera.hpp" | ||
|
||
#include <gz/msgs.hh> | ||
#include <gz/math.hh> | ||
#include <gz/transport.hh> | ||
|
||
// #include <opencv2/opencv.hpp> | ||
#include "flow_opencv.hpp" | ||
#include <iostream> | ||
|
||
OpticalFlowOpenCV *_optical_flow = nullptr; | ||
int _dt_us = 0; | ||
|
||
int calculate_flow(const gz::msgs::Image &image_msg, uint64_t sim_time, int &integration_time, float &flow_x, | ||
float &flow_y) | ||
{ | ||
if (!_optical_flow) { | ||
float hfov = 1.74; | ||
int output_rate = 30; | ||
int image_width = image_msg.width(); | ||
int image_height = image_msg.height(); | ||
float focal_length = (image_width / 2.0f) / tan(hfov / 2.0f); | ||
|
||
_optical_flow = new OpticalFlowOpenCV(focal_length, focal_length, output_rate, image_width, image_height); | ||
} | ||
|
||
cv::Mat image = cv::Mat(image_msg.height(), image_msg.width(), CV_8UC3, (void *)image_msg.data().c_str()); | ||
|
||
cv::Mat gray_image; | ||
cv::cvtColor(image, gray_image, cv::COLOR_RGB2GRAY); | ||
|
||
int quality = _optical_flow->calcFlow(gray_image.data, sim_time, integration_time, flow_x, flow_y); | ||
|
||
return quality; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#include <gz/msgs/image.pb.h> | ||
|
||
int calculate_flow(const gz::msgs::Image &image_msg, uint64_t sim_time, int &integration_time, float &flow_x, | ||
float &flow_y); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we should add a sensor plugin for an optical flow sensor, not calculate optical flow inside the gzbridge. Then it is not a bridge anymore
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.
hmm yeah I was thinking about that. I need to figure out how to create a gz plugin that is launched with sim since it doesn't exist yet for gz