1

我正在尝试删除长度低于 OpenCv 限制的边。在 Matlab Canny 边缘检测器+bwareaopen 中完成了这项工作,但是我无法获得 cvBlobsLib CBlobResult::Filter 函数并且无法使用 FillBlob 显示结果。这是我的代码

    image = imread(imageflname, CV_LOAD_IMAGE_COLOR);
    Mat gray;
    cvtColor(image,gray, CV_BGR2GRAY);
    float min_thr = 54; 
    GaussianBlur(gray, gray, Size(5,5), 0.8, BORDER_REPLICATE);
    imwrite("gray.png", gray);
    Canny(gray, edge_im, min_thr, min_thr*3, 3); 
    imwrite("edge_im.png", edge_im);
    CBlobResult blobs;
    Mat binary_image(edge_im.size(), CV_8UC1);
    blobs = CBlobResult(binary_image,Mat(),4);
    cout<<"# blobs found: "<<blobs.GetNumBlobs()<<endl;
    blobs.Filter( blobs, B_INCLUDE, CBlobGetArea(), B_GREATER, 70 );
    cout<<"After deletion found: "<<blobs.GetNumBlobs()<<endl;
    Mat edge_open(edge_im.size(), image.type());
    edge_open.setTo(0);
    for(int i=0;i<blobs.GetNumBlobs();i++){
            blobs.GetBlob(i)->FillBlob(edge_open,CV_RGB(255,255,255));
    }   
    imwrite("edge_im_open.png", edge_open);

边缘图像显示正常,但区域开口部分无法正常工作。'edge_open' 不是它应该的样子。这可能是什么原因?有什么编码建议吗?

谢谢。

4

0 回答 0