Qt OpenCV imread 中文路径

 

开发环境:  Qt5.7  Creator + OpenCV2.4.9(自己编译的);

问题:imread中文路径无法成功,英文路径就可以。

 

解决办法1:

        cv::Mat image ;
        QFile file(strFilePath);  //strFilePath 路径
        if(file.open(QIODevice::ReadOnly ))
        {
               QByteArray byteArray  = file.readAll();
               std::vector<char> data(byteArray.data(),byteArray.data()+ byteArray.size());
               image = cv::imdecode(cv::Mat(data),1);  //>0 Return a 3-channel color image
               file.close();
         }

 

解决办法2:

 

QString strPath = 中文路径地址
std::string path = strPath.toLocal8Bit().toStdString(); //关键是这个
cv::Mat image = cv::imread(path,1 ); //成功了

 

 

解决办法3://Unicode转码为UTF-8  

void UNICODE_to_UTF8(CStringW& unicodeString, std::string& str)
{
	int stringLength = ::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, wcslen(unicodeString), NULL, 0, NULL, NULL);

	char* buffer = new char[stringLength + 1];
	::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, wcslen(unicodeString), buffer, stringLength, NULL, NULL);
	buffer[stringLength] = '\0';

	str = buffer;

	delete[] buffer;
}

 

办法3 参考自文章http://blog.csdn.net/leixiaohua1020/article/details/42363593, 我还没有测试

 

 

 

 

 

 

 

 

 

 

 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值