问题描述
- c++ 0xC0000005: 读取位置 0x02F91000 时发生访问冲突
-
double a[65536] = { 0 };
double b[65536] = { 0 };
double c[65536] = { 0 };void C测试Dlg::OnBnClickedButton9()
{
// TODO: 在此添加控件通知处理程序代码
Mat img = imread("F:结果2.bmp",4);
int width = img.cols;
int height = img.rows;
int step = img.step;
double total = img.cols*img.rows;
for (int i = 0; i <img.rows; i++)
{
for (int j = 0; j < img.cols; j++)
a[((ushort*)img.data + i*step)[j]]++;
}
for (int i = 0; i <65536; i++)
{
b[i] = (double)a[i] / total;
if (i == 0)c[i] = b[i];
else c[i] = c[i - 1] + b[i];
}
//图像增强
for (int i = 0; i < img.rows; i++)
{
for (int j = 0; j < img.cols; j++)
{((ushort*)(i *img.step + img.data))[j] = c[((ushort*)(i * img.step + img.data))[j]] * 65535; } } imwrite("F:结果直方图11.bmp", img); HBITMAP bitmap; bitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(), _T("F:结果直方图11.bmp"), IMAGE_BITMAP, 300, 300, LR_LOADFROMFILE); m_show1.SetBitmap(bitmap);
}
是指针的问题?还是什么。求解
解决方案
程序启动的时候,弹出如下错误框.......
答案就在这里:0xC0000005: 读取位置 0x01900014 时发生访问冲突
----------------------
解决方案二:
非法访问内存的情况都有哪些呢,你想过吗.