【问题标题】:Application error(0xc000007b) when runnning Opencv example in Visual Studio 2015在 Visual Studio 2015 中运行 Opencv 示例时应用程序错误 (0xc000007b)
【发布时间】:2016-01-20 04:04:08
【问题描述】:

我在 Visual Studio 2015 中运行 canny edge 示例,但出现此错误。

应用程序无法正确启动 (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;
}

【问题讨论】:

  • 您链接到哪些 OpenCV 库?你链接到vs12吗?因为您需要将链接器升级到 MSVS 2015 的 vs13

标签: opencv visual-studio-2015


【解决方案1】:

其实我的评论就是答案,还有一些补充

您链接到哪些 OpenCV 库?你链接到vs12吗?因为 您需要将链接器升级到 MSVS 2015 的 vs13

OpenCV 不附带 Visual Studio 15 预构建,因此您需要为 VS2015 自己构建 OpenCV

This person 似乎也遇到过类似的问题,教你如何编译 VS2015

【讨论】:

  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多