如何在opencv中使用erode和dilate函数? [英] How to use erode and dilate function in opencv?

查看:1415
本文介绍了如何在opencv中使用erode和dilate函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用erode和dilate过程消除数字周围的事情。我试了,但没有发生。我改变了值只是为了看是否会改变的东西,但是,没有什么改变。图像继续如上面的链接。这个参数怎么样...我读了文档,但不太明白(你可以看到,我在函数中猜)。我做错了什么?

I'm trying to eliminate the thing around the number with erode and dilate process. I tryed but nothing happened. I changed the values just for see if would change something, but again, nothing has changed. The image continues like in the link above. What about this parameters... I read the documentation but don't quite understand (as you can see, I was guessing in the function). What am I doing wrong?

该图片: https://docs.google.com/file/d/0BzUNc6BOkYrNeVhYUk1oQjFSQTQ/edit?usp=sharing

代码:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main ( int argc, char **argv )
{
    Mat im_gray;
    Mat img_bw;
    Mat img_final;

    Mat im_rgb  = imread("cam.jpg");
    cvtColor(im_rgb,im_gray,CV_RGB2GRAY);


    adaptiveThreshold(im_gray, img_bw, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 105, 1); 


    dilate(img_bw, img_final, 0, Point(-1, -1), 2, 1, 1);


    imwrite("cam_final.jpg", img_final);

    return 0;
}  


推荐答案

http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=dilate#dilate\">官方文档,第三个参数应该是内核(或结构元素)。您目前正在传送0:

According to official docs, the third argument should be the kernel (or structuring element). You are currently passing 0:

dilate(img_bw, img_final, 0, Point(-1, -1), 2, 1, 1);

尝试以这种方式重写:

dilate(img_bw, img_final, Mat(), Point(-1, -1), 2, 1, 1);

在这种情况下,将使用默认的3x3内核。

In this case, a default 3x3 kernel will be used.

这篇关于如何在opencv中使用erode和dilate函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆