gpt4 book ai didi

opencv - 修复深度图,图像边框仍为黑色

转载 作者:行者123 更新时间:2023-12-02 16:17:34 33 4
gpt4 key购买 nike

我正在尝试使用here描述的方法来修补深度图的缺失深度值。总结方法:

  • 将深度图缩小为原始大小
  • 的20%
  • 将缩小的图像中的所有黑色(未知)像素修补为
  • 放大到原始大小
  • 用放大的图像
  • 中的相应值替换原始图像中的所有黑色像素

    super 简单,一切正常。显示结果的视频可以在 here中找到。

    但是,我想知道为什么左和顶部图像边框仍应该是黑色的(尽管可以在视频中看到)。我的第一个想法是,这可能与边界插值(图像边界之外的黑色像素)有关,但是我不希望这也会在其他图像边界上发生。我的第二个想法是,它特定于所用的修复方法(Alexandru Telea的方法),但是将其更改为基于Navier-Stokes的方法并不会改变结果。

    有人可以向我解释为什么会发生这种情况,如果可能的话,如何告诉OpenCV也修补这些区域?

    提前致谢。

    最佳答案

    http://answers.opencv.org/question/86569/inpainting-depth-map-still-black-image-borders/?comment=86587#comment-86587中由@theodore询问后,我使用示例图像测试了行为修复。看起来它无法正确处理边框,因此可以使用cv::copyMakeBorder创建边框。

    这是带有某种单元测试的扩展版本:

    int main(int argc, char* argv[])
    {
    cv::Mat input = cv::imread("C:/StackOverflow/Input/depthInpaint.png");
    cv::Mat img;
    cv::cvtColor(input, img, CV_BGR2GRAY);

    cv::Mat inpainted;
    const unsigned char noDepth = 0; // change to 255, if values no depth uses max value or use the mask image
    //cv::inpaint(img, (img == noDepth), depth, 5.0, cv::INPAINT_TELEA); // img is the 8-bit input image (depth map with blank spots)


    double inpaintRadius = 5;
    int makeBorder = 1;
    cv::Mat borderimg;
    cv::copyMakeBorder(img, borderimg, makeBorder, makeBorder, makeBorder, makeBorder, cv::BORDER_REPLICATE);
    cv::imshow("border", borderimg);
    cv::inpaint(borderimg, (borderimg == noDepth), inpainted, inpaintRadius, cv::INPAINT_TELEA); // img is the 8-bit input image (depth map with blank spots)

    cv::Mat originalEmbedded = borderimg(cv::Rect(makeBorder, makeBorder, img.cols, img.rows));
    cv::Mat inpaintedEmbedded = inpainted(cv::Rect(makeBorder, makeBorder, img.cols, img.rows));


    cv::Mat diffImage;
    cv::absdiff(img, originalEmbedded, diffImage);
    cv::imshow("embedding correct?", diffImage > 0);

    cv::Mat mask = img == noDepth;
    cv::imshow("mask", mask);


    cv::imshow("input", input);
    cv::imshow("inpainted", inpainted);
    cv::imshow("inpainted from border", inpaintedEmbedded);
    cv::waitKey(0);
    return 0;
    }

    如果您认为它是正确的,那么这是简化版:
    int main(int argc, char* argv[])
    {
    cv::Mat input = cv::imread("C:/StackOverflow/Input/depthInpaint.png");
    cv::Mat img;
    cv::cvtColor(input, img, CV_BGR2GRAY);

    cv::Mat inpainted;
    const unsigned char noDepth = 0; // change to 255, if values no depth uses max value or use the mask image
    //cv::inpaint(img, (img == noDepth), depth, 5.0, cv::INPAINT_TELEA); // img is the 8-bit input image (depth map with blank spots)

    double inpaintRadius = 5;
    int makeBorderSize = 1;
    cv::Mat borderimg;
    //cv::copyMakeBorder(img, borderimg, borderSize, borderSize, borderSize, borderSize, cv::BORDER_REPLICATE);
    cv::copyMakeBorder(img, borderimg, makeBorderSize, makeBorderSize, makeBorderSize, makeBorderSize, cv::BORDER_REPLICATE);
    //cv::imshow("border", borderimg);
    cv::inpaint(borderimg, (borderimg == noDepth), inpainted, inpaintRadius, cv::INPAINT_TELEA); // img is the 8-bit input image (depth map with blank spots)

    // extract the original area without border:
    cv::Mat inpaintedEmbedded = inpainted(cv::Rect(makeBorderSize, makeBorderSize, img.cols, img.rows));



    cv::imshow("input", input);
    cv::imshow("inpainted from border", inpaintedEmbedded);
    cv::waitKey(0);
    return 0;
    }

    输入内容:

    enter image description here

    这是带有边框的输入(边框大小为5,可以更好地可视化效果):

    enter image description here

    这是输出:

    enter image description here

    关于opencv - 修复深度图,图像边框仍为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25974033/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com