我使用這樣的功能;Findcontours()運行時錯誤
Mat large = imread(path+name);
Mat rgb;
if (large.rows > 2500 || large.cols > 1250)
{
pyrDown(large, rgb);
}
else
{
rgb = large.clone();
}
cv::Mat smallx;
cvtColor(rgb, smallx, CV_BGR2GRAY);
Mat grad,connected,bw;
Mat morphKernel = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
cv::morphologyEx(smallx, grad, MORPH_GRADIENT, morphKernel);
cv::threshold(grad, bw, 100, 255, THRESH_BINARY + THRESH_OTSU);
morphKernel = getStructuringElement(MORPH_RECT, Size(9, 1));
cv::morphologyEx(bw, connected, MORPH_CLOSE, morphKernel);
Mat mask = Mat::zeros(bw.size(), CV_8UC1);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
cv::findContours(connected, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
某些輸入圖像提示異常,當函數返回時,它拋出我 「_Mybase :: DEALLOCATE(_Ptr,_COUNT);」代碼塊在xmemory0類中。我必須抓住這種錯誤並防止這個過程發生意外的暫停
--------------錯誤的詳細信息--------------
我試着用30種不同的輸入代碼塊,但在一些圖像給了錯誤。在findcontours之後,它拋出一個異常中斷並向我顯示此消息。 0xC0000409:0xc0000409在 ImageRecognizer.exe在0x74477fb2(ucrtbase.dll)
未處理的異常。
那時,在我的Visual Studio中用這些行打開的「vector」類;
~vector() _NOEXCEPT
{ // destroy the object
_Tidy();
}
或「xmemory」class opening with these lines;
void deallocate(pointer _Ptr, size_type _Count)
{ // deallocate object at _Ptr, ignore size
_Mybase::deallocate(_Ptr, _Count);
}
好了,我已經試過沒有50000但在那個時候,我得到同樣的錯誤了更多的輸入初始化向量。無論如何,我知道這不是有用的解決方案,但我必須徹底解決這個錯誤。 –
嘗試沒有運行點(0,0) 並嘗試此重載方法 空隙CV :: findContours(InputOutputArray \t圖像,OutputArrayOfArrays \t輪廓,INT模式,INT方法,點偏移=點()) – hagor
我可以嘗試而不點,但我需要層次結構。我已經知道這個方法選項,但它對我的情況沒有用處。但是我要測試沒有點(0,0)。 –