Ask Your Question
0

Problem accessing Mat

asked 2013-07-14 12:03:47 -0600

updated 2013-07-14 13:21:30 -0600

Hi,

I'm writing a simple program that extracts descriptors from images and writes them to files.

I'm saving the descriptors in a Mat variable, but I'm getting wrong values when trying to access them.

Here is the code:

            string s = format("%s\\%s\\img%d.ppm", dataset_dir.c_str(), dsname, k);
            Mat imgK = imread(s, 0);
            if( imgK.empty() )
                break;

            detector->detect(imgK, kp);
            descriptor->compute(imgK, kp, desc);

            //writing the descriptors to a file
            char fileName[512];
            sprintf(fileName,"C:\\BinaryDescriptors\\OpenCVRes\\%s\\%s\\Descriptors%d.txt",descriptor_name,dsname,k);
            FILE * fid;
            fid=fopen(fileName,"a+");
            for (int ix=0; ix< kp.size(); ix++){

                fprintf(fid,"%f \t%f", kp[ix].pt.x,kp[ix].pt.y);
                fprintf(fid, "\t1 \t0 \t1");
                fflush(fid);
                //writing the descriptor
                for (int jx=0;jx<desc.cols;jx++){
                    int gil = desc.at<int>(ix,jx);
                    printf("AAAA %d", gil);
                    fprintf(fid,"\t%d",desc.at<int>(ix,jx));
                    fflush(fid);
                }
            }
            fprintf(fid,"\n");
            fclose(fid);

The line where I'm accessing the descriptors matrix is int gil = desc.at int(ix,jx); Is there something I'm doing wrong?

Any help will be greatly appreciated, as I'm quite stuck :)

Thanks,

Gil.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-07-14 15:08:20 -0600

berak gravatar image

"The line where I'm accessing the descriptors matrix is int gil = desc.at<int>(ix,jx); Is there something I'm doing wrong?"

no idea, what kind of descriptor you're using, but it's type is definitely not int.

some of them are float ( SIFT,SURF ), others are uchar

edit flag offensive delete link more

Comments

Thank you for your help!

GilLevi gravatar imageGilLevi ( 2013-07-16 11:05:24 -0600 )edit
1

answered 2013-07-14 16:35:17 -0600

Notas gravatar image

Don't mix C++ and C! I'm getting nightmares seeing all that mixup... First search if OpenCV provides functionality that you want to use. In this case, look at FileStorage.

edit flag offensive delete link more

Comments

You are correct, but this isn't related to his question. He actually has problems acessing his data, because he uses the wrong pointer type at the .at<type>(x,y) operator like @berak already mentioned. So please try to focus answers specific to the question.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-15 06:06:17 -0600 )edit

Question Tools

Stats

Asked: 2013-07-14 12:03:47 -0600

Seen: 340 times

Last updated: Jul 14 '13