Giter Site home page Giter Site logo

Comments (4)

sjorsjee avatar sjorsjee commented on August 21, 2024 1

Thank you!
That was the problem.
I think it is fixed now.

from o3d3xx-ros.

tpanzarella avatar tpanzarella commented on August 21, 2024

To do what you want, you just need to do something like:

cv::Mat xim, yim, zim;
std::vector<cv::Mat> channels(3);
cv::split(xyz, channels);

xim = channels[0];
yim = channels[1];
zim = channels[2];

Now each individual spatial plane of the image is available as a single channel image with the same number of rows, columns, and pixel depth (namely signed 16-bit integers) as the original 3-channel image.

Now, what I am suggesting above is what you should do. However, to answer one of your concerns above:

but by using this way we only get half of the pixels.

This is a result of (using your z-image plane as an example):

img_z.at<uchar>(row, col/2) = result;

The pixel depth is 16-bits not 8.

But again, your code is over complicating things. Use the above snippet I have posted in and you should be good to go.

from o3d3xx-ros.

sjorsjee avatar sjorsjee commented on August 21, 2024

Thanks for your reaction.

if i understand you correctly i can use it this way.
i stil get the wrong numbers. can it be that the image is being converted wrong from the topic ?

sorry for bothering you

// ROS
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <stdlib.h>
#include <std_msgs/String.h>

// OpenCV
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
namespace enc = sensor_msgs::image_encodings;

// Read message
void read_image(const sensor_msgs::ImagePtr& msg)
{
// Read image
cv_bridge::CvImagePtr img_ptr;

try
	{
  		img_ptr = cv_bridge::toCvCopy(msg, enc::TYPE_16SC3);
	}
catch (cv_bridge::Exception& e)
	{
  		ROS_ERROR("cv_bridge exception: %s", e.what());
  		return;
	}
	cv::Mat xim, yim, zim;
	std::vector<cv::Mat> channels(3);
	cv::split(img_ptr->image, channels);

	xim = channels[0];
	yim = channels[1];
	zim = channels[2];

ROS_INFO("img %i",zim.at(89,34));

}

// Start and initialize the node
int main(int argc, char **argv)
{
// Initialize ros node
ros::init(argc, argv, "listener");
ros::NodeHandle nh;

// Subscribe to the topic
ros::Subscriber sub = nh.subscribe("o3d3xx/camera/xyz_image", 100, read_image);

// Wait for messages
ros::spin();

}

from o3d3xx-ros.

tpanzarella avatar tpanzarella commented on August 21, 2024

Two things:

First, you should change:

zim.at(89,34)

to

zim.at<std::int16_t>(89,34)

Second, be aware that the xyz_image is in the same coordinate frame as the point cloud, namely x-forward, y-left, z-up. The only difference is that the data are sent as signed 16-bit ints in mm rather than 32-bit floats in meters as the point cloud does.

from o3d3xx-ros.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.