How to Solve Vector Variable Error in sub thread

Once, when using an industrial camera for timing photo recognition, I encountered a situation: at that time, a sub thread was used for timing photo recognition, but after running, it was found that the error of memory overflow was reported when the sub thread was opened, resulting in the collapse of the program. After exclusion, it was found that the vector variable was used in the sub thread. After using the vector variable, the memory is not cleared, resulting in saving. You should use resize to clear the memory.

Program segment with error:

vector<Mat> channels;
split(imgRect, channels);
Mat img = channels.at(0);

Program segments that can operate normally after modification:

vector<Mat> channels;
split(imgRect, channels);
Mat img = channels.at(0);
channels.resize(0);

It is hereby recorded and shared

Read More: