【问题标题】:dot detection on the washer with opencv使用opencv在洗衣机上进行点检测
【发布时间】:2020-07-20 09:57:49
【问题描述】:

我正在使用opencv blob检测功能来检测黑点,但它会导致速度慢和cpu消耗高。有没有更有效的方法来检测那些黑点?并且 Blob 检测有时无法检测到一些黑点

这是我的示例图片

这是我现有的代码

SimpleBlobDetector::Params params;
params.minThreshold = 50;
params.maxThreshold = 200;
params.filterByArea = true;
params.minArea = 500;
params.filterByCircularity = true;
params.minCircularity = 0.1;
std::vector<KeyPoint> keypoints;
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
detector->detect( im, keypoints);
Mat im_with_keypoints;
drawKeypoints( im, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

这些是尝试检测的黑点

【问题讨论】:

  • 您想要检测的所需点是什么?你的图像分辨率是多少?您可以使用形态学方法。 SimpleBlobDetector 是先进的,它通常会获得较慢的响应。调整输入源的大小会有所帮助
  • @YunusTemurlenk 我已经上传了另一张带有所需点的图片我想检测我的分辨率 1296 px x 966 px

标签: c++ opencv computer-vision blob diplib


【解决方案1】:

1- 为了能够在 SimpleBlobDetector 期间提高速度,您可以调整输入源的大小除以 2 或更多。这仍然有助于找到 blob,也将提高速度。

2- 另一方面,为了获得精确的解决方案,您可以检测每个轮廓并在它们周围画圈。可以通过半径过滤圆,也可以输入圆的内部计算像素,过滤轮廓大小等。可以继续使用形态函数来完成任务。

这是指导和输出的代码:

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

using namespace std;
using namespace cv;
RNG rng(12345);

int main()
{
    
    Mat img = imread("/ur/img/directory/image.png",0);
    imshow("Input",img);
    medianBlur(img,img,5);
    Mat canny_output;
    Canny( img, canny_output, 145, 145*3 );
    vector<vector<Point> > contours;
    findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
    vector<vector<Point> > contours_poly( contours.size() );
    vector<Point2f>centers( contours.size() );
    vector<float>radius( contours.size() );
    for( size_t i = 0; i < contours.size(); i++ )
    {
        approxPolyDP( contours[i], contours_poly[i], 3, true );
        minEnclosingCircle( contours_poly[i], centers[i], radius[i] );
    }
    Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
    for( size_t i = 0; i< contours.size(); i++ )
    {
        Scalar color = Scalar( 0,255,255);
        drawContours( drawing, contours_poly, (int)i, color );
        if((int)radius[i]>0 && (int)radius[i]<100)
            circle( img, centers[i], (int)radius[i], color, 2 );
    }
    imshow("Output",img);
    imshow("Contours",drawing);
    waitKey(0);
    return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 2013-03-01
    • 2016-10-12
    • 1970-01-01
    • 2014-03-13
    相关资源
    最近更新 更多