c++ - OpenCV findContours


i have c++ project using qt 5.1.1 , opencv 2.4.6. image processing algorithm runs in separate thread. works fine if call opencv function findcontours() program crashes stack overflow message (right in first time function called, not called several times before) "unhandled exception @ 0x56ec9a47 in sara.exe: 0xc00000fd: stack overflow."

i found same problem in case matter of changing project visual studio 2010...but in case, project in vs2010.

the algoritm runs fine if create separate console project, calls image processing algorithm, same code inside thread in qt project show stack overflow! if remove findcontours() function, woks should. in both projects use same libs , debug dlls (versioned xxx246d.dll), , compiling program debug.

i tried make stack larger changing properties -> configuration properties -> linker -> system -> stack reserve size option, program still crashes, different message, saying "unhandled exception @ 0x76e5c41f in sara.exe: microsoft c++ exception: concurrency::scheduler_resource_allocation_error @ memory location 0x14c7adc8.."

i don't think it's code problem, since runs fine console aplication, if wants see it, goes as:

qimage saravisualcontrol::findcircles(void)  { mat imginput = imread("m:/desktop/pseyeright1.jpg", cv_load_image_color);   mat roiinput(imginput, rect(point(205, 72), point(419,285))); mat imgcontours = roiinput.clone();  cvtcolor(imgcontours, imgcontours, cv_bgr2gray);  gaussianblur(imgcontours, imgcontours, size(3, 3), 0, 0, 4);             threshold(imgcontours, imgcontours, 150, 255, thresh_binary); // ou ler o otsu uma vez e usar ele  vector<vector<point> > contours; vector<vec4i> hierarchy;      findcontours(imgcontours, contours, hierarchy, cv_retr_list, cv_chain_approx_none, point(0, 0)); // program crashes here!  vector<rotatedrect> ellipses; rotatedrect ellipse;  for(int = 0; < contours.size(); i++) {     if(contours[i].size() >= 5)     {         ellipse = fitellipse(contours[i]);            ellipses.push_back(ellipse);     }     else     {         point2f center;         float radius = 0.0;         minenclosingcircle(contours[i], center, radius);         ellipses.push_back(rotatedrect(center, size2f(radius, radius), 0.0));     } }  cvtcolor(imgcontours, roiinput, cv_gray2bgr);   int baseline = 0; const double fontscale = 0.5; const int thickness = 1;     for(int = 0; < ellipses.size(); i++) {             cv::ellipse(roiinput, ellipses[i], cv_rgb(255, 0, 0), 1, 8);     size textsize = gettextsize(std::to_string((long long)i + 1), font_hershey_script_simplex, fontscale, thickness, &baseline);      puttext(roiinput, std::to_string((long long)i + 1), point(ellipses[i].center.x - (textsize.width/2), ellipses[i].center.y + (textsize.height/2)), font_hershey_script_simplex, fontscale,          scalar(255, 255, 255), thickness, 8, false);          }       return qimage((uchar*)roiinput.data, roiinput.cols, roiinput.rows, qimage::format_rgb32); } 

i faced similar situation today opencv 2.4.8 while building debug project on qt creator 3.1.2 using using msvc 2013 compiler.

suddenly, noticed .pro file linking application opencv release libraries:

libs += -l"c:\\opencv\\build\\x86\\vc12\\lib" \     -lopencv_core248 \     -lopencv_highgui248 \     -lopencv_imgproc248 

when should in fact, linking opencv debug libraries:

libs += -l"c:\\opencv\\build\\x86\\vc12\\lib" \     -lopencv_core248d \     -lopencv_highgui248d \     -lopencv_imgproc248d 

remember kids: project build type should match opencv libraries type.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -