Unhandled Exception when using cv::resize(....) with 5 threads simultaneously
Using visual c++ (15.7.5 - 2017).
When using this line (by 5 threads) :
cv::resize(img_export_5, resized_img_export_5_ext, size, 0, 0, INTER_CUBIC);
I get this error frequently:
Unhandled Exception: System.Runtime.InteropServices.SEHException: External component has thrown an exception. at cv.resize(_InputArray* , _OutputArray* , Size_<int>* , Double , Double , Int32 ) at UFO.UFO_microscopy.Thread_export_5.ThreadEntryPoint() in c:\users\ufo\desktop\f7 cimg updated\ufo\ufo\ufo_microscopy.h:line 2402 at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
Here is the block where I get the error:
Mat img_export_1(4000, 8800, CV_8U, Scalar(0));
Mat resized_img_export_1_ext;
while (export_thread_1_cont)
{cv::Size size(calibrated_x_length_external, y_length_read_bin_file); cv::Size size_final(0, 0);
while (!export_frame_available_1)
{
if (!export_thread_1_cont) break;
// WAITS FOR FRAME
}
if (!export_thread_1_cont) break;
for (int width = 0; width < y_length_read_bin_file; width++)
{
for (int length = 0; length < samplesPerRecord_read_bin_file; length = length + 1)
{
avg = loaded_image_array_1[width][length];
mapped_value = ((avg - lower_limit[selected_channel_num]) / (contrast_calibration_ext[length] - lower_limit[selected_channel_num])) * 255;
img_export_1.at<uchar>(width, length) = mapped_value;
}
}
resize(img_export_1, resized_img_export_1_ext, size, 0, 0, INTER_CUBIC);
sprintf(export_file_name, "%s\\%d.bmp", export_directory_full, selected_frame_export_1);
imwrite(export_file_name, resized_img_export_1_ext);
export_frame_available_1 = false;
goto back_exp_1;
}
Note: When I use 4 threads, I get this error less frequently.
Please help me!!!!Please help me!!!Please help me!!!!
what made you think, it was threadsafe, ever ?
System.Threading
-- also, managed code here ?where the hell comes this from ?
(raw) pointers to
InputArray
, srsly ?link text
this yellow marked line is giving the error. Basically, i am reading a 2D matrix to form a Mat. And then, trying to resize that Mat. Resizing process gives error when more than 4 threads are used.
I understood the root cause of the problem. I declared lots of 2D arrays which already occupied large amount of RAM. When, I used more and more threads, it needed more & more memory to create the Mat object during resize operation dynamically. Since, my app is 32 bit, it crashes when memory requirement becomes more than ~2GB.
again, things you should NOT do here:
oh, it also has a
goto
. what a mess.