gaoxiang12 / slambook2

edition 2 of the slambook
MIT License
5.39k stars 2k forks source link

CH7 在运行orb_self时提示Segmentation Fault #256

Open smallrain777 opened 1 year ago

smallrain777 commented 1 year ago

$ ./orb_self Segmentation fault

尝试通过ulimit修改stack size为100M但是仍然没有解决

howardchina commented 1 year ago

hey, I solve this problem by locate the bug in this line! https://github.com/gaoxiang12/slambook2/blob/f522131fadae7e7ec1a09f18873bc65369cdd073/ch7/orb_self.cpp#L384 the coordinates of point pp and qq can be negative value, so the img.at() crash.

I solve this by simply assign all the negative coordinate values to zeros like this before calling img.at():

if (pp.y < 0){pp.y = 0;}
if (pp.x < 0){pp.x = 0;}
if (qq.y < 0){qq.y = 0;}
if (qq.x < 0){qq.x = 0;}

if (img.at<uchar>(pp.y, pp.x) < img.at<uchar>(qq.y, qq.x)) {
smallrain777 commented 1 year ago

Thanks so much!