码迷,mamicode.com
首页 > 其他好文 > 详细

openCV打开图像或视频时绝对路径输入格式

时间:2015-05-04 18:17:51      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

在openCV中打开图像或视频的方法有多种,最常用的有
1、只需输入文件名和后缀名
    当需要打开的文件存放在工程文件下的test文件夹下时,只需输入文件名和后缀名,博主在这提醒初学者,一定注意后缀名问题,我已吃过很多次亏了,一个有效的办法是加一个验证过程,如下代码所示:
Mat image = imread("pp.jpg",0);
 if (image.empty())
 {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
  cout << "error";
  return -1;
 }
 cout << "image尺寸:" << image.rows << "  " << image.cols << endl;
 
2、绝对路径
    当需要打开的文件存放在自己指定的文件夹下时(最好不用中文路径,你懂的)会用的绝对路径,这里需要注意的是绝对路径的格式问题。从地址栏直接粘贴复制过来时不能用。如:VideoCapture capture("E:\zipai.wmv");。正确的格式是:VideoCapture capture("E:\\zipai.wmv");不知你看出区别没有。
   当你的文件存放在test文件夹下时,你想使用绝对路径打开有两种方式,第一种就是上面提到的完整路径,第二种就是简单路径../zipai.wmv。注意前面的两点和斜杠的方向。

使用绝对路径也应该加一个验证工程避免出错


openCV打开图像或视频时绝对路径输入格式

标签:

原文地址:http://blog.csdn.net/sunshine_in_moon/article/details/45481865

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!