Monday, March 15, 2010

A small bug in "Camera Calibration Toolbox for Matlab"

Today, when I use the toolbox for calibration, it gives a error :
"
??? Error using ==> eq
Matrix dimensions must agree.

Error in ==> loadpgm at 68
elseif ~any(c == white)

"

The images is PGM format. These errors come from "loadpgm.m" file. I find that when the error happens, the c is empty, which means the reader pointer is getting the end of file.

In the "loadpgm.m" file, the program likes:
"
maxval = fscanf(fid, '%d', 1);
while 1
c = fread(fid,1,'char');
if c == '#',
fgetl(fid);
elseif ~any(c == white)
fseek(fid, -1, 'cof'); % unputc()
break;
end
end

"

The program read maxval correctly, so it is going on and checking next value, if it's '#' or says 35, then the program will read a row line. What happens here, the interesting thing is the first image data value is 35, which is not '#', but just a interger value 35. The program "think" it's '#', and get the whole line which contain all image data, so next time ,it finds it goes to end of file.

I change the first image data to 36, then it works very well. The matlab function imread works well here for this special case.