Linux平台下用OpenCV读取文件夹内图片并显示
2017-10-24 13:57
615 查看
#include <cv.h>
#include <highgui.h>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
//定义文件夹的绝对路径
const char* dir_name = "/home/zhhangfuqiang/images/";
struct dirent * filename; // return value for readdir()
DIR * dir; // return value for opendir()
//打开文件夹
dir = opendir( dir_name );
cout<<"Successfully opened the dir !"<<endl;
/* 遍历文件夹中的所有文件 */
while( ( filename = readdir(dir) ) != NULL )
{
get rid of "." and ".."
if( strcmp( filename->d_name , "." ) == 0 ||
strcmp( filename->d_name , "..") == 0 )
continue;
cout<<filename ->d_name <<endl;
//为文件名赋值
string name=filename->d_name;
//OpenCV读取Mat格式的图片
Mat img=imread("/home/zhangfuqiang/images/"+name, CV_LOAD_IMAGE_UNCHANGED);
//实例化窗口
cv:: namedWindow("Depth image");
Mat img_update;
//因为我是用Kinect2采集的图片,尺寸为1920x1080,我把它压缩一下
cv::resize(img,img_update,cv::Size(640,480),(0,0),(0,0),cv::INTER_LINEAR);
//在窗口上展示图片
imshow("Depth image",img_update);
//wait key for 5000ms
cv::waitKey(500);
}
#include <highgui.h>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
//定义文件夹的绝对路径
const char* dir_name = "/home/zhhangfuqiang/images/";
struct dirent * filename; // return value for readdir()
DIR * dir; // return value for opendir()
//打开文件夹
dir = opendir( dir_name );
cout<<"Successfully opened the dir !"<<endl;
/* 遍历文件夹中的所有文件 */
while( ( filename = readdir(dir) ) != NULL )
{
get rid of "." and ".."
if( strcmp( filename->d_name , "." ) == 0 ||
strcmp( filename->d_name , "..") == 0 )
continue;
cout<<filename ->d_name <<endl;
//为文件名赋值
string name=filename->d_name;
//OpenCV读取Mat格式的图片
Mat img=imread("/home/zhangfuqiang/images/"+name, CV_LOAD_IMAGE_UNCHANGED);
//实例化窗口
cv:: namedWindow("Depth image");
Mat img_update;
//因为我是用Kinect2采集的图片,尺寸为1920x1080,我把它压缩一下
cv::resize(img,img_update,cv::Size(640,480),(0,0),(0,0),cv::INTER_LINEAR);
//在窗口上展示图片
imshow("Depth image",img_update);
//wait key for 5000ms
cv::waitKey(500);
}
相关文章推荐
- Opencv读取文件夹连续图片,RGB分量显示,图像灰度化
- Opencv读取文件夹连续图片,RGB分量显示,图像灰度化
- Opencv读取文件夹连续图片,RGB分量显示,图像灰度化
- OpenCV基础篇之读取显示图片
- opencv读取,显示,写入图片(关于imwrite函数)
- OpenCV读取图片,从摄像头读入视频,从文件夹中读入视频
- Java开发Opencv之(二)读取与显示图片
- opencv3.x遍历文件夹读取图片
- opencv中逐文件夹读取图片
- Linux+qt+opencv显示图片
- Android开发之--读取文件夹下图片生成略缩图并点击显示大图
- opencv:批量读取一个文件夹下的图片,并转换成视频
- opencv 读取一个文件夹下的多张图片并处理保存
- opencv读取某文件夹下图片并进行归一化
- OpenCV基础篇之读取显示图片
- TensorFlow与OpenCV,读取图片,进行简单操作并显示
- OpenCv中批量读取图片数据并显示出来的C++程序
- Opencv2.3.1读取图片并显示
- vs2015+opencv3.2+mfc读取摄像头显示在图片控件Picture Control
- OpenCV基础篇之读取显示图片