2015-05-28 43 views
1

我正在使用OpenCV 2.4.10版。使用Visual Studio 2013(C++)的OpenCV:findContours斷點錯誤

當我調試我得到斷點錯誤:wkernelbase.pdb不加載。

此外,我得到這個錯誤在Visual Studio中的輸出:

First-chance exception at 0x7543C42D in Perspective.exe: Microsoft C++ exception: cv::Exception at memory location 0x003FEDDC. 
Unhandled exception at 0x7543C42D in Perspective.exe: Microsoft C++ exception: cv::Exception at memory location 0x003FEDDC. 

在我的應用程序,在命令行打印了這一點:

OpenCV Error: Assertion failed <0 <= contourIdx< <int>last> in cv::drawContours, file...\..\..\..\opencv\imgproc\src\contours.cpp, line 1810 

任何建議,如何應對這個?這裏是我的代碼:

#include "opencv2/core/core.hpp" 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include "iostream" 

using namespace cv; 
using namespace std; 
int main() 
{ 
    Mat image; 
    image = imread("shape.jpg", 1); 
    namedWindow("Display window", CV_WINDOW_AUTOSIZE); 
    imshow("Display window", image); 
    Mat gray; 
    cvtColor(image, gray, CV_BGR2GRAY); 
    Canny(gray, gray, 100, 200, 3); 

    /// Find contours 
    vector<vector<Point> > contours; 
    vector<Vec4i> hierarchy; 
    RNG rng(12345); 
    findContours(gray, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); 
    /// Draw contours 
    Mat drawing = Mat::zeros(gray.size(), CV_8UC3); 
    for (int i = 0; i < contours.size(); i++) 
    { 
     Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); 
     drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point()); 
    } 

    imshow("Result window", drawing); 
    waitKey(0); 
    return 0; 
} 

我知道我的形象是在正確的目錄中。

+1

請再看看您正在鏈接的opencv庫。不要混合調試和釋放庫,或者在調試版本中使用版本庫或其他方式。 – berak

+0

嗨,貝拉克,感謝您的快速回復。我剛剛檢查過它們,並且使用了正確的庫(我目前正在通過調試來運行它)。 – futureLookingGrimm

+0

您是否鏈接到Visual Studio 2013庫。這些應該在vc12文件夾中。是vc12 = Visual Studio 2013. – drescherjm

回答

0

我試過你的代碼。

這個例子(可能)是沒有意義的,但你的代碼工作。

關於VC10,VC12 ......的整個事情可能會相當混亂。我的建議是嘗試遵循OpenCV HOWTO for Windows and Visual Studio。也許這樣你會解決你在問題中描述的問題(甚至找出錯誤)。

2

這是vs2013和OpenCV

嘗試與已知的兼容性問題與

vector<cv::Mat> coutours; 

,在我的工作的情況下更換

vector<vector<Point> > contours;