stereolabs / zed-opencv

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

strange output from depth camera #84

Closed AndreAhmed closed 2 years ago

AndreAhmed commented 3 years ago

I'm using Zed Camrea and I'm getting Two Matrices.

from reterive image, which is 4 Channel BGRA, just for displaying from measure and it's 1 channel CF32_C1 I'm trying to do temporal removal on it, and I get a ghost image that turns the filtered depth image into black.

// To share data between sl::Mat and cv::Mat, use slMat2cvMat()
// Only the headers and pointer to the sl::Mat are copied, not the data itself
Mat depth_image_zed(new_width, new_height, MAT_TYPE::F32_C1);
cv::Mat depth_image_ocv = slMat2cvMat(depth_image_zed);

Mat depth_image_zed_display(new_width, new_height, MAT_TYPE::U8_C4);

cv::Mat depth_image_ocv_display = slMat2cvMat(depth_image_zed_display);

// Loop until 'q' is pressed
char key = ' ';
int count = 0;
cv::Mat acc;
acc = cv::Mat::zeros(depth_image_ocv.size(), depth_image_ocv.type());

cv::Mat accumulator = cv::Mat::zeros(depth_image_ocv.size(), depth_image_ocv.type());

cv::Mat last_image(depth_image_ocv.rows, depth_image_ocv.cols, depth_image_ocv.type());
while (key != 'q') {

    if (zed.grab(runtime_parameters) == ERROR_CODE::SUCCESS) {

        zed.retrieveImage(depth_image_zed_display, VIEW::DEPTH, MEM::CPU, new_image_size);

        zed.retrieveMeasure(depth_image_zed, MEASURE::DEPTH, MEM::CPU, new_image_size);

        cv::Mat result;
        double factor = 0.5;
        cv::addWeighted(depth_image_ocv, 1.0 - factor, last_image, factor, 0.0, result);
        last_image = result;

        string s1 = type2str(depth_image_ocv.type());
        string s2 = type2str(result.type());

        cv::imshow("dep", depth_image_ocv_display);

        cv::Mat ucharMat, ucharMatScaled;
        depth_image_ocv.convertTo(ucharMat, CV_8UC1);
        // scale values from 0..1 to 0..255
        ucharMat.convertTo(ucharMatScaled, CV_8UC1, 255, 0);
        cv::imshow("filtered_ dep", ucharMatScaled);

        // Handle key event
        key = cv::waitKey(10);
    }
}
zed.close();

1l10Q

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