Spatial and temporal on depth image

asked 2020-10-30 14:57:41 -0600

Ahmed gravatar image

Hi,

I would like to do Spatial and temporal on a depth image. spatial average can be achieved by convolution (cv::filter2D), for temporal average you would need to accumulate() N images, and divide by N but I don't know how to use OpenCV to do that.

What I tried for spatial filter is

            cv::Mat dst;
            int kernel_size = 2;
            cv::Mat kernel = cv::Mat::ones(kernel_size, kernel_size, CV_32F) / (float)(kernel_size * kernel_size);
            // Apply filter
            filter2D(depth_image_ocv, dst, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);

but the result is horrible as shown in the image.

image description

            cv::imshow("Filtered Depth", dst);
            cv::imshow("Depth", depth_image_ocv);
edit retag flag offensive close merge delete

Comments

try an odd kernel size, 3,5,7, etc. think of it, summing over neighbours needs a "center" pixel

you also could try a simple boxFilter()

berak gravatar imageberak ( 2020-10-31 02:20:03 -0600 )edit

Thanks I will try it. Have another problem. Also the above code that does temporarily filtering isn't working. In each frame the filtered image is getting ghosty and it does that untill it fades to black –

Ahmed gravatar imageAhmed ( 2020-10-31 03:15:26 -0600 )edit

@Ahmed You need to ask a separate question.

Volker Siegel gravatar imageVolker Siegel ( 2020-11-01 02:09:37 -0600 )edit