line_detector icon indicating copy to clipboard operation
line_detector copied to clipboard

memory error

Open ArsenLuca opened this issue 6 years ago • 8 comments

When I use the following image as input, the algorithm meets with a memory error in function int EDLineDetector::EDline(image_int8u_p image, LineChains &lines, bool smoothed) It seems to be a memory out of range error. @frotms Could you please have a try and resolve the problem? 2

ArsenLuca avatar Jul 04 '18 11:07 ArsenLuca

@ArsenLuca , What is the error info?

frotms avatar Jul 04 '18 11:07 frotms

@frotms In Linux Eclipse C++ IDE, it shows: malloc(): memory corruption(fast): 0x0000000002145150 *** In Visual Studio IDE, it shows error in delete function or sometimes malloc function.

ArsenLuca avatar Jul 04 '18 12:07 ArsenLuca

@frotms you can have a try using the image above

ArsenLuca avatar Jul 04 '18 12:07 ArsenLuca

In windows VS, it shows image

ArsenLuca avatar Jul 04 '18 12:07 ArsenLuca

@frotms Also, in each run, different errors happen. In one run, it happens that:

for (unsigned int lineID = 0; lineID < numOfFinalLine; lineID++){ lineIDInScaled = scaledLines[lineID].lineIDInScaled; direction = edLineVec_[ZERO]->lineDirection_[lineIDInScaled]; singleLine.scaledCount = ZERO; singleLine.direction = direction; singleLine.lineLength = scaledLines[lineID].lineLength; singleLine.salience = edLineVec_[ZERO]->lineSalience_[lineIDInScaled]; singleLine.numOfPixels = edLineVec_[ZERO]->lines_.sId[lineIDInScaled + 1] - edLineVec_[ZERO]->lines_.sId[lineIDInScaled];

edLineVec_[ZERO]->lines_.sId has a size of 40, while lineIDInScaled is 39. So edLineVec_[ZERO]->lines_.sId[lineIDInScaled + 1] is out of range.

ArsenLuca avatar Jul 04 '18 12:07 ArsenLuca

I'll try later @ArsenLuca

frotms avatar Jul 04 '18 12:07 frotms

@frotms I first resize the image to 640*640 and debug the codes. It comes that in the following line: lines.sId.resize(5 * edges.numOfEdges); edges.numOfEdges is 8. so edLineVec_[ZERO]->lines_.sId has the size of 40.

while in: for (unsigned int lineID = 0; lineID < numOfFinalLine; lineID++){ lineIDInScaled = scaledLines[lineID].lineIDInScaled; direction = edLineVec_[ZERO]->lineDirection_[lineIDInScaled]; singleLine.scaledCount = ZERO; singleLine.direction = direction; singleLine.lineLength = scaledLines[lineID].lineLength; singleLine.salience = edLineVec_[ZERO]->lineSalience_[lineIDInScaled]; singleLine.numOfPixels = edLineVec_[ZERO]->lines_.sId[lineIDInScaled + 1] - edLineVec_[ZERO]->lines_.sId[lineIDInScaled]; numOfFinalLine is 93, So when the loop comes at lineID == 39, lineIDInScaled is also 39, So edLineVec_[ZERO]->lines_.sId[lineIDInScaled + 1] is out of range. I think lineIDInScaled+1 should be less than 5 * edges.numOfEdges and I don't know exactly why when using this image, 5 * edges.numOfEdges can be equal to lineIDInScaled+1

ArsenLuca avatar Jul 04 '18 12:07 ArsenLuca

@frotms It seems that the problem is due to 5 * edges.numOfEdges is not enough for numOfFinalLine. So why do you set the constant multiplier to be 5? And how to control 5 * edges.numOfEdges is larger than numOfFinalLine?

ArsenLuca avatar Jul 05 '18 02:07 ArsenLuca