Ask Your Question

Revision history [back]

Unexpected result when comparing sample image with database of images opencv c++

I am working on Image matching program, it captures image from IR camera stores it in one directory. A database of images exist in a different directory. I get an unexpected result while executing. I somehow realize that it's because I'm messing with different directories and something basic. Any help in getting around the mistake? Here's a snippet of the code.

Code:

VideoCapture cap(0);    
Mat frame;
Mat src, dst, tmp,img_3,img_4;

filename3 = (char *)malloc(sizeof(char));
printf("\n-------------------------------------------------\n");
printf("\nOne to Many Image matching with SURF Algorithm.\n");
printf("\n-------------------------------------------------\n");

//Get the Vein image from Webcam that needs to be compared with the database.
// The below function gets frame and saves it in /home/srikbaba/opencv/veins
veincnt = captureVein(veincnt, cap);
if(veincnt == -1)
     cout << "A problem has occured" << endl;
printf("\nPlease enter the filename of saved image with the extension.\n");
scanf("%s",filename3);
//Scan the directory for images.
DIR *dir;
struct dirent *ent;
clock_t tstart1 = clock(); //start clock function, do something!!!!
if ((dir = opendir ("/home/srikbaba/images")) != NULL) 
{
    /* print all the files and directories within directory */
    while ((ent = readdir (dir)) != NULL) 
    {
        if(ent->d_type!= DT_DIR)
        {
            //Print the images
            printf ("%s\n", ent->d_name);
            //Store the Filename
            img_db = ent->d_name;
            //Open each file name as Mat identifier and loop the process
            img_3 = imread (filename3, IMREAD_GRAYSCALE);

//Filename3 is saved in /home/srikbaba/opencv/veins --> different directory
// I feel this is the problem
                img_4 = imread (img_db, IMREAD_GRAYSCALE);
                if( !img_3.data)
                {
                    std::cout<< " --(!) Invalid filename or file not found! " << std::endl;
                    return -1;
                }

Because of this I always get --(!) Invalid filename or file not found message. Is there a way I can compare one image from a directory and another image from a different directory? I hope what I asked is not confusing. Kindly help.

Working on Opencv - C++ on Ubuntu 12.04 LTS