assertion failed [closed]
I am using opencv for image processing, while comparing images by using command compareHist i am getting the following error:
OpenCV Error: Assertion failed (H1.type() == H2.type() && H1.type() == CV_32F) in compareHist, file /home/alishba/opencv-2.4.9/modules/imgproc/src/histogram.cpp, line 1985
terminate called after throwing an instance of 'cv::Exception'
what(): /home/alishba/opencv-2.4.9/modules/imgproc/src/histogram.cpp:1985: error: (-215) H1.type() == H2.type() && H1.type() == CV_32F in function compareHist
Aborted (core dumped)
int main()
{
string path="Finger Vein Database/";
int sets=5;
int learning =3;
int test=1;
//creating learning database
cout<<"creating DB\n";
//Mat database[sets*learning];
vector<Mat> database(sets*learning);
int counter=0;
for(int i=1;i<=sets;i++)
{
for(int j=1;j<=learning;j++)
{
stringstream ssm;
//string t1="%ss%d/1%d.bmp";
//sprintf(t1,path,i,j);
ssm<<path<<"s"<<i<<"/1"<<j<<".bmp";
string t1=ssm.str();
Mat im= imread(t1,0);
Mat hist=GetCompiledHistogram(im);
database[counter++]=hist;
t1="";
//im=&NULL;
//hist=&NULL;
}
}
counter=0;
//testing
cout<<"Testing started\n";
//Mat databaseTest[sets*test];
vector<Mat> databaseTest(sets*test);
for(int i=1;i<=sets;i++)
{
for(int j=learning+1;j<=test;j++)
{
stringstream ssm;
ssm<<path<<"s"<<i<<"/1"<<j<<".bmp";
string t1=ssm.str();
Mat im= imread(t1,0);
Mat hist=GetCompiledHistogram(im);
databaseTest[counter++]=hist;
t1="";
//im=NULL;
//hist=NULL;
}
}
int count=0;
//int maxX=sizeof(databaseTest)/sizeof(*databaseTest);
int maxX=databaseTest.size();
double out;
for(int x=0;x<maxX;x++)
{
//int maxY=sizeof(database)/sizeof(*database);
int maxY=database.size();
double results[maxY];
for(int y=0; y<maxY;y++)
{
cout<<x<<" "<<y<<"\n";
Mat h1=database[y];
Mat h2=databaseTest[x];
cout << typeid(h2).name() << '\n';
out=compareHist(h1,h2 , CV_COMP_CORREL);
results[y]=out;
}
int mached= MinIn(results,maxY);
if(ceil(mached/learning)==x)
count++;
}
int total =sets*test;
cout<<((total-count)/total);
return 0;
}
please append your code to the question
i have added my main code to the question
good ! next time, - there's a "10101" button to format code properly ;)
any suggestions on this ?????
error complains, that your histogram is not float. add a check like:
cerr << h1.type() << " " << h1.size() << endl;
(same for h2)