kamino410 / procam-calibration

A calibration software for projector-camera system using chessboard and structured light patterns.
MIT License
122 stars 37 forks source link

!Error : chessboard was not found in anf gc_filenames[-2]! #17

Closed hypatiash closed 4 months ago

hypatiash commented 5 months ago

Hi, Firstly thanks for your contribution but I desperately need help. I try the sample_data in the code and it works, and I captured my own images and named them as capture_0, .. capture_4 same as in sample_data naming and also images were named as graycode_00 etc. Then I run the code according to me python calibrate.py 800 1280 9 7 47 3 and I got the error Error : chessboard was not found in '.\capture_0\graycode_36.jpg' so I replaced the graycode_36 with some verified image (for example graycode_25) and I ran the code again but I got the same error. Then, I replaced whole capture_0 with the sample_data capture_0 (of course I eliminated necesary number of images accoring to me) and I still got the same error. So I know that my captured images are not the problem here. Then I realized res, cam_corners = cv2.findChessboardCorners(white_img, chess_shape) if not res: print('Error : chessboard was not found in \'' + gc_filenames[-2] + '\'') return None cam_objps_list.append(objps) cam_corners_list.append(cam_corners)

in the above code in gc_filenmaes[-2] error always turns back to second to last picture no matter what. When I change the inside of the gc_filnames[-2] to [-10] this time I got Error : chessboard was not found in '.\capture_0\graycode_28.jpg' which is last to 10th picture considering I have total 38 pictures. I dont understand why this happens because it works with sample data but it does not work with me. Again, I switched sample data capture_0 folder with mine according to number of images etc. but I still got the error. At this point I dont know what to do.

kbarkevich commented 4 months ago

So, it seems like the algorithm is trying to establish a baseline chessboard pattern by looking at the image with total illumination (the "white_img", which is the second to last pattern generated). However, on Windows at least, the way the array containing the filenames (gc_fname_lists) is sorted is not correct, and did not result in the correct image being the second-to-last one.

I fixed this issue by changing the for loop in calibrate.py's calibrate() function from

    for dname, gc_filenames in zip(dirnames, gc_fname_lists):

to

    new_gc_fname_lists = [sorted(gc_fname_lists[i], key=lambda x: int(x[x.rindex('_')+1:x.rindex('.')])) for i in range(len(gc_fname_lists))]

    for dname, gc_filenames in zip(dirnames, new_gc_fname_lists):

and then the correct image is consistently selected.

hypatiash commented 4 months ago

Thank you so much for your reply! :) It did work out for me.