当前位置:网站首页>【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);
}
边栏推荐
- Wpewebkit debugging MSE playback
- Huawei cloud SRE deterministic operation and maintenance special issue (the first issue)
- Why is the frame rate calculated by opencv wrong?
- 荣耀推出积分商城,支持兑换各种荣耀产品
- ORACLE - 数据查询
- As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)
- Unity技术手册 - 粒子发射和生命周期内速度子模块
- Actual combat: how to quickly change font color in typera (blog sharing - perfect) -2022.6.25 (solved)
- 电路模块分析练习6(开关)
- Recently prepared to translate foreign high-quality articles
猜你喜欢
Circuit module analysis exercise 5 (power supply)
Unity的Ping类使用
使用EAST ocr遇到的坑解决方法(编译lanms)
Intimacy - [comfortable exit] - final communication to reduce injury
1281_FreeRTOS_vTaskDelayUntil实现分析
Oracle -- table operation
民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
Es7/es9 -- new features and regularities
STM32 development board + smart cloud aiot+ home monitoring and control system
Why is the frame rate calculated by opencv wrong?
随机推荐
Core points of assembly language
ES6 - numerical extension and object extension
Fastjson deserialization randomness failed
The applet draws a simple pie chart
2022 love analysis · panoramic report of it operation and maintenance manufacturers
NLP text summary: use the pre training model to perform text summary tasks [transformers:pipeline, T5, Bart, Pegasus]
【ModuleBuilder】GP服务实现SDE中两个图层相交选取
.sql数据库导入错误:/*!40101 SET @[email protected]@COLLATION_CONNECTION */
异或运算符简单逻辑运算 a^=b
Civil Aviation Administration: by 2025, China will initially build a safe, intelligent, efficient and green aviation logistics system
Implementation of importing vscode from PDM
小程序绘制一个简单的饼图
Unity技术手册 - 粒子基础主模块属性-上
2、一个向量乘它的转置,其几何意义是什么?
UE4_ Ue5 combines the offline voice recognition plug-in for speech recognition
Recently prepared to translate foreign high-quality articles
Live800在线客服系统:跨越时空做生意,从每次互动开始
Oracle -- table operation
1281_FreeRTOS_vTaskDelayUntil实现分析
Unity technical manual - particle emission and life cycle velocity sub module