python c++ opencv打开图片路径写法

python代码

python 复制代码
import cv2

img = cv2.imread("d:\\2.jpg")
# img = cv2.imread("d:/2.jpg") 
cv2.imshow("1",img)
cv2.waitKey(0)
cv2.destroyAllWindows()

也就是说如果d盘有一张图片2.jpg,可以写成以下2种方式,注意斜杠方向,图片名字最好不要中文。

img = cv2.imread("d:\\2.jpg")

或

img = cv2.imread("d:/2.jpg")

c++代码:

cpp 复制代码
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main()
{
	// 读入一张图片(游戏原画)
	Mat img=imread("D:\\2.jpg");
	// 创建一个名为 "游戏原画"窗口
	namedWindow("game");
	// 在窗口中显示游戏原画
	imshow("game",img);
	// 等待6000 ms后窗口自动关闭
	waitKey(0);
}

或者:Mat img=imread("D:/2.jpg");

相关推荐
钱栈up14 小时前
奥迪上汽拍板「三年三款」,合资阵营的换挡节奏终于跟上了
爬虫·python·数据分析
东莞市云毅网络有限公司14 小时前
SQLite FTS5 做中文问答检索:分词、排序与召回测试
python·sqlite·自动化运维·geo·数据监测
timeDifference₇1 天前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu1 天前
python:DecisionTree
开发语言·后端·python·算法
ShineWinsu1 天前
对于Qt:事件的解析
c++·qt·面试·笔试·gui·客户端·事件
怒放的生命19911 天前
代码知识库 RAG 问答系统 —— 从 0 到 1 实现教程
python·状态模式·fastapi·全栈开发·ai agent应用开发
geovindu1 天前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
闻缺陷则喜何志丹1 天前
【数论】P10136 [USACO24JAN] Cowlendar S|普及+
c++·数学·数论·洛谷
fengkai45451 天前
Python运维
运维·python·监控·psutil·ipy
Fancy.7611 天前
:Python条件与循环语句学习总结
python