@@ -131,32 +131,43 @@ buildMapping::HDMapping::buildMapStatus buildMapping::HDMapping::constructWorldM
131
131
m_bd->compute (currImg, m_currLines, m_currLineDescriptors);
132
132
if (m_preLineDescriptors.empty ()) {
133
133
m_preLines = m_currLines;
134
- m_preLineDescriptors = m_currLineDescriptors;
134
+ m_preLineDescriptors = m_currLineDescriptors. clone () ;
135
135
}
136
+ // 匹配器匹配策略,筛选高精度匹配线
137
+ std::vector<cv::DMatch> good_matches;
138
+ #if 0
136
139
cv::Ptr<cv::line_descriptor::BinaryDescriptorMatcher> bdm = cv::line_descriptor::BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
137
- // std::vector<std::vector<cv::DMatch>> line_matches;
138
140
// bdm->radiusMatch(m_currLineDescriptors, m_preLineDescriptors, line_matches, 30);
139
141
std::vector<cv::DMatch> line_matches;
140
- bdm->match (m_currLineDescriptors, m_preLineDescriptors, line_matches);
141
-
142
- // 待参考https: //blog.csdn.net/weixin_43821376/article/details/104990667 换个匹配器看看?
143
- /* 筛选高精度匹配点对 */
144
- std::vector<cv::DMatch> good_matches;
142
+ bdm->match(m_preLineDescriptors, m_currLineDescriptors, line_matches);
145
143
for (int i = 0; i < (int)line_matches.size(); i++) {
146
144
if (line_matches[i].distance < 20)
147
145
good_matches.push_back(line_matches[i]);
148
146
}
147
+ #else
148
+ std::vector<std::vector<cv::DMatch>> lmatches;
149
+ cv::BFMatcher bfm = cv::BFMatcher (cv::NORM_HAMMING, false );
150
+ bfm.knnMatch (m_preLineDescriptors, m_currLineDescriptors, lmatches, 2 );
151
+ for (size_t i = 0 ; i < lmatches.size (); i++) {
152
+ const cv::DMatch& bestMatch = lmatches[i][0 ];
153
+ const cv::DMatch& betterMatch = lmatches[i][1 ];
154
+ float distanceRatio = bestMatch.distance / betterMatch.distance ;
155
+ if ((distanceRatio < 0.7 ) || (bestMatch.distance < 20 ))
156
+ good_matches.push_back (bestMatch);
157
+ }
158
+ #endif
159
+ printf (" Detect And match lanes Elapsed second Time:%.6f\n " ,
160
+ (cv::getTickCount () - t1) * 1.0 / cv::getTickFrequency ());
149
161
150
162
/* plot matches */
151
- cv::Mat lsd_outImg, img1, img2;
152
- std::vector<char > lsd_mask (good_matches.size (), 1 );
153
- cv::cvtColor (m_prevImg, img1, cv::COLOR_GRAY2BGR);
154
- cv::cvtColor (currImg, img2, cv::COLOR_GRAY2BGR);
155
- cv::line_descriptor::drawLineMatches (img1, m_preLines, img2, m_currLines, good_matches,
156
- lsd_outImg, cv::Scalar::all (-1 ), cv::Scalar::all (-1 ), lsd_mask, cv::line_descriptor::DrawLinesMatchesFlags::DEFAULT);
157
- printf (" detectLanes Elapsed second Time:%.6f\n " ,
158
- (cv::getTickCount () - t1) * 1.0 / cv::getTickFrequency ());
159
- cv::imwrite (" Lane_track.jpg" , lsd_outImg);
163
+ // cv::Mat lsd_outImg, img1, img2;
164
+ // std::vector<char> lsd_mask(good_matches.size(), 1);
165
+ // cv::cvtColor(m_prevImg, img1, cv::COLOR_GRAY2BGR);
166
+ // cv::cvtColor(currImg, img2, cv::COLOR_GRAY2BGR);
167
+ // cv::line_descriptor::drawLineMatches(img1, m_preLines, img2, m_currLines, good_matches,
168
+ // lsd_outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), lsd_mask, cv::line_descriptor::DrawLinesMatchesFlags::DEFAULT);
169
+
170
+ // cv::imwrite("Lane_track" + std::to_string(num) + ".jpg", lsd_outImg);
160
171
// cv::Mat outImg1;
161
172
// cv::cvtColor(currImg, outImg1, cv::COLOR_GRAY2BGR);
162
173
// cv::line_descriptor::drawKeylines(outImg1, m_currLines, outImg1, cv::Scalar(0, 255, 0));
0 commit comments