问题描述
我正在尝试使用opencv检测电子图照片中的组件。我在BFMathcer中使用ORB特征检测器。要检测多个事件,我现在使用滑动窗口方法。 在我的第一个测试中,我试图检测电路图像上的二极管,但最终在二极管模板上未检测到关键点。
我的第一个解决方案是在检测关键点之前拉伸图像,但是匹配不佳。
二极管模板
使用的电路
如果解是尺度/旋转不变的,那就太好了。
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 (将#修改为@)