lgyqpp 2018-09-27 08:46 采纳率: 0%
浏览 1185

如何调用另一个类的源文件(cpp)中的某个函数的计算结果(变量)?

现有一个程序,可以根据地址读取两幅图像,可以处理像素,目的是计算两幅图像对应像素点的lab的差值,同时计算色差,并通过一个按钮显示到一个编辑框里面。目前大部分算法都已写完,就是点击按钮如何让计算结果显示到编辑框中那一步不太会。
先给出我的CGDALProcess累里的ColorAberration函数。

double CGDALProcess::ColorAberration(CString imgPath, CString imgRefPath)
{
GDALDataset* datasetsrc = (GDALDataset*)GDALOpen(imgPath, GA_ReadOnly);
GDALDataset* datasetref = (GDALDataset*)GDALOpen(imgRefPath, GA_ReadOnly);

if (nullptr == datasetsrc)
{
    return 0;
}
if (nullptr == datasetref)
{
    datasetref = datasetsrc;
}

int bandCount = datasetsrc->GetRasterCount();
int width = datasetsrc->GetRasterXSize();
int height = datasetsrc->GetRasterYSize();

int bandCountref = datasetref->GetRasterCount();
int widthref = datasetref->GetRasterXSize();
int heightref = datasetref->GetRasterYSize();

if (bandCount > 3)
{
    bandCount = 3;
}

//设置仿射变换
double adfGeoTransform[6] = { 0 };
datasetsrc->GetGeoTransform(adfGeoTransform);

unsigned char * imageRGB = new unsigned char[width * height * 3]();
unsigned char * imageRefRGB = new unsigned char[widthref * heightref * 3]();

int bandmap[3] = { 1, 2, 3 };

datasetsrc->RasterIO(GF_Read, 0, 0, width, height, imageRGB, width, height, GDT_Byte, bandCount, bandmap, bandCount, bandCount * width, 1);
datasetref->RasterIO(GF_Read, 0, 0, widthref, heightref, imageRefRGB, widthref, heightref, GDT_Byte, bandCount, bandmap, bandCount, bandCount * widthref, 1);

int src_Size = width * height;//原图大小
int ref_Size = widthref * heightref;//模版图像大小

//src RGB to Lab
double *imgSrc_lab = new double[src_Size * 3];
for (int i = 0; i < src_Size * 3; i += 3)
{
    Rgb2Lab(imageRGB[i + 0], imageRGB[i + 1], imageRGB[i + 2], imgSrc_lab[i + 0], imgSrc_lab[i + 1], imgSrc_lab[i + 2]);
}

//ref RGB to Lab
double *imgRef_lab = new double[ref_Size * 3];
for (int i = 0; i < ref_Size * 3; i += 3)
{
    Rgb2Lab(imageRefRGB[i + 0], imageRefRGB[i + 1], imageRefRGB[i + 2], imgRef_lab[i + 0], imgRef_lab[i + 1], imgRef_lab[i + 2]);
}

//求两幅图所有像素值lab三通道差值的和(模版图像lab-原始图像lab),再除以图像大小以求平均值
int i;
int suml(0); int suma(0); int sumb(0);
for (i = 0; i< src_Size; i++)
{
    suml += imgRef_lab[i * 3 + 0] - imgSrc_lab[i * 3 + 0];
    suma += imgRef_lab[i * 3 + 1] - imgSrc_lab[i * 3 + 1];
    sumb += imgRef_lab[i * 3 + 1] - imgSrc_lab[i * 3 + 1];
}

double deltal;
double deltaa;
double deltab;

deltal = suml / src_Size;
deltaa = suma / src_Size;
deltab = sumb / src_Size;

return deltal;

delete[] imageRGB;
imageRGB = nullptr;
delete[] imageRefRGB;
imageRefRGB = nullptr;

GDALClose(datasetsrc);

}

然后是我dlg里的按钮代码
void CColorTransferDlg::OnBnClickedButton2()
{
if (m_strSrcPath == "" || m_strRefPath == "" )
return;

int t;

CGDALProcess ca;
t = ca.ColorAberration(m_strSrcPath, m_strRefPath);

UpdateData(TRUE);//读取控件变量值

m_m = t; 

UpdateData(FALSE);//把改过的值更新到控件

}

这是我自己的方法,打算先把l提取并显示的,但貌似不能计算出来。不知道怎么解决

  • 写回答

2条回答

  • wjintao 2018-09-27 08:59
    关注

    建议在OnBnClickedButton2()打断点,定位问题

    评论

报告相同问题?

悬赏问题

  • ¥20 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏