帮助使用扩张功能OpenCV

and*_*oga 6 c++ opencv function image-processing mathematical-morphology

在下面的代码中我想使用该dilate函数,但我不知道如何将Mat类转换为InputArrayOutputArray.你能帮助我吗?

使用这个原型函数:

void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() )
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    Mat edges;

    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;


    for(;;)
    {

        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        //dilate(edges,edges,NULL);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", frame);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

kar*_*lip 19

Stack Overflow周围有一些例子,如下所示:

int erosion_size = 6;   
cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS,
                      cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1), 
                      cv::Point(erosion_size, erosion_size) );

cv::dilate(edges, edges, element); 
Run Code Online (Sandbox Code Playgroud)

或者这个:

cv::dilate(edges, edges, cv::Mat(), cv::Point(-1,-1));
Run Code Online (Sandbox Code Playgroud)

  • -1,它在文档中是有效的,但你没有链接它,并且答案不符合Stack Overflow标准.链接自:http://stackoverflow.com/questions/how-to-answer - > http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx`但是,没有解释的代码很少有用.至少提供一两句话来解释发生了什么 (5认同)
  • 鉴于[so]帖子旨在为其他用户提供未来价值,帖子的年龄以及是否已被接受应该不会影响您是否决定编辑它.如果你觉得这个答案应该保持原样,那么就是这样的原因(也就是你很高兴发布这个答案,就这个问题而言,如果你还没有这样做的话),这是一回事,但是你可能不应该将这些理由作为你推理的要点. (3认同)