license-plate-detect-recoginition-opencv
license-plate-detect-recoginition-opencv copied to clipboard
关于调试输出乱码问题
不好意思我是新手,main.cpp要如何启动呢?使用vs2019打开后报了很多错,是否是需要配置依赖项?
上个问题已解决,但是现在新问题就是调试输出是乱码应该如何解决呢,请大佬指教

然后报错是这些

然后报错是这些
你的opencv安装成功了嘛
然后报错是这些
你的opencv安装成功了嘛
成功的,环境配置应该也没错
这个乱码问题主要出在了
函数 string lprnet::rec(Mat img)中
for (i = 0; i < len_s; i++) { result.push_back(name[no_repeat_blank_label[i]]); }
这里对 name 数组取索引,然而前面的声明中
extern const string name = "京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新0123456789ABCDEFGHJKLMNPQRSTUVWXYZIO-";
name中包含中文和英文字符,取索引时每个长度不一致,应使用wstring类型,改为
extern const wstring name = L"京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新0123456789ABCDEFGHJKLMNPQRSTUVWXYZIO-";
后面的代码也同样改用wstring
wstring result; for (i = 0; i < len_s; i++) { result.push_back(name[no_repeat_blank_label[i]]); } // cout << wstring2string(result) << endl; return wstring2string(result);
其中自定义转换函数如下,使用了两个api进行转换
#include <comdef.h> string wstring2string(wstring wstr) { string result; int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL); if (len <= 0)return result; char* buffer = new char[len + 1]; if (buffer == NULL)return result; WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL); buffer[len] = '\0'; result.append(buffer); delete[] buffer; return result; } wstring string2wstring(string str) { wstring result; int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0); if (len < 0)return result; wchar_t* buffer = new wchar_t[len + 1]; if (buffer == NULL)return result; MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len); buffer[len] = '\0'; result.append(buffer); delete[] buffer; return result; }
成功解决乱码的问题