Calculating MyHistogram
Hi all,
I'm trying to do a version of mine to calcolute an Histogram.
I think that the logic is this, but i don't know why it's going in segmentation fault.
Can anyone help me?
//My Hist
int Occorrenze[255];
for(int i=0;i<255;i++)
Occorrenze[i]=0;
for(int i=0;i<src.rows;i++)
{
for(int j=0;j<src.cols;j++)
{
Occorrenze[src.at<uchar>(i,j)]++;
}
}
Mat MyHist(255,255,CV_8U);
for(int colonna=0;colonna<255;colonna++)
{
int numero=0;
int flag=0;
while(numero != Occorrenze[colonna] && flag==0)
{
MyHist.at<uchar>((255-numero),colonna)=255;
numero++;
if(numero==255)
flag=1;
}
}
namedWindow("Hist",WINDOW_AUTOSIZE);
imshow("Hist",MyHist);
thank u so much
You should use an array of
size=256
as values go from0
to255
(included).I guess your segmentation fault comes from this line:
MyHist.at<uchar>((255-numero),colonna)=255;
When
numero==0
,255-numero==255
but you have declared:Mat MyHist(255,255,CV_8U);
.If you are on Linux, gdb is a pretty useful tool for debugging.
Thank u so much Eduardo.
I changed the size and it is going well. Obvious the result isn't the same of the opencv function "calchist but the trand i think is similar.