Skip to content

Commit b24beba

Browse files
committed
feat:add lane track
1 parent 9089301 commit b24beba

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ void YUVConvertToMat(const char* yuvImageFile, unsigned char* image_data) {
2828
}
2929

3030
int main(int, char**) {
31-
std::string imagePath = "/opt_disk2/rd22946/vscode_work/python_works/mytest/test"; // /opt_disk2/rd22946/AllDataAndModels/from_tongwenchao/116_new_undistort/116"; //"/opt_disk2/rd22946/AllDataAndModels/from_tongwenchao/map_R_new_undistort/map_R";
31+
std::string imagePath = "/opt_disk2/rd22946/AllDataAndModels/from_tongwenchao/116_new_undistort/116"; // "/opt_disk2/rd22946/vscode_work/python_works/mytest/test"; // /opt_disk2/rd22946/AllDataAndModels/from_tongwenchao/116_new_undistort/116"; //"/opt_disk2/rd22946/AllDataAndModels/from_tongwenchao/map_R_new_undistort/map_R";
3232
std::vector<std::string> imagePaths;
33-
size_t numImgs = getFullNames(filesystem::path(imagePath), imagePaths, ".yuv");
33+
size_t numImgs = getFullNames(filesystem::path(imagePath), imagePaths, ".jpg");
3434
// std::sort(imagePaths.begin(), imagePaths.end(),
3535
// [](std::string p1, std::string p2) { return atoi(filesystem::path(p1).filenameNoExt().substr(6).c_str()) < atoi(filesystem::path(p2).filenameNoExt().substr(6).c_str()); });
3636
std::sort(imagePaths.begin(), imagePaths.end(),
@@ -44,10 +44,11 @@ int main(int, char**) {
4444
buildMapping::HDMapping::localizeMapStatus statusL = buildMapping::HDMapping::localizeMapStatus::LOCALIZE_MAP_PROCESSING;
4545
for (size_t i = 351; i < 1160; i++) { // from 351, to 1160 for 116_new_undistort/116
4646
fid << imagePaths[i] << std::endl;
47-
// cv::Mat srcImage = cv::imread(imagePaths[i]);
48-
cv::Mat srcImage = cv::Mat::zeros(480, 640, CV_8UC1);
49-
const char* imgYUVpath = imagePaths[i].c_str();
50-
YUVConvertToMat(imgYUVpath, srcImage.data);
47+
cv::Mat srcImage = cv::imread(imagePaths[i]);
48+
// cv::Mat srcImage = cv::Mat::zeros(480, 640, CV_8UC1);
49+
// const char* imgYUVpath = imagePaths[i].c_str();
50+
// YUVConvertToMat(imgYUVpath, srcImage.data);
51+
5152
if (i == 1159) {
5253
flag = true;
5354
}

src/HDMapping.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,43 @@ buildMapping::HDMapping::buildMapStatus buildMapping::HDMapping::constructWorldM
131131
m_bd->compute(currImg, m_currLines, m_currLineDescriptors);
132132
if (m_preLineDescriptors.empty()) {
133133
m_preLines = m_currLines;
134-
m_preLineDescriptors = m_currLineDescriptors;
134+
m_preLineDescriptors = m_currLineDescriptors.clone();
135135
}
136+
// 匹配器匹配策略,筛选高精度匹配线
137+
std::vector<cv::DMatch> good_matches;
138+
#if 0
136139
cv::Ptr<cv::line_descriptor::BinaryDescriptorMatcher> bdm = cv::line_descriptor::BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
137-
// std::vector<std::vector<cv::DMatch>> line_matches;
138140
// bdm->radiusMatch(m_currLineDescriptors, m_preLineDescriptors, line_matches, 30);
139141
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);
145143
for (int i = 0; i < (int)line_matches.size(); i++) {
146144
if (line_matches[i].distance < 20)
147145
good_matches.push_back(line_matches[i]);
148146
}
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());
149161

150162
/* 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);
160171
// cv::Mat outImg1;
161172
// cv::cvtColor(currImg, outImg1, cv::COLOR_GRAY2BGR);
162173
// cv::line_descriptor::drawKeylines(outImg1, m_currLines, outImg1, cv::Scalar(0, 255, 0));

0 commit comments

Comments
 (0)