【问题标题】:Dilate works fine and erode does not output correctly imageDilate 工作正常,erode 无法正确输出图像
【发布时间】:2017-04-02 17:44:10
【问题描述】:

我有这个代码。

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <opencv/cv.h>
#include <iostream>
#include <Windows.h>


using namespace std;
using namespace cv;

int main(int, char**)

{
Mat image = imread("text.tif", 0);
Mat dilate_im = image.clone();
Mat erode_im = image.clone();

if (image.empty())//check if empty
{
    printf("Image is not read! File is probably missing! Press any key to        exim program");//message for error
    waitKey(); //10 second delay for showing message to user
}
else
{

    namedWindow("Original", 1);
    imshow("Original", image);

    dilate(image, dilate_im, Mat());
    erode(image, erode_im, Mat());

    namedWindow("Dilate Image", 1);
    imshow("Dilate Image", dilate_im);

    namedWindow("Erode Image", 1);
    imshow("Erode Image", erode_im);

    waitKey();
}
return 0;
}

虽然扩张功能工作并输出正确的图像,但腐蚀不起作用,我只得到一张黑色图像。

这是输出:

View the output of this program here

你能帮我解释一下为什么腐蚀功能不起作用吗?

非常感谢您。

【问题讨论】:

  • 对我来说输出看起来不错,文本被侵蚀并消失了。您可以使用不同的输入进行测试。

标签: c++ opencv


【解决方案1】:

您同时调用erodedilate 方法为:

dilate(image, dilate_im, Mat());
erode(image, erode_im, Mat()); 

根据documentation

src - 输入图像;通道数可以是任意的,但深度应该是 CV_8U、CV_16U、CV_16S、CV_32F 或 `CV_64F 之一。

dst - 与 src 大小和类型相同的输出图像。

element - 用于腐蚀的结构元素;如果 element=Mat() ,使用 3 x 3 矩形结构元素

所以在不知不觉中,您使用默认的 3x3 内核调用 erodedilate,但在腐蚀的情况下,前景文本的宽度似乎小于 3 像素,这将被黑色覆盖,并且因此黑色输出。

【讨论】:

  • 你好,我看到了这篇文章:docs.opencv.org/2.4/doc/tutorials/imgproc/erosion_dilatation/… 不应该让字母变薄吗?就我而言,它会擦除​​它们而不是使它们变薄。换句话说,你是说如果我使用不同的掩码(而不是 3x3),这会是什么字?
  • 是的,小于 3x3 的自定义掩码可能有效,但不确定,您需要对其进行测试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-17
  • 2015-07-25
  • 2019-01-11
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多