baidu_36186174 2017-06-23 08:31 采纳率: 0%
浏览 1012

求大佬帮助,opencv灰度图片处理程序可以处理小图片,大图片就出现0xC0000005访问冲突

#include

#include

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;
// 大津法函数实现

int OTSU(cv::Mat srcImage)
{
int nCols = srcImage.cols;
int nRows = srcImage.rows;
int threshold = 0;
// 初始化统计参数

int nSumPix[256];
float nProDis[256];
for (int i = 0; i < 256; i++)
{
nSumPix[i] = 0;
nProDis[i] = 0;
}
// 统计灰度级中每个像素在整幅图像中的个数

for (int i = 0; i < nCols; i++)
{
for (int j = 0; j < nRows; j++)
{
int x = srcImage.at(i, j); ** // 此处出错**
nSumPix[x]++;
}
}
// 计算每个灰度级占图像中的概率分布

for (int i = 0; i < 256; i++)
{
nProDis[i] = (float)nSumPix[i] / (nCols * nRows);
}
// 遍历灰度级[0,255],计算出最大类间方差下的阈值

float w0, w1, u0_temp, u1_temp, u0, u1, delta_temp;
double delta_max = 0.0;
for (int i = 0; i < 256; i++)
{
// 初始化相关参数

w0 = w1 = u0_temp = u1_temp = u0 = u1 = delta_temp = 0;
for (int j = 0; j < 256; j++)
{
//背景部分

if (j <= i)
{
// 当前i为分割阈值,第一类总的概率

w0 += nProDis[j];
u0_temp += j * nProDis[j];
}
//前景部分

else
{
// 当前i为分割阈值,第一类总的概率

w1 += nProDis[j];
u1_temp += j * nProDis[j];
}
}
// 分别计算各类的平均灰度

u0 = u0_temp / w0;
u1 = u1_temp / w1;
delta_temp = (float)(w0 w1 pow((u0 - u1), 2));
// 依次找到最大类间方差下的阈值

if (delta_temp > delta_max)
{
delta_max = delta_temp;
threshold = i;
}
}
return threshold;
}

  • 写回答

5条回答 默认 最新

  • baidu_36186174 2017-06-23 08:46
    关注

    图片说明
    此处调用堆栈

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料