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

比如用 imread() 读取这个文件夹下的test.jpg
《OpenCV读取图片路径的几种写法》
可以有下面几种方法


#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;
}

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

    原文作者:流楚丶格念
    原文地址: https://blog.csdn.net/weixin_45525272/article/details/120811295
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞