我是使用 VS2012 和 openCV 完成我的 FYP 的新手,我必须使用 Contours 检测人体(对象检测)。我已经成功安装了(VS2012 和 openCV),并且一直在做一些基本的图像处理,除了逻辑或句法之外没有任何未知问题,直到我遇到使用我现在被拘留的 findContours 函数。我的问题是:
当我不使用与 Contour 相关的东西时,即 findContours , drawContours,通过评论它,一切都很好,我可以使用 trackbar 来扩大/侵蚀图像,但是一旦我使用 Contour 相关的东西并按“F5”,图像显示检测到的对象周围的轮廓与断点一起显示 Program.exe 已触发断点,因此我无法进一步使用它。
为方便起见,以下是堆栈跟踪中的列表:
注意 1:我已按照pbrandoli给出的说明进行操作 ,但在通过 Microsoft 符号服务器加载未突出显示的“ntdll.dll 和 msvcr”后,在重新启动 (Cntrl+Shift+F5) 或调试(F5) 时会突出显示并再次获得未突出显示表示它丢失。
注2:为方便起见,我已经简明了列表。
ntdll.dll!77ca5204() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!77c6fbae() Unknown
ntdll.dll!77c02b04() Unknown
KernelBase.dll!75ff7e27() Unknown
> msvcr110d.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036 C++
msvcr110d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322 C++
msvcr110d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 C++
msvcr110d.dll!operator delete(void * pUserData) Line 54 C++
binaryFrame.exe!std::allocator<cv::Point_<int> >::deallocate(cv::Point_<int> * _Ptr,
unsigned int __formal) Line 586 C++
binaryFrame.exe!std::_Wrap_alloc<std::allocator<cv::Point_<int> >
>::deallocate(cv::Point_<int> * _Ptr, unsigned int _Count) Line 888 C++
binaryFrame.exe!std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >::_Tidy()
binaryFrame.exe!showBinImage() Line 66 C++
binaryFrame.exe!main(int __formal, char * * argv) Line 21 C++
binaryFrame.exe!__tmainCRTStartup() Line 536 C
binaryFrame.exe!mainCRTStartup() Line 377 C
kernel32.dll!763e1154() Unknown
ntdll.dll!77c3b299() Unknown
ntdll.dll!77c3b26c() Unknown
以下是我在图像中用于轮廓检测的代码:
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
void showBinImage();
int val=2;
int main( int, char** argv )
{
showBinImage();
return 0;
}
void showBinImage(){
Mat bin;
Mat im_gray;
Mat im_rgb = imread("nk5.jpg");
// Trackbar
namedWindow("ErodedImage",1);
createTrackbar("Erode", "ErodedImage", &val, 50);
cvtColor(im_rgb, im_gray,CV_RGB2GRAY);
threshold(im_gray, bin, 128.0, 255.0, THRESH_BINARY_INV);
//imwrite("bnasir.jpg", img_bw);
namedWindow("Binary",1);
imshow("Binary", bin);
while (true)
{
Mat erodeElement = getStructuringElement( MORPH_CROSS,Size(val*3,val*3));
Mat dilateElement = getStructuringElement( MORPH_RECT,Size(val*8,val*8));
Mat eroded; // the destination image
erode(bin,eroded,erodeElement+50);
dilate(eroded,eroded,dilateElement);
std::vector<std::vector<cv::Point>> contours;
findContours(eroded, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
// Draw black contours on a white image
Mat result(eroded.size(),CV_8U,cv::Scalar(255));
drawContours(result,contours,-1, cv::Scalar(0), 2); // with a thickness of 2
imshow("ErodedImage",(eroded));
waitKey(10);
}
}