Ask Your Question

Jluis619's profile - activity

2018-06-05 22:45:36 -0500 received badge  Nice Question (source)
2016-07-05 14:31:53 -0500 received badge  Famous Question (source)
2016-07-05 03:48:01 -0500 received badge  Student (source)
2016-06-14 00:03:08 -0500 received badge  Notable Question (source)
2016-06-10 02:13:07 -0500 received badge  Popular Question (source)
2016-06-10 00:00:00 -0500 received badge  Enthusiast
2016-06-09 20:25:26 -0500 received badge  Editor (source)
2016-06-08 18:35:58 -0500 asked a question get a depth image using a kinect and openCV.

I have a code in C ++ that stores a Kinect's depth image, I wonder if there is any way to get an image, in where I can define the depth of the things captured into this image. for example, I only want the things that are at max at 1 meter of distance of the Kinect's sensor

I found the code into a thread here, so I edited it so I can try to get the image, the code is the next.


#include <ros/ros.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 std;
unsigned int cnt = 0;
void RetornoImagen(const sensor_msgs::ImageConstPtr& msg_depth )

    //convertimos a un tipo de imagen de opencV
    cv_bridge::CvImagePtr img_ptr_depth;

        img_ptr_depth = cv_bridge::toCvCopy(*msg_depth, sensor_msgs::image_encodings::TYPE_32FC1);
    catch (cv_bridge::Exception& e)
        ROS_ERROR("cv_bridge exception:  %s", e.what());

    double minVal, maxVal;
    cv::Mat &mat = img_ptr_depth->image;
    cv::Mat img2;
    cv::Mat invertida;
    cv::imshow("windowName",mat );
    //mat.convertTo(img2,CV_8U, 255.0/(maxVal - minVal), 100.0 );
    minMaxLoc(mat, &minVal, &maxVal,NULL,NULL); //find minimum and maximum intensities

    mat.convertTo(img2,CV_32FC1,65535.0/(maxVal - minVal), -minVal * 65535.0/(maxVal - minVal));




char file1[100];
char file2[100];

 sprintf( file1, "%04d_depth.png", cnt );

//parametros de compresion
    std::vector<int> pp;

//guardamos la imagen en el disco duro, donde se ejecuta el nodo.

    ROS_INFO_STREAM("El minimo es:" << minVal);
    ROS_INFO_STREAM("El maximo es:" << maxVal);


int main(int argc, char **argv)
    char a;
    //initialize the ROS system and become a node.
    ros::init(argc, argv, "guardar_imagen");
    ros::NodeHandle nh;

    //image_transport::ImageTransport it(nh);
    ros::Subscriber image_sub_;
    ros::Rate rate(1);

//creamos ventanas para visualizar el contenido 
    cvNamedWindow("windowName", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("ventana2", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("ventana3", CV_WINDOW_AUTOSIZE);

    image_sub_ = nh.subscribe("/camera/depth_registered/hw_registered/image_rect_raw", 1, &RetornoImagen);


        char c;

        ROS_INFO_STREAM("\nIngrese 'a' para guardar\n");
        c = tolower(c);
        ROS_INFO_STREAM("You entered " << c << "\n");

        if( c == 'a' )
            unsigned int cnt_init = cnt;
            while( cnt - cnt_init < 1 )

        else break;

    ROS_INFO_STREAM("Cerrando nodo\nClosing node\n");
    //Destruimos las ventanas

  return 0;

thank you.


2016-06-06 23:58:21 -0500 commented answer How can I get depth data from Kinect?

Hello, could you give me the full code? I'm new to this. and I would like to work with images in depth. Thank you... :)

2016-06-06 15:58:13 -0500 commented question Problem of saving depth image

is this the full code? If not could you give me please, I want to work with images in depth but I find somewhat complicated to start since 0. thank you :)

2016-06-03 11:16:33 -0500 commented answer Turtlebot depth image not showing in image_view

can you help me? the code don't save the image, the code runs perfectly, I select the option 'a' for to save the picture, and it continues to running, without save nothing. I used 'roswtf' and told me that subscribers nodes are disconnected