分享

OpenCV读取图片路径的几种写法

 流楚丶格念 2022-01-14

比如用 imread() 读取这个文件夹下的test.jpg
在这里插入图片描述
可以有下面几种方法


#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>  

using namespace cv;

int main(int argc, char* argv[])
{
Mat img;

//-- 1 --双右斜线法  
//string imgpath = "D:\\Study\\Picture\\test2.jpg";  
//-- 2 --双左斜线法  
//string imgpath = "D://Study//Picture//test2.jpg";  
//-- 3 --单左斜线法  
//string imgpath = "D:/Study/Picture/test2.jpg";  
//-- 4 --以上三种混合法  
//string imgpath = "D: /Study//Picture\\test2.jpg";  
//-- 5 --相对路径法  把图片放在本文件的当前目录下
//string imgpath = "test2.jpg";  
//-- 6 --命令行参数法  
string imgpath = argv[1];

img = imread(imgpath, 1);
imshow("img", img);

waitKey(0);
return 0;
}

在这里插入图片描述

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多