我試圖讓a simple OpenCV sample在Windows上使用C++,而我的C++不僅僅是生鏽。將_TCHAR *轉換爲char *
The sample是相當簡單:所以之前
int _tmain(int argc, _TCHAR* argv[])
:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if(argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if(! image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
當我提出一個新的簡單的C++控制檯在Visual Studio應用程序(使用ATL)2012我得到main
不同的模板我發送文件名到OpenCV的imread
函數,我需要將_TCHAR*
arg[1]
轉換爲char*
。使用一個簡單的文件名,「OpenCV的-logo.jpg」,從內存窗口中的內存,我可以看到_TCHAR正在採取兩個字節每個
o.p.e.n.c.v.-.l.o.g.o...j.p.g...
6f 00 70 00 65 00 6e 00 63 00 76 00 2d 00 6c 00 6f 00 67 00 6f 00 2e 00 6a 00 70 00 67 00 00 00
繼轉換建議在another answer我試圖使用ATL 7.0 String Conversion Classes and Macros通過將以下代碼:
char* filename = CT2A(argv[1]);
但所得到的存儲器是亂的,肯定不是 '的OpenCV-logo.jpg' 爲ASCII字符串:
fe fe fe fe fe fe fe fe fe fe ...
þþþþþþþþþþ ...
我應該使用哪種轉換技術,函數或宏?
(注:This可能是一個相關的問題,但我看不出如何適用於此the answer。)
您的項目模板正試圖爲unicode支持創建一個C++項目。我不記得具體的項目/編譯器選項,但應該有一些指定是否使用unicode。 – OldProgrammer
它在[通用項目屬性頁面](http://msdn.microsoft.com/en-us/library/vstudio/8x480de8.aspx) – user786653
您需要USES_CONVERSION;語句在使用轉換宏的每個函數的頂部? –