stereolabs / zed-opencv

ZED SDK interface sample for OpenCV
https://www.stereolabs.com/docs/opencv/
MIT License
137 stars 79 forks source link

zed.retrieveImage changes the input matrix format #83

Closed AndreAhmed closed 2 years ago

AndreAhmed commented 3 years ago

Hi, I would like to do some image processing on the depth image, and the function

zed.retrieveImage changes the format of the cv::mat to U8_C4 which I don't want

Mat depth_image_zed(new_width, new_height, MAT_TYPE::F32_C1); cv::Mat depth_image_ocv = slMat2cvMat(depth_image_zed); zed.retrieveImage(depth_image_zed, VIEW::DEPTH, MEM::CPU, new_image_size);

        double min;
        double max;
        cv::minMaxIdx(depth_image_ocv, &min, &max);
        cv::Mat adjMap;
        cv::convertScaleAbs(depth_image_ocv, adjMap, 255 / max);
        cv::imshow("Out", adjMap);
AndreAhmed commented 3 years ago

I can't do ANY operation on depth_image_zed, coloning or doing anything is Impossible. What's the point of using OpenCV then ?

obraun-sl commented 3 years ago

Use zed.retrieveMeasure(DEPTH) instead of retrieveImage if you want a 32bits matrix.

AndreAhmed commented 3 years ago

@obraun-sl I already did that, the image is flickering and I only had access to the data only using cloning.


            zed.retrieveMeasure(depth_image_zed, MEASURE::DEPTH, MEM::CPU, new_image_size);
            cv::Mat proce = depth_image_ocv.clone();
            double min;
            double max;
            cv::minMaxIdx(proce, &min, &max);
            cv::Mat adjMap;
            // Histogram Equalization
            float scale = 255 / (max - min);
            proce.convertTo(adjMap, CV_8UC1, scale, -min * scale);

            // this is great. It converts your grayscale image into a tone-mapped one, 
            // much more pleasing for the eye
            // function is found in contrib module, so include contrib.hpp 
            // and link accordingly
            cv::Mat falseColorsMap;
            applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_AUTUMN);

            cv::imshow("Out", falseColorsMap);
github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days