assertion failed [closed]

asked 2015-11-05 11:44:17 -0600

alishba gravatar image

updated 2015-11-05 12:52:03 -0600

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;
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-07 08:13:32.819313

Comments

1

please append your code to the question

berak gravatar imageberak ( 2015-11-05 12:01:31 -0600 )edit

i have added my main code to the question

alishba gravatar imagealishba ( 2015-11-05 12:37:45 -0600 )edit

good ! next time, - there's a "10101" button to format code properly ;)

berak gravatar imageberak ( 2015-11-05 12:40:00 -0600 )edit

any suggestions on this ?????

alishba gravatar imagealishba ( 2015-11-05 13:08:04 -0600 )edit

error complains, that your histogram is not float. add a check like:

cerr << h1.type() << " " << h1.size() << endl; (same for h2)

berak gravatar imageberak ( 2015-11-06 00:13:12 -0600 )edit