Skip to content
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

updated flip realsense #27

Merged
merged 8 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Added `rotateImage180` parameter to rotate the image when the camera is mounted upside down (https://github.com/robotology/yarp-device-realsense2/pull/27).

### Changed
- If all the distortion parameters are zero, explicitly specify that the image has `YARP_DISTORTION_NONE` distortion (https://github.com/robotology/yarp-device-realsense2/pull/26).
- Changed minimum required YARP version to 3.5 (https://github.com/robotology/yarp-device-realsense2/pull/26).
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Parameters used by this device are:
|:----------------------------:|:-----------------:|:--------------:|:------------:|:-------:|:-------------:|:---------------:|:-------------------------------------------------------------------------------------:|:---------------------------------------------------------------------:|
| `stereoMode` | - | bool | Read / write | | false | No(see notes) | Flag for using the realsense as stereo camera | This option is to use it with yarp::dev::ServerGrabber as network wrapper. The stereo images provided are raw images(yarp::sig::PixelMono) and note that not all the realsense devices have the stereo streams. |
| `verbose` | - | bool | Read / write | | false | No | Flag for enabling debug prints | |
| `rotateImage180` | | bool | Read / write | - | - | No | Flag for enabling rotating the image 180 degrees | Parameter useful when a camera is mounted upside down |
| `SETTINGS` | - | group | Read / write | - | - | Yes | Initial setting of the device. | Properties must be read/writable in order for setting to work |
| | `rgbResolution` | int, int | Read / write | pixels | - | Yes | Size of rgb image in pixels | 2 values expected as height, width |
| | `depthResolution` | int, int | Read / write | pixels | - | Yes | Size of depth image in pixels | Values are height, width |
Expand Down
26 changes: 22 additions & 4 deletions src/devices/realsense2/realsense2Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,12 @@ bool realsense2Driver::open(Searchable& config)
params.push_back(&(p.second));
}

if(config.check("rotateImage180")){
m_rotateImage180 = config.find("rotateImage180").asBool();
if (m_rotateImage180) {
yCInfo(REALSENSE2) << "parameter rotateImage180 enabled, the image is rotated";
}
}
m_verbose = config.check("verbose");
if (config.check("stereoMode")) {
m_stereoMode = config.find("stereoMode").asBool();
Expand Down Expand Up @@ -1072,8 +1078,16 @@ bool realsense2Driver::getImage(FlexImage& Frame, Stamp *timeStamp, rs2::framese
yCError(REALSENSE2) << "Device and local copy data size doesn't match";
return false;
}

memcpy((void*)Frame.getRawImage(), (void*)color_frm.get_data(), mem_to_wrt);
if (m_rotateImage180) {
for (int i = 0; i < (color_frm.get_width() * color_frm.get_height()); i++) {
for (size_t pixelIndex = 0; pixelIndex < bytesPerPixel(format); pixelIndex++) {
((char *)Frame.getRawImage())[i * bytesPerPixel(format) + pixelIndex] = ((char *)color_frm.get_data())[
( Frame.getRawImageSize() - ((i+1) * bytesPerPixel(format) ) + pixelIndex];
}
}
} else {
memcpy((void*)Frame.getRawImage(), (void*)color_frm.get_data(), mem_to_wrt);
}
m_rgb_stamp.update();
if (timeStamp != nullptr)
{
Expand Down Expand Up @@ -1102,10 +1116,14 @@ bool realsense2Driver::getImage(depthImage& Frame, Stamp *timeStamp, const rs2::

float* rawImage = &Frame.pixel(0,0);
const auto * rawImageRs =(const uint16_t *) depth_frm.get_data();

for(int i = 0; i < w * h; i++)
{
rawImage[i] = m_scale * rawImageRs[i];

if (m_rotateImage180) {
rawImage[i] = m_scale * rawImageRs[(w * h - 1) - i];
}else {
rawImage[i] = m_scale * rawImageRs[i];
}
}

m_depth_stamp.update();
Expand Down
2 changes: 2 additions & 0 deletions src/devices/realsense2/realsense2Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class realsense2Driver :
typedef yarp::os::Property Property;
typedef yarp::sig::FlexImage FlexImage;


public:
realsense2Driver();
~realsense2Driver() override = default;
Expand Down Expand Up @@ -141,6 +142,7 @@ class realsense2Driver :
bool m_needAlignment;
int m_fps;
float m_scale;
bool m_rotateImage180{false};
std::vector<cameraFeature_id_t> m_supportedFeatures;
};
#endif