在@theodore询问http://answers.opencv.org/question/86569/inpainting-depth-map-still-black-image-borders/?comment=86587#comment-86587后,我用示例图像测试了inpaint的行为。它看起来不能正确处理边框,因此可以使用创建边框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;
}
这里的输入:
这是带边框的输入(bordersiz E(5)可视化效果越好):
下面是输出:
可能是左边的值是不是255?你可以添加另一个窗口,显示深度值等于255的所有深度值?例如'cv :: imshow(“newWindowName”,depthf == 255);'如果这就是您可以在链接代码的第13行和第16行将使用过的掩码更改为'> 250'或其他内容而不是'== 255'的原因。 – Micka 2014-09-22 14:58:51
因为我得到的深度值未知为0,对我来说,它会是depthf == 0或depthf> 5,但无论如何,这里有一些图片:[This](https://drive.google.com/file/d/ 0B-qt8lafqDaeQy03QndSMkUxUkU/edit?usp = sharing)显示了一个示例深度图。 [This](https://drive.google.com/file/d/0B-qt8lafqDaeZUNOdVBNMlNLcXc/edit?usp=sharing)是用于修补的蒙版。并且[this](https://drive.google.com/file/d/0B-qt8lafqDaeSi01cmJDc3Byc1U/edit?usp=sharing)就是结果。任何想法@Micka?左边框有点奇怪,但让我们坚持顶部边框。它明显包含在面具中。 – thomas 2014-09-22 18:55:26
你看过_tmp1和_tmp吗? – Micka 2014-09-22 19:02:53