OpenCV在windows,QT,C++环境下读取中文路径文件
·
OpenCV在windows,QT,C++环境下读取中文路径文件
opencv4.x本身是不支持中文编码的,在qt中可以通过获取操作系统的编码类型,将指定字符串编码为对应操作系统的编码的字节序列,从而绕过opencv本身,由操作系统来完成字符串的解码和对中文路径的访问。
QString path("C:/Users/24795/Desktop/111 - 副本.bmp");
// 编码为系统本地编码(Windows 下通常是 GBK)
QStringEncoder encoder(QStringConverter::Encoding::System);
QByteArray localEncodedPath = encoder(path);
std::string stdFilePath = byteFilePath.toStdString();
qInfo() << __FUNCTION__ << stdFilePath;
cv::Mat img = cv::imread(stdFilePath,cv::IMREAD_GRAYSCALE);
控制台输出
main "C:/Users/24795/Desktop/111 - \xB8\xB1\xB1\xBE.bmp"
更多推荐
所有评论(0)