I tried to draw 10 * 10 matrix on a video frame and here is the drawing function:
void AddMatrixToVideo::process(cv::Mat &videoFrameInput)
{
int MatrixStartPointX = 0;
int MatrixStartPointY = 0;
int m,n;
for(int i = 0; i < matrixNumInRow; ++i) {
for(int j = 0; j < matrixNumInColm; ++j) {
//draw horizontal line
for(m = MatrixStartPointX; m < MatrixStartPointX + matrixWidth; ++m) {
processGrayFrame(m,MatrixStartPointY,videoFrameInput);
processGrayFrame(m,MatrixStartPointY + matrixHeight,videoFrameInput);
}
//draw vertical line
for(n = MatrixStartPointY; n < MatrixStartPointY + matrixHeight; ++n) {
// processGrayFrame(MatrixStartPointX,n,videoFrameInput);
// processGrayFrame(MatrixStartPointX + matrixWidth,n,videoFrameInput);
}
MatrixStartPointX += matrixWidth;
}
MatrixStartPointX = 0;
MatrixStartPointY += matrixHeight;
}
}
Here is the processGrayFrame():
void AddMatrixToVideo::processGrayFrame(int x,int y,cv::Mat &videoFrameInput)
{
videoFrameInput.at<uchar>(y,x) = 255;
}
After running the program, it seems that the drawing progress works the memory usage keeps increasing and finally run out of memory. If I comment the processGrameFrame() function, the memory problem goes(of course it won't draw lines any more). So my question is why does the assigning operation cause the memory leak problem?
output. (if you change it, others/you later won't get confused)