ROI2

#include “binary.hpp”
#include

void testROI(string fname)
{
stringstream ss;
int lx, ly, rx, ry;
Mat img=imread(fname);
int x1 = fname.rfind(’(’);
string s12 = fname.substr(x1 + 1, 2);
string s34 = fname.substr(x1 + 3, 2);
string s56 = fname.substr(x1 + 5, 2);
string s78 = fname.substr(x1 + 7, 2);
ss << s12;
ss >> lx;
ss.clear();
ss << s34;
ss >> ly;
ss.clear();
ss << s56;
ss >> rx;
ss.clear();
ss << s78;
ss >> ry;
ss.clear();
cout << lx << endl << ly << endl << rx << endl << ry << endl;
lx = lximg.cols/100;
ly = ly
img.rows/100;
rx = rx * img.cols/100;
ry = ry * img.rows/100;
cout << lx << endl << ly << endl << rx<< endl << ry << endl;
Rect roi(lx,ly,rx-lx,ry-ly);
Mat img1(img, roi);
imwrite(“ROI.png”, img1);
}

int main(int argc, char **argv)
{
if (argc < 3) return 0;
string s = argv[1];
string s1 = argv[2];
if (s == “ROI”)
{
testROI(s1);
}
return 0;
}

1.使用命令行参数,在project的project properties中可以添加命令行参数,空格后可以增加。
2.使用sstream库中的stringstream可以将string类型变为int类型
stringstream ss;
string s=“55”;
int x;
ss<<s;
ss>>x; /x=55/
3.string类中的rfind()函数可以找到字符串中的某个字符的位置,返回该字符的位置,返回类型为int。

发布了5 篇原创文章 · 获赞 1 · 访问量 597

猜你喜欢

转载自blog.csdn.net/davidhan427/article/details/103964966
ROI