nothinglo / NISwGSP

C++ implementation of the ECCV 2016 paper, Natural Image Stitching with the Global Similarity Prior.
332 stars 124 forks source link

a runtime error #9

Closed yzsz closed 7 years ago

yzsz commented 7 years ago

I managed to compile and run on linux with gcc 6 but met a runtime error. The debugging feature pair and line result files were well generated, but not the stitching files. It was nothing wrong when processing some example images like AANAP-skyline and APAP-railtracks. But when I tried some other examples e.g. AANAP-roundabout, an OOM happened in MultiImages::textureMapping, at this line: Mat polygon_index_mask(rects[i].height + shift.y, rects[i].width + shift.x, CV_32SC1, Scalar::all(NO_GRID));

roundabout0 rect = [1.17309e+06 x 1.58113e+06 from (2.06305e+06, 1.13368e+06)] roundabout3 rect = [2.15131e+06 x 3.12946e+06 from (765193, 0)] roundabout1 rect = [1.88212e+06 x 1.3209e+06 from (952085, 1.66553e+06)] roundabout2 rect = [5.51731e+06 x 3.61797e+06 from (0, 36694.4)] OpenCV Error: Insufficient memory (Failed to allocate 7419210561064 bytes) in OutOfMemoryError, file /UglyMan_NISwGSP_Stitching/opencv-3.0.0/modules/core/src/alloc.cpp, line 52 OpenCV Error: Assertion failed (u != 0) in create, file /UglyMan_NISwGSP_Stitching/opencv-3.0.0/modules/core/src/matrix.cpp, line 411 terminate called after throwing an instance of 'cv::Exception' what(): /UglyMan_NISwGSP_Stitching/opencv-3.0.0/modules/core/src/matrix.cpp:411: error: (-215) u != 0 in function create

When processing APAP-garden, the output is: DSC02931 rect = [9153.74 x 7622.71 from (9500.55, 56574)] DSC02933 rect = [93026.5 x 130673 from (0, 0)] DSC02930 rect = [4716.9 x 4616.46 from (7974, 57841.4)] DSC02932 rect = [4582.3 x 5106.73 from (8343.71, 57186.2)] DSC02934 rect = [1329.46 x 1211.29 from (11132, 60498.9)] other errors are the same

I tried to debug and found if I comment these lines in MultiImages::getCameraParams, the program can run without error, but with a wrong result: if (!(*adjuster)(images_features, pairwise_matches, camera_params)) { printError("F(getCameraParams) camera parameters adjuster failed"); } It seems that when these codes executed, the value of one of camera_params's member becomes illegal. I'm not sure about this, but it might be useful.

nothinglo commented 7 years ago

Hi, I surmise the problem is due to the wrong index of each image in the *STITCH-GRAPH.txt.

In "AANAP-roundabout-STITCH-GRAPH.txt"

{center_image_index | 1 | center image index} {center_image_rotation_angle | 0 | center image rotation angle} {images_count | 4 | images count} {matching_graph_image_edges-0 | 1,3 | matching graph image edge 0} {matching_graph_image_edges-1 | 2,3 | matching graph image edge 1}

0 => roundabout0 image 1 => roundabout1 image 2 => roundabout2 image 3 => roundabout3 image

But the index is not consistent between your device and mine.

The reason is according to your output:

roundabout0 rect = [1.17309e+06 x 1.58113e+06 from (2.06305e+06, 1.13368e+06)] roundabout3 rect = [2.15131e+06 x 3.12946e+06 from (765193, 0)] roundabout1 rect = [1.88212e+06 x 1.3209e+06 from (952085, 1.66553e+06)] roundabout2 rect = [5.51731e+06 x 3.61797e+06 from (0, 36694.4)]

and mine:

roundabout0 rect = [855.777 x 566.812 from (0, 135.668)] roundabout1 rect = [859.329 x 578.347 from (541.454, 123.999)] roundabout2 rect = [906.457 x 610.837 from (939.36, 8.92342)] roundabout3 rect = [889.318 x 594.416 from (119.783, 0)]

Thus, I consider that if you correct the indices in the *STITCH-GRAPH.txt, then the problem will be solved. You can try it first and I will adjust my code to prevent this situation in different devices. However, I am quite busy recently. I hope I could fix it as soon as possible. Thanks!

yzsz commented 7 years ago

Thanks, I tried to use scandir instead of opendir+readdir and it works.

Liuzichi commented 5 years ago

Thanks, I tried to use scandir instead of opendir+readdir and it works. What do you change for fix this bug?