#include <iostream>
bool divide_images = false;
vector<Mat> imgs;
string result_name = "result.jpg";
void printUsage(char** argv);
int parseCmdArgs(int argc, char** argv);
int main(
int argc,
char* argv[])
{
int retval = parseCmdArgs(argc, argv);
if (retval) return EXIT_FAILURE;
if (status != Stitcher::OK)
{
cout << "无法拼接图像,错误代码 = " << int(status) << endl;
return EXIT_FAILURE;
}
imwrite(result_name, pano);
cout << "拼接完成\n" << result_name << " 已保存!";
return EXIT_SUCCESS;
}
void printUsage(char** argv)
{
cout <<
"图像拼接器。\n\n" << "使用方法:\n" << argv[0] <<" [标志] img1 img2 [...imgN]\n\n"
"标志:\n"
" --d3\n"
" 内部将每个图像创建三个块以提高拼接成功率\n"
" --mode (panorama|scans)\n"
" 确定拼接器的配置。默认为 'panorama',\n"
" 此模式适用于创建照片全景图。'scans' 选项适用于\n"
" 拼接仿射变换下的材料,例如扫描件。\n"
" --output <result_img>\n"
" 默认为 'result.jpg'。\n\n"
"示例用法:\n" << argv[0] << " --d3 --mode scans img1.jpg img2.jpg\n";
}
int parseCmdArgs(int argc, char** argv)
{
if (argc == 1)
{
printUsage(argv);
return EXIT_FAILURE;
}
for (int i = 1; i < argc; ++i)
{
if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
{
printUsage(argv);
return EXIT_FAILURE;
}
else if (string(argv[i]) == "--d3")
{
divide_images = true;
}
else if (string(argv[i]) == "--output")
{
result_name = argv[i + 1];
i++;
}
else if (string(argv[i]) == "--mode")
{
if (string(argv[i + 1]) == "panorama")
mode = Stitcher::PANORAMA;
else if (string(argv[i + 1]) == "scans")
mode = Stitcher::SCANS;
else
{
cout << "--mode 标志值无效\n";
return EXIT_FAILURE;
}
i++;
}
else
{
Mat img =
imread(samples::findFile(argv[i]));
{
cout << "无法读取图像 '" << argv[i] << "'\n";
return EXIT_FAILURE;
}
if (divide_images)
{
imgs.push_back(img(rect).clone());
imgs.push_back(img(rect).clone());
imgs.push_back(img(rect).clone());
}
else
imgs.push_back(img);
}
}
return EXIT_SUCCESS;
}
bool empty() const
如果数组没有元素,则返回 true。
int rows
行和列的数量,当矩阵超过 2 维时为 (-1, -1)
定义 mat.hpp:2155
二维矩形的模板类。
定义 types.hpp:444
Status
定义 stitching.hpp:153
std::shared_ptr< _Tp > Ptr
定义 cvstd_wrapper.hpp:23
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
从文件中加载图像。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3