DepthImage to Mat (OpenCV)

asked 2014-09-25 09:37:29 -0600

I am working with a 3d camera that provides a depthimage which is encoded in 32FC1 I need the image in OpenCV format (Mat) in order to access each component as a matrix. I am working on a ROS system, so I receive the image in ROS format.

The problem is that when I have done the transformation, I try to access the Matrix data with Mat::at but I can not see real values. I don't know where the problem is.

Here is my code:

cv_bridge::CvImagePtr cv_ptr;
    try{
        cv_ptr = cv_bridge::toCvCopy(pdepth);
    }
    catch (cv_bridge::Exception& e){
        ROS_ERROR("cv_bridge exception: %s", e.what());
        return;
    }

    for(uint col = 0; col < 800; col++){
        float d = 8.0;
        for(uint pix = 0; pix < 300; pix++){
            if (cv_ptr->image.at<float>(pix,col) < 32/(0.45814893-0.001529713*pix)) d = cv_ptr->image.at<float>(pix,col);
edit retag flag offensive close merge delete

Comments

How does your image look like? Are you sure that your image is a float image? (e.g. is cv_ptr->image.type() == CV_32FC1 ). Of which datatype is pdepth? You also should avoid to hard code image sizes and better write the iteration as

 for(uint col = 0; col &lt; cv_ptr-&gt;image.cols; col++){

so that you can use your code also with other image sizes. Also the variable name "pix" is really confusing as it should be 'row'.

FooBar gravatar imageFooBar ( 2014-09-26 01:30:07 -0600 )edit