2016-01-20 96 views
0

我在Visual Studio 2015中运行canny边缘示例,并且出现此错误。当在Visual Studio 2015中运行Opencv示例时出现应用程序错误(0xc000007b)

应用程序无法正确启动(0xc000007b)。

然后visual studio显示这个错误。

Canny Edge.exe中的0x77A2D5B2(ntdll.dll)未处理的异常:0xC000007B:%hs不是设计为在Windows上运行,或者它包含错误。尝试使用原始安装介质重新安装程序,或与系统管理员或软件供应商联系以获得支持。错误状态0x。

我很确定这个编码工作,因为我在Visual Studio 2013中运行此编码之前。这是我的编码。

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

#include <iostream> 
#include <algorithm> 

using namespace cv; 
using namespace std; 

void help() 
{ 
    cout << "\nThis program demonstrates line finding with the Hough transform.\n" 
     "Usage:\n" 
     "./houghlines <image_name>, Default is pic1.jpg\n" << endl; 
} 

bool less_by_y(const cv::Point& lhs, const cv::Point& rhs) 
{ 
    return lhs.y < rhs.y; 
} 

int main(int argc, char** argv) 
{ 
    const char* filename = argc >= 2 ? argv[1] : "pic1.jpg"; 

    vector<vector<Point> > contours; 
    vector<Vec4i> hierarchy; 
    Rect roi; 

    Mat src = imread("test_4_1.png"); 
    if (src.empty()) 
    { 
     help(); 
     cout << "can not open " << filename << endl; 
     return -1; 
    } 

    Mat dst, cdst; 
    Canny(src, dst, 50, 200, 3); 
    cvtColor(dst, cdst, CV_GRAY2BGR); 
    findContours(dst, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); 

    //vector<Vec2f> lines; 
    //HoughLines(dst, lines, 1, CV_PI/180, 50, 0, 0); 

    //for (size_t i = 0; i < lines.size(); i++) 
    //{ 
    // float rho = lines[i][0], theta = lines[i][1]; 
    // Point pt1, pt2; 
    // double a = cos(theta), b = sin(theta); 
    // double x0 = a*rho, y0 = b*rho; 
    // pt1.x = cvRound(x0 + 1000 * (-b)); 
    // pt1.y = cvRound(y0 + 1000 * (a)); 
    // pt2.x = cvRound(x0 - 1000 * (-b)); 
    // pt2.y = cvRound(y0 - 1000 * (a)); 
    // line(cdst, pt1, pt2, Scalar(0, 0, 255), 1, CV_AA); 
    // cout << pt1 << " " << pt2 << endl; 
    //} 

    vector<Vec4i> lines; 
    HoughLinesP(dst, lines, 1, CV_PI/180, 30, 50, 10); 
    for (size_t i = 0; i < lines.size(); i++) 
    { 
     Vec4i l = lines[i]; 
     line(cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 1, CV_AA); 
     cout << l << endl; 
    } 

    cout << endl << lines.size() << endl; 
    cout << arcLength(contours[0], true) << endl; 
    cout << dst.size() << endl << endl; 

    for (int a = 0; a < contours[0].size(); a++){ 
     cout << contours[0][a] << " "; 
    } 

    vector<Point> test = contours[0]; 
    auto mmx = std::minmax_element(test.begin(), test.end(), less_by_y); 
    cout << endl << *mmx.first._Ptr << endl << *mmx.second._Ptr; 

    vector<Point> test2 = contours[1]; 
    auto mmx_1 = std::minmax_element(test2.begin(), test2.end(), less_by_y); 
    cout << endl << *mmx_1.first._Ptr << endl << *mmx_1.second._Ptr; 

    imshow("source", src); 
    imshow("detected lines", cdst); 

    /* ROI by creating mask for the parallelogram */ 
    Mat mask = cvCreateMat(dst.size().height, dst.size().width, CV_8UC1); 
    // Create black image with the same size as the original 
    for (int i = 0; i < mask.cols; i++) 
     for (int j = 0; j < mask.rows; j++) 
      mask.at<uchar>(Point(i, j)) = 0; 

    cout <<endl<<endl<< *mmx.first._Ptr << *mmx.second._Ptr << *mmx_1.first._Ptr << *mmx_1.second._Ptr << endl; 

    // Create Polygon from vertices 
    vector<Point> ROI_Vertices = { *mmx.first._Ptr, *mmx.second._Ptr, *mmx_1.first._Ptr, *mmx_1.second._Ptr}; 

    vector<Point> ROI_Poly; 
    approxPolyDP(ROI_Vertices, ROI_Poly, 1.0, false); 

    // Fill polygon white 
    fillConvexPoly(mask, &ROI_Poly[0], ROI_Poly.size(), 255, 8, 0); 
    cout << ROI_Poly.size() << endl; 

    // Create new image for result storage 
    Mat imageDest = cvCreateMat(dst.size().height, dst.size().width, CV_8UC3); 

    // Cut out ROI and store it in imageDest 
    src.copyTo(imageDest, mask); 

    imshow("mask", mask); 
    imshow("image", imageDest); 

    waitKey(); 

    return 0; 
} 
+0

你链接到什么OpenCV库?你链接到vs12吗?因为您需要将链接器升级到VS13,因为MSVS 2015 – GPPK

回答

2

其实我的意见是答案,添加了一些新

OpenCV的利布斯你链接到什么?你链接到vs12吗?因为 你需要你的连接器升级到vs13为MSVS 2015年

OpenCV的不来与Visual Studio 15的预构建,所以你需要自己构建OpenCV进行VS2015

This person似乎有一个类似的问题,并告诉你如何编译VS2015

+0

非常感谢! – SamTew

相关问题