Ask Your Question

Revision history [back]

Does cv::VideoCapture support both UTF-8 and traditional codepage-encoded strings?

Hello, I recently built OpenCV 3.2.0 from the Git repository (I downloaded the current source code in the master-branch, and I think it is somewhat different from the currently available official release), and built it on Windows 7, Visual Studio 2015, with CUDA support.

Please look at the following code:

int main()
{
    cv::VideoCapture vc_949{ "안녕\\이런.wmv" };
    std::cout << vc_949.isOpened() << std::endl;
    cv::VideoCapture vc_utf8{ u8"안녕\\이런.wmv" };
    std::cout << vc_utf8.isOpened() << std::endl;
}

I compiled this with Visual Studio 2015 and it prints:

1
1

Two character arrays "안녕\\이런.wmv" and u8"안녕\\이런.wmv" were completely different; even their lengths are not the same. But it seems that both vc_949 and vc_utf8 opens the video without any problem.

I wonder:

  1. How that's possible? Underlying data type of two strings are the same, and they call the same overload of the constructor.
  2. Which one is the preferred way? I wish I can use UTF-8 strings, but I've heard lots of complains about unicode support in OpenCV. Is it safe to use UTF-8 encoded strings for cv::VideoCapture (or other OpenCV components working with files) in Windows?