#include "windows.h"
void imagePro::getIni(double &thickness, double &sharpness, cv::string &mode, double &constrastRatio, double &wPara,int &ibit)
{
LPTSTR lpPath = new char[MAX_PATH];
LPTSTR _thickness = new char[MAX_PATH];
LPTSTR _sharpness = new char[MAX_PATH];
LPTSTR _mode = new char[MAX_PATH];
LPTSTR _constrastRatio = new char[MAX_PATH];
LPSTR _wPara = new char[MAX_PATH];
strcpy(lpPath, "..\\alParameters.ini");
if (!GetPrivateProfileString("Pro", "thickness", "", _thickness, MAX_PATH, lpPath) |
!GetPrivateProfileString("Pro", "sharpness", "", _sharpness, MAX_PATH, lpPath) |
!GetPrivateProfileString("Pro", "mode", "", _mode, MAX_PATH, lpPath) |
!GetPrivateProfileString("Pro", "constrastRatio", "", _constrastRatio, MAX_PATH, lpPath) |
!GetPrivateProfileString("Pro", "wPara", "", _wPara, MAX_PATH, lpPath) |
!GetPrivateProfileInt("Model", "ibit", 0, lpPath)
)
{
setIni();
}
ibit = GetPrivateProfileInt("Model", "ibit", 0, lpPath);
thickness = strtod(_thickness, NULL);
sharpness = strtod(_sharpness, NULL);
mode = (string)_mode;
constrastRatio = strtod(_constrastRatio, NULL);
wPara = strtod(_wPara, NULL);
// cout << thickness << endl;
// cout << sharpness << endl;
// cout << mode << endl;
// cout << constrastRatio << endl;
// cout << wPara << endl;
// cout << canny_Par << endl;
//添加判断 如果不符合规则 则不用这个函数
delete lpPath;
delete _thickness;
delete _sharpness;
delete _mode;
delete _constrastRatio;
delete _wPara;
}
setini()写入的ini文件如下,使用getIni()函数取值:
void imagePro::setIni()
{
LPTSTR lpPath = new char[MAX_PATH];
strcpy(lpPath, "..\\alParameters.ini");
WritePrivateProfileString("Pro", "thickness", "5", lpPath);
WritePrivateProfileString("Pro", "sharpness", "0.2", lpPath);
WritePrivateProfileString("Pro", "mode", "CV_LOGdddd", lpPath);
WritePrivateProfileString("Pro", "constrastRatio", "10", lpPath);
WritePrivateProfileString("Pro", "wPara", "0.10", lpPath);
WritePrivateProfileString("Shear", "canny_Par", "25", lpPath);
delete lpPath;
}