Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ubuntu 20.04.6 LTS and OpenCV-4.9.0 #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char **argv)
assert(vTextDete.size()==vTextMean.size());

// b) Read image info
im = cv::imread(Set.sReadPath + vImg_Name[ni], CV_LOAD_IMAGE_UNCHANGED);
im = cv::imread(Set.sReadPath + vImg_Name[ni], cv::IMREAD_UNCHANGED);
double tframe = vImg_Time[ni];
if(im.empty()){
cerr << endl << "Failed to load image at: "
Expand Down
2 changes: 1 addition & 1 deletion src/ORBextractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <vector>
#include <list>
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
using namespace std;

namespace TextSLAM
Expand Down
2 changes: 1 addition & 1 deletion src/mapText.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ double mapText::GetSgeo(const keyframe* KF, mapText* obj)
cv::putText(imText, s.str(), cv::Point(5, imText.rows-5), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(255), 1, 8);

// show
namedWindow(ShowName, CV_WINDOW_NORMAL);
namedWindow(ShowName, cv::WINDOW_NORMAL);
imshow(ShowName, imText);
waitKey(0);
}
Expand Down
102 changes: 79 additions & 23 deletions src/tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ void tool::ShowMatches(const vector<int> &Match12, const cv::Mat &F1Img, const c
imwrite(SaveName, img_match);

if(SHOW){
namedWindow("Matches", CV_WINDOW_NORMAL);
namedWindow("Matches", cv::WINDOW_NORMAL);
imshow("Matches", img_match);
waitKey(0);
}
Expand Down Expand Up @@ -1795,7 +1795,7 @@ void tool::ShowMatches(const vector<int> &Match12, const Mat &F1Img, const Mat &

Mat img_match;
cout<<"show match num is: "<<num<<endl;
namedWindow("Matches", CV_WINDOW_NORMAL);
namedWindow("Matches", cv::WINDOW_NORMAL);
drawMatches(F1Img, F1Keys, F2Img, F2Keys, match_show, img_match);
imshow("Matches", img_match);
waitKey(0);
Expand Down Expand Up @@ -1823,7 +1823,7 @@ void tool::ShowMatches(const vector<match> &Match12, const Mat &F1Img, const Mat

Mat img_match;
cout<<"show match num is: "<<num<<endl;
namedWindow("RawMatches", CV_WINDOW_NORMAL);
namedWindow("RawMatches", cv::WINDOW_NORMAL);
drawMatches(F1Img, F1Keys, F2Img, F2Keys, match_show, img_match);
imshow("RawMatches", img_match);
waitKey(0);
Expand Down Expand Up @@ -1855,7 +1855,7 @@ void tool::ShowMatches(const vector<match> &Match12, const Mat &F1Img, const Mat
if(SAVE)
imwrite(SaveName, img_match);
if(SHOW){
namedWindow("RawMatches", CV_WINDOW_NORMAL);
namedWindow("RawMatches", cv::WINDOW_NORMAL);
imshow("RawMatches", img_match);
waitKey(0);
}
Expand Down Expand Up @@ -1890,7 +1890,7 @@ void tool::ShowMatchesLP(const Mat &F1Img, const Mat &F2Img, const vector<Vec2>
drawMatches(F1Img, keys1, F2Img, keys2, match_show, img_match);

if(SHOW){
namedWindow("LP Matches", CV_WINDOW_NORMAL);
namedWindow("LP Matches", cv::WINDOW_NORMAL);
imshow("LP Matches", img_match);
waitKey(0);
}
Expand Down Expand Up @@ -1930,7 +1930,7 @@ void tool::ShowMatchesLP(const Mat &F1Img, const Mat &F2Img, const vector<Vec2>
drawMatches(F1Img, keys1, F2Img, keys2, match_show, img_match);

if(SHOW){
namedWindow("LP Matches", CV_WINDOW_NORMAL);
namedWindow("LP Matches", cv::WINDOW_NORMAL);
imshow("LP Matches", img_match);
waitKey(0);
}
Expand Down Expand Up @@ -1976,7 +1976,7 @@ void tool::ShowFeatures(const cv::Mat &Img, const vector<cv::KeyPoint> &Keys, co
if(SHOW){
cv::Mat imGrayOut;
drawKeypoints(Img, Keys, imGrayOut, Scalar(0,0,255));
namedWindow("ShowFeatures", CV_WINDOW_NORMAL);
namedWindow("ShowFeatures", cv::WINDOW_NORMAL);
imshow("ShowFeatures", imGrayOut);
waitKey(0);
}
Expand Down Expand Up @@ -2019,11 +2019,7 @@ cv::Mat tool::ShowTextBoxWithText(const vector<vector<Vec2>> &textbox, const vec
Scalar Color = Scalar(0, 0, 255);

// obj showMsg
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, 0.4,0.4,0,0.35); // hScale,vScale,0,lineWidth
IplImage tmp = IplImage(Imgdraw);
CvArr* src = (CvArr*)&tmp;

cv::HersheyFonts font = cv::FONT_HERSHEY_SIMPLEX;
for(size_t i0 = 0; i0<textbox.size(); i0++){
vector<Vec2> Box4Pts = textbox[i0];
line(Imgdraw, cv::Point2d(Box4Pts[0](0), Box4Pts[0](1)), cv::Point2d(Box4Pts[1](0), Box4Pts[1](1)), Color);
Expand All @@ -2032,38 +2028,38 @@ cv::Mat tool::ShowTextBoxWithText(const vector<vector<Vec2>> &textbox, const vec
line(Imgdraw, cv::Point2d(Box4Pts[3](0), Box4Pts[3](1)), cv::Point2d(Box4Pts[0](0), Box4Pts[0](1)), Color);

// 3. show obj id & mean
cvPutText(src, vShowText[i0].c_str(), cvPoint(Box4Pts[0](0), Box4Pts[0](1)), &font,CV_RGB(255,255,0));
cv::putText(Imgdraw, vShowText[i0].c_str(), cv::Point(Box4Pts[0](0), Box4Pts[0](1)), cv::FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,255,0), 0.35);
//cv::putText(src, vShowText[i0].c_str(), cv::Point(Box4Pts[0](0), Box4Pts[0](1)), &font,CV_RGB(255,255,0));
}

namedWindow(ShowName, CV_WINDOW_NORMAL);
namedWindow(ShowName, cv::WINDOW_NORMAL);
imshow(ShowName, Imgdraw);
waitKey(0);

return Imgdraw;
}


cv::Mat tool::ShowTextBoxSingle(const Mat &Img, const vector<Vec2> &Pred, const int &ObjId)
{
Mat Imgdraw = Img.clone();
Scalar Color = Scalar(0, 0, 255);
// obj showMsg
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, 0.4,0.4,0,0.35); // hScale,vScale,0,lineWidth
IplImage tmp = IplImage(Imgdraw);
CvArr* src = (CvArr*)&tmp;


line(Imgdraw, cv::Point2d(Pred[0](0), Pred[0](1)), cv::Point2d(Pred[1](0), Pred[1](1)), Color);
line(Imgdraw, cv::Point2d(Pred[1](0), Pred[1](1)), cv::Point2d(Pred[2](0), Pred[2](1)), Color);
line(Imgdraw, cv::Point2d(Pred[2](0), Pred[2](1)), cv::Point2d(Pred[3](0), Pred[3](1)), Color);
line(Imgdraw, cv::Point2d(Pred[3](0), Pred[3](1)), cv::Point2d(Pred[0](0), Pred[0](1)), Color);

string showMsg = to_string(ObjId);
cvPutText(src, showMsg.c_str(), cvPoint(Pred[0](0), Pred[0](1)), &font,CV_RGB(255,255,0));
cv::putText(Imgdraw, showMsg.c_str(), cv::Point(Pred[0](0), Pred[0](1)), cv::FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,255,0), 0.35);
//cv::putText(src, showMsg.c_str(), cv::Point(Pred[0](0), Pred[0](1)), &font,CV_RGB(255,255,0));

return Imgdraw;
}

// return the text box && box with its region fill in (fusion of ShowTextBox+ShowTextBoxFill)
/*
vector<cv::Mat> tool::TextBoxWithFill(const vector<vector<Vec2>> &textbox, const vector<int> &vObjId, const Mat Img, const vector<int> &textLabel)
{
cv::Mat BackImg = cv::Mat::ones(Img.size(), CV_32F)*(-1.0);
Expand Down Expand Up @@ -2098,8 +2094,38 @@ vector<cv::Mat> tool::TextBoxWithFill(const vector<vector<Vec2>> &textbox, const
ImgOut.push_back(Imgdraw);
return ImgOut;
}
*/
vector<cv::Mat> tool::TextBoxWithFill(const vector<vector<Vec2>> &textbox, const vector<int> &vObjId, const Mat Img, const vector<int> &textLabel)
{
cv::Mat BackImg = cv::Mat::ones(Img.size(), CV_32F)*(-1.0);
Mat Imgdraw = Img.clone();
Scalar Color = Scalar(0, 0, 255);

for(size_t i0 = 0; i0<textbox.size(); i0++){
// 1. get text label
BackImg = GetTextLabelMask(BackImg, textbox[i0], textLabel[i0]); // CHECK, cv::Mat put pointer into func. maybe return the new mat to the same pointer

// 2. get text box show img
vector<Vec2> Box4Pts = textbox[i0];
line(Imgdraw, cv::Point2d(Box4Pts[0](0), Box4Pts[0](1)), cv::Point2d(Box4Pts[1](0), Box4Pts[1](1)), Color);
line(Imgdraw, cv::Point2d(Box4Pts[1](0), Box4Pts[1](1)), cv::Point2d(Box4Pts[2](0), Box4Pts[2](1)), Color);
line(Imgdraw, cv::Point2d(Box4Pts[2](0), Box4Pts[2](1)), cv::Point2d(Box4Pts[3](0), Box4Pts[3](1)), Color);
line(Imgdraw, cv::Point2d(Box4Pts[3](0), Box4Pts[3](1)), cv::Point2d(Box4Pts[0](0), Box4Pts[0](1)), Color);

// 3. show obj id
string showMsg = to_string(vObjId[i0]);
cv::putText(Imgdraw, showMsg.c_str(), cv::Point(Box4Pts[0](0), Box4Pts[0](1)), cv::FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,255,0), 0.35);
}

vector<cv::Mat> ImgOut;
ImgOut.push_back(BackImg);
ImgOut.push_back(Imgdraw);
return ImgOut;
}


// based on TextBoxWithFill, add semantic meaning
/*
vector<cv::Mat> tool::TextBoxWithFill(const vector<vector<Vec2>> &textbox, const vector<int> &vObjId, const vector<TextInfo> &textinfo, const Mat Img, const vector<int> &textLabel)
{
cv::Mat BackImg = cv::Mat::ones(Img.size(), CV_32F)*(-1.0);
Expand Down Expand Up @@ -2136,6 +2162,36 @@ vector<cv::Mat> tool::TextBoxWithFill(const vector<vector<Vec2>> &textbox, const
return ImgOut;
}

*/
vector<cv::Mat> tool::TextBoxWithFill(const vector<vector<Vec2>> &textbox, const vector<int> &vObjId, const vector<TextInfo> &textinfo, const Mat Img, const vector<int> &textLabel)
{
cv::Mat BackImg = cv::Mat::ones(Img.size(), CV_32F)*(-1.0);
Mat Imgdraw = Img.clone();
Scalar Color = Scalar(0, 0, 255);

for(size_t i0 = 0; i0<textbox.size(); i0++){
// 1. get text label
BackImg = GetTextLabelMask(BackImg, textbox[i0], textLabel[i0]); // CHECK, cv::Mat put pointer into func. maybe return the new mat to the same pointer

// 2. get text box show img
vector<Vec2> Box4Pts = textbox[i0];
line(Imgdraw, cv::Point2d(Box4Pts[0](0), Box4Pts[0](1)), cv::Point2d(Box4Pts[1](0), Box4Pts[1](1)), Color);
line(Imgdraw, cv::Point2d(Box4Pts[1](0), Box4Pts[1](1)), cv::Point2d(Box4Pts[2](0), Box4Pts[2](1)), Color);
line(Imgdraw, cv::Point2d(Box4Pts[2](0), Box4Pts[2](1)), cv::Point2d(Box4Pts[3](0), Box4Pts[3](1)), Color);
line(Imgdraw, cv::Point2d(Box4Pts[3](0), Box4Pts[3](1)), cv::Point2d(Box4Pts[0](0), Box4Pts[0](1)), Color);

// 3. show obj id
string showMsg = to_string(vObjId[i0]);
showMsg += textinfo[i0].mean;
cv::putText(Imgdraw, showMsg.c_str(), cv::Point(Box4Pts[0](0), Box4Pts[0](1)), cv::FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,255,0), 0.35);
}

vector<cv::Mat> ImgOut;
ImgOut.push_back(BackImg);
ImgOut.push_back(Imgdraw);
return ImgOut;
}


cv::Mat tool::GetTextLabelMask(const cv::Mat &BackImg, const vector<Vec2> &TextObjBox, const int &TextLabel)
{
Expand All @@ -2157,7 +2213,7 @@ cv::Mat tool::GetTextLabelMask(const cv::Mat &BackImg, const vector<Vec2> &TextO
cv::Mat ImgZero = cv::Mat::zeros(BackImg.size(),CV_8UC1);
cv::fillPoly(ImgZero, ptMask, npt, 1, cv::Scalar(255,255,255));

cv::namedWindow("ImgZero", CV_WINDOW_NORMAL);
cv::namedWindow("ImgZero", cv::WINDOW_NORMAL);
cv::imshow("ImgZero", ImgZero);
cv::waitKey(0);
}
Expand Down Expand Up @@ -2250,7 +2306,7 @@ void tool::ShowMatchesLP(const Mat &F1Img, const Mat &F2Img, const vector<Featur
drawMatches(F1Img, keys1, F2Img, keys2, match_show, img_match);

if(SHOW){
namedWindow("LP Matches", CV_WINDOW_NORMAL);
namedWindow("LP Matches", cv::WINDOW_NORMAL);
imshow("LP Matches", img_match);
waitKey(0);
}
Expand All @@ -2261,7 +2317,7 @@ void tool::ShowMatchesLP(const Mat &F1Img, const Mat &F2Img, const vector<Featur

void tool::ShowImg(const cv::Mat &ImgDraw, const string &name)
{
cv::namedWindow(name, CV_WINDOW_NORMAL);
cv::namedWindow(name, cv::WINDOW_NORMAL);
cv::imshow(name, ImgDraw);
cv::waitKey(0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ int tracking::GrabImageMonocular(const cv::Mat &im, const double &ImgTimeStamp,
cv::Mat ImTrack, ImTrack1;
im.copyTo(ImTrack);
if(Set->Flag_RGB==0)
cvtColor(ImTrack, ImTrack, CV_BGR2GRAY);
cvtColor(ImTrack, ImTrack, cv::COLOR_BGR2GRAY);
else if(Set->Flag_RGB==1)
cvtColor(ImTrack, ImTrack, CV_RGB2GRAY);
cvtColor(ImTrack, ImTrack, cv::COLOR_RGB2GRAY);

Width = ImTrack.cols;
Height = ImTrack.rows;
Expand Down