forked from ros-drivers/usb_cam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ethz-asl/pr-make-networks-work
Make learning work
- Loading branch information
Showing
23 changed files
with
407 additions
and
478 deletions.
There are no files selected for viewing
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
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,26 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug test_depth_anything_v2", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/build/devel/lib/usb_cam/test_depth_anything_v2", | ||
"cwd": "${workspaceFolder}", | ||
"environment": [], | ||
"externalConsole": false, | ||
"MIMode": "gdb", // Use gdb for debugging | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
} | ||
], | ||
"miDebuggerPath": "/usr/bin/gdb" | ||
} | ||
] | ||
} |
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,56 @@ | ||
#!/bin/bash | ||
source /opt/ros/noetic/setup.bash | ||
|
||
# Set paths for the model and plan files | ||
MODEL_PATH="test/resources/depth_anything_v2_vits_16.onnx" | ||
|
||
# Check if the ONNX model file exists | ||
if [ ! -f "$MODEL_PATH" ]; then | ||
# If the model file doesn't exist, check if the environment variable is set | ||
if [ -z "$DEPTH_ANYTHING_V2_VITS_16_LINK" ]; then | ||
echo "The model file does not exist, and the environment variable DEPTH_ANYTHING_V2_VITS_16_LINK is not set." | ||
exit 1 | ||
else | ||
# If the environment variable is set, download the model | ||
echo "ONNX model file not found. Attempting to download..." | ||
|
||
# Create the directory if it doesn't exist | ||
mkdir -p "$(dirname "$MODEL_PATH")" | ||
|
||
# Download the file | ||
if wget -O "$MODEL_PATH" "$DEPTH_ANYTHING_V2_VITS_16_LINK"; then | ||
echo "Download successful." | ||
else | ||
echo "Download failed." | ||
exit 1 | ||
fi | ||
fi | ||
else | ||
echo "ONNX model file already exists." | ||
fi | ||
|
||
# Build the project and run tests | ||
rm -rf build | ||
mkdir -p build | ||
cd build | ||
|
||
if cmake .. -DBUILD_TESTING=ON; then | ||
echo "CMake successful." | ||
if make test_depth_anything_v2; then | ||
echo "Make successful." | ||
else | ||
echo "Make failed." | ||
exit 1 | ||
fi | ||
else | ||
echo "CMake failed." | ||
exit 1 | ||
fi | ||
|
||
# Run the test executable | ||
if ./devel/lib/usb_cam/test_depth_anything_v2; then | ||
echo "Tests successful." | ||
else | ||
echo "Tests failed." | ||
exit 1 | ||
fi |
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,60 @@ | ||
#ifndef DEPTH_ANYTHING_HPP_ | ||
#define DEPTH_ANYTHING_HPP_ | ||
|
||
#include "interface.hpp" | ||
#include "ros/ros.h" | ||
#include <cv_bridge/cv_bridge.h> | ||
#include <opencv2/opencv.hpp> | ||
#include <sensor_msgs/Image.h> | ||
|
||
class DepthAnythingV2 : public LearningInterface { | ||
public: | ||
DepthAnythingV2(ros::NodeHandle* nh, std::string model_path) { | ||
_INPUT_SIZE = cv::Size(_HEIGHT, _WIDTH); | ||
_model_path = model_path; | ||
|
||
if (nh != nullptr) { | ||
_depth_publication = nh->advertise<sensor_msgs::Image>("depth_anything_v2", 1); | ||
} | ||
} | ||
|
||
void set_input(sensor_msgs::Image& msg) override { | ||
cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::RGB8); | ||
cv::Mat image = cv_ptr->image; | ||
|
||
// Change size to 518x518 (still uint8) | ||
cv::Mat resized_image; | ||
cv::resize(image, resized_image, _INPUT_SIZE); | ||
|
||
// Change to float32 between 0 and 1 | ||
std::vector<cv::Mat> channels; | ||
cv::split(resized_image, channels); | ||
for (uint8_t i = 0; i < 3; ++i) { | ||
channels[i].convertTo(channels[i], CV_32F, 1.0f / 255.0f); | ||
} | ||
cv::Mat float_image; | ||
cv::merge(channels, float_image); | ||
_input_data = float_image.reshape(1, 1).ptr<float>(0); | ||
} | ||
|
||
void publish() override { | ||
if (_depth_publication.getTopic() != "") { | ||
cv::Mat depth_prediction = cv::Mat(_HEIGHT, _WIDTH, CV_32FC1, _output_data); | ||
|
||
cv_bridge::CvImage depth_image; | ||
depth_image.header.stamp = ros::Time::now(); | ||
depth_image.header.frame_id = "depth_frame"; | ||
depth_image.encoding = sensor_msgs::image_encodings::TYPE_32FC1; | ||
depth_image.image = depth_prediction; | ||
_depth_publication.publish(depth_image.toImageMsg()); | ||
} | ||
} | ||
|
||
private: | ||
const size_t _HEIGHT = 518; | ||
const size_t _WIDTH = 518; | ||
cv::Size _INPUT_SIZE; | ||
ros::Publisher _depth_publication; | ||
}; | ||
|
||
#endif // DEPTH_ANYTHING_HPP_ |
Oops, something went wrong.