微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

多个模板匹配,使用ORB进行电子组件检测

如何解决多个模板匹配,使用ORB进行电子组件检测

我正在尝试使用opencv检测电子图照片中的组件。我在BFMathcer中使用ORB特征检测器。要检测多个事件,我现在使用滑动窗口方法。 在我的第一个测试中,我试图检测电路图像上的二极管,但最终在二极管模板上未检测到关键点。

我的第一个解决方案是在检测关键点之前拉伸图像,但是匹配不佳。

二极管模板

1

使用的电路

2

(抱歉,链接无法嵌入图片...)

是否有更好的方法提取关键点? 或其他建议?

如果解是尺度/旋转不变的,那就太好了。

            cv::Mat template_img,capture;

            std::vector<cv::KeyPoint> mTemplate_key_points;
            cv::Mat mTemplate_descriptors;
            std::vector<cv::KeyPoint> key_pts;
            cv::Mat descriptors;

            auto ORB = cv::ORB::create(2000);
            ORB->detectAndCompute(template_img,cv::noArray(),mTemplate_key_points,mTemplate_descriptors);
            ORB->detectAndCompute(capture,key_pts,descriptors);

            cv::BFMatcher matcher(cv::norM_HAMMING);
            std::vector< std::vector<cv::DMatch> > nn_matches;
            matcher.knnMatch(mTemplate_descriptors,descriptors,nn_matches,2);

            std::vector<cv::KeyPoint> matched1,matched2;
            float feature_distance =0;
            for (auto& descriptor_match: nn_matches)
            {
                float dist1 = descriptor_match[0].distance;
                float dist2 = descriptor_match[1].distance;
                feature_distance += dist2 -dist1;
                if(dist1 < 0.8f * dist2)
                {
                    matched1.push_back(mTemplate_key_points[descriptor_match[0].queryIdx]);
                    matched2.push_back(key_pts[descriptor_match[0].trainIdx]);
                }
            }

            std::vector<cv::Point2f> template_hom;
            for (auto pt : matched1)
            {
                template_hom.push_back(pt.pt);
            }
            std::vector<cv::Point2f> image_hom;
            for (auto pt : matched2)
            {
                image_hom.push_back(pt.pt);
            }

            auto my_homography = cv::findHomography(image_hom,template_hom);

            cv::Mat cuted_component;
            cv::warpPerspective(distorted,cuted_component,my_homography,cv::Size(300,300));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。