opencv imread()在Windows上的非ASCII文件名 [英] opencv imread() on Windows for non-ASCII file names

查看:573
本文介绍了opencv imread()在Windows上的非ASCII文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个在Windows上打开(和编写)包含非Ascii字符的文件路径的OpenCV问题。
我看到了问题 OpenCV使用外部字符imread(openCV ),QString unicodes ,但仍然不明白解决问题的正确方法。

We have an OpenCV problem of opening (and writing) file paths that contain non-Ascii characters on Windows. I saw questions OpenCV imread with foreign characters and imread(openCV),QString unicodes but still didn't understand a proper way of solving the problem.

就像我在OpenCV源代码中看到的,它甚至在Windows上使用fopen(而不是_wfopen),afaik fopen不处理Windows上的非ascii字符。从上面的问题,我看到可能有一些技巧使用QStrings,但如果它的工作原理是什么?如何将unicode字符串转换为Windows?fopen()接受的字符数组?

As far I as I saw in the OpenCV source code, it uses fopen even on Windows (instead of _wfopen) and afaik fopen does not handle non-ascii characters on Windows. From the questions above I saw that there could be some trick using QStrings, but if it works what does it exactly do? How does it transform a unicode string to a character array that will be accepted by Windows' fopen()?

我们不使用QT

提前感谢!

推荐答案

没有破解OpenCV源代码的方法是使用 _wfopen (如Remy建议)将整个文件读入内存缓冲区。然后使用OpenCV的函数 imdecode 从该缓冲区创建 cv :: Mat

The way to do this without hacking the OpenCV source code is to use _wfopen (as Remy suggested) to read the whole file into a memory buffer. Then use OpenCV's function imdecode to create a cv::Mat from that buffer.

如果有必要,请使用 imencode 撰写图像到内存缓冲区,然后使用 _wfopen 打开一个具有UNICODE名称的文件,并将缓冲区写入它(或者,您可以 imwrite 到一个临时文件,然后使用相应的API函数移动/重命名它。)

You can do the reverse too, if necessary - i.e. use imencode to write an image to a memory buffer, then use _wfopen to open a file with a UNICODE name and write the buffer to it (alternatively, you could just imwrite to a temporary file and then move/rename it using the appropriate API function).

这篇关于opencv imread()在Windows上的非ASCII文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆