当前位置:网站首页>【opencv450-samples】读取图像路径列表并保持比例显示
【opencv450-samples】读取图像路径列表并保持比例显示
2022-06-25 21:58:00 【十年一梦实验室】
/*
* Created on: Nov 23, 2010
* Author: Ethan Rublee
*
* A starter sample for using opencv, load up an imagelist
* that was generated with imagelist_creator.cpp
* easy as CV_PI right?
*/
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <vector>
using namespace cv;
using namespace std;
static void help(char** av)
{
cout << "\nThis program gets you started being able to read images from a list in a file\n"
"Usage:\n./" << av[0] << " image_list.yaml\n"
<< "\tThis is a starter sample, to get you up and going in a copy pasta fashion.\n"
<< "\tThe program reads in an list of images from a yaml or xml file and displays\n"
<< "one at a time\n"
<< "\tTry running imagelist_creator to generate a list of images.\n"
"Using OpenCV version %s\n" << CV_VERSION << "\n" << endl;
}
//读取路径字符串列表
static bool readStringList(const string& filename, vector<string>& l)
{
l.resize(0);//调整容器大小
FileStorage fs(filename, FileStorage::READ);//读取文件
if (!fs.isOpened())
return false;
FileNode n = fs.getFirstTopLevelNode();//首节点
if (n.type() != FileNode::SEQ)
return false;
FileNodeIterator it = n.begin(), it_end = n.end();//迭代器
for (; it != it_end; ++it)
l.push_back((string)*it);//加入列表
return true;
}
//依次显示所有图像灰度图
static int process(const vector<string>& images)
{
namedWindow("image", WINDOW_KEEPRATIO); //保持图像比例 resizable window;
for (size_t i = 0; i < images.size(); i++)
{
Mat image = imread(images[i], IMREAD_GRAYSCALE); // do grayscale processing?
imshow("image", image);
cout << "Press a key to see the next image in the list." << endl;
waitKey(); // wait infinitely for a key to be pressed
}
return 0;
}
int main(int ac, char** av)
{
cv::CommandLineParser parser(ac, av, "{help h||}{@input||}");
if (parser.has("help"))
{
help(av);
return 0;
}
std::string arg = parser.get<std::string>("@input");//文件名
if (arg.empty())
{
help(av);
return 1;
}
vector<string> imagelist;//图像路径列表
if (!readStringList(arg, imagelist))//读取文件路径列表
{
cerr << "Failed to read image list\n" << endl;
help(av);
return 1;
}
return process(imagelist);
}
边栏推荐
- Fastjson deserialization randomness failed
- Basic concepts of processor scheduling
- 小程序-视图与逻辑
- Which PHP open source works deserve attention
- Unity技术手册 - 粒子基础主模块属性-上
- The new version of Tencent's "peace elite" is coming: add a new account security protection system, and upgrade the detection of in-game violations
- 腾讯《和平精英》新版本将至:新增账号安全保护系统,游戏内违规行为检测升级
- ORACLE - 数据查询
- Flex & Bison 開始
- STM32 development board + smart cloud aiot+ home monitoring and control system
猜你喜欢

Unity的Ping类使用

【opencv450-samples】inpaint 使用区域邻域恢复图像中的选定区域

oracle -- 表操作

2022 love analysis · panoramic report of it operation and maintenance manufacturers

Use and difference between ue4\ue5 blueprint node delay and retroggable delay

Kubernetes cluster construction of multiple ECS

UE4_ Ue5 combines the offline voice recognition plug-in for speech recognition

UE4\UE5 蓝图节点Delay与Retriggerable Delay的使用与区别

STM32开发板+机智云AIoT+家庭监测控制系统

ES6 -- 形参设置初始值、拓展运算符、迭代器、生成函数
随机推荐
Flex & Bison 開始
The wisdom of questioning? How to ask questions?
How to disable the optical drive
zabbix_server配置文件详解
剑指 Offer 46. 把数字翻译成字符串(DP)
How do I project points on a 3D plane- How to project a point onto a plane in 3D?
OSPF - detailed explanation of GRE tunnel (including configuration command)
Trillions of hot money smashed into the space economy. Is it really a good business?
小程序绘制一个简单的饼图
[eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)
Set up your own website (15)
Oracle - 基本入门
ES6 const constants and array deconstruction
哪些PHP开源作品值得关注
Intimacy - [comfortable exit] - final communication to reduce injury
What are the channels for Internet advertising to gain customers?
Sword finger offer 46 Translate numbers to strings (DP)
电路模块分析练习6(开关)
PDM fur