ouster-lidar / ouster_example

Ouster, Inc. sample code
Other
451 stars 434 forks source link

Unable to get an intensity image that shows the environment similar to Ouster Studio intensity image using C++ code #540

Closed arunumd closed 11 months ago

arunumd commented 11 months ago

Describe your question

The Ouster Studio has the feature of viewing the 2D intensity image on the screen. This image looks very realistic. It shows the environment of the LiDAR like a photograph. So I am trying to reproduce the same kind of image through some C++ and OpenCV code by following the docs, provided examples and inventing some more things of my own. The code below is what I have produced for performing this operation.

    Eigen::Array<uint32_t, -1, -1, Eigen::RowMajor> reflectivity;

    if (info.format.udp_profile_lidar ==
        sensor::UDPProfileLidar::PROFILE_LIDAR_LEGACY) {
        reflectivity = scan.field(sensor::ChanField::REFLECTIVITY);
    } else if (info.format.udp_profile_lidar ==
               sensor::UDPProfileLidar::PROFILE_RNG19_RFL8_SIG16_NIR16_DUAL) {
        reflectivity = scan.field<uint8_t>(sensor::ChanField::REFLECTIVITY)
                           .cast<uint32_t>();
    } else {  // legacy or single return profile
        reflectivity = scan.field<uint16_t>(sensor::ChanField::REFLECTIVITY)
                           .cast<uint32_t>();
    }

    //! [doc-stag-cpp-destagger]
    auto reflectivity_destaggered =
        destagger<uint32_t>(reflectivity, info.format.pixel_shift_by_row);
    //! [doc-etag-cpp-destagger]

    cv::Mat intensity_img = cv::Mat(h, w, CV_8UC3);

    for (size_t i = 0; i < h; i++) {
        for (size_t j = 0; j < w; j++) {
            intensity_img.at<char>(i, j) = reflectivity_destaggered(i, j);
        }
        std::cout << "\n";
    }
    cv::namedWindow("Intensity image", cv::WINDOW_AUTOSIZE);
    cv::imshow("Intensity image", intensity_img);
    cv::waitKey(0);
    return 0;
}

However the image I get is nothing like what I get from Ouster Studio. Please see the snapshots below for comparison.

Screenshots

What I get from Ouster Studio intensity image: ouster_studio_op

What I get from my C++ code using OpenCV and Ouster SDK: ouster_opencv_cpp_image

It seems as though something is wrong with this code in terms of how I try to get the reflectivity array for the environment. I am wondering what is wrong?

Platform (please complete the following information):

arunumd commented 11 months ago

Hello,

Any idea why does the reflectivity matrix have mostly zeros in its entries? When I std::cout the intensity_img, it looks like this. Mostly overwhelmed by zeroes. So the image looks mostly black.

image

Samahu commented 11 months ago

There might be different issues with your code:

Hope this helps!

Samahu commented 11 months ago

No response, marking the issue as done.