findContours异常问题(opencv3.1+vs2013)

1. VS2013环境配置

1.1 配置opencv3.1环境

      1)配置包含目录和库目录

       

      2)配置opencv依赖库

      

1.2 opencv3.1运行模式配置

     配置运行库:

     1)外部连接依赖为:opencv_world310.lib:(Release模式)

          则运行库配置为/MT或/MD才能正常工作

     2)  外部连接依赖为:opencv_world310d.lib:(Debug模式)

          则运行库配置为/MTd或/MDd才能正常工作

     

     MT:MultiThread(static link)     ibcmt.lib
     MD:MultiThread(dynamic link)    msvert.lib

2. 示例代码

#include <opencv2/opencv.hpp>
#include <iostream>
struct Component
{
    cv::Rect boundingBox;
    double area;
    double circularity;
};
int main()
{
    // Create a small image with a circle in it.
    cv::Mat image(256, 256, CV_8UC3, cv::Scalar(0, 0, 0));
    cv::circle(image, cv::Point(80, 110), 42, cv::Scalar(255,127, 63), -1);

    // Find canny edges.
    cv::Mat cannyEdges;
    cv::Canny(image, cannyEdges, 80, 60);

    // Show the images.
    cv::imshow("img", image);
    cv::imshow("cannyEdges", cannyEdges);

    // Find the contours in the canny image.
    cv::vector<cv::Vec4i> hierarchy;

    // "Each contour is stored as a vector of points."
    // http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours
    typedef cv::vector<cv::vector<cv::Point> > TContours;
    TContours contours;
    cv::findContours(cannyEdges, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE);
    // cannyEdges is destroyed after calling cv::findContours

    // Print number of found contours.
    std::cout << "Found " << contours.size() << " contours." << std::endl;

    // Convert contours to Components.
    typedef cv::vector<Component> TComponents;
    TComponents components;
    for (TContours::const_iterator it( contours.begin() ); it != contours.end(); ++it)
    {
        Component c;
        c.area = cv::contourArea(*it);
        c.boundingBox = cv::boundingRect(*it);
        c.circularity = 0.0; // Insert whatever you mean by circularity;
        components.push_back(c);
    }

    for (TComponents::const_iterator it( components.begin() ); it != components.end(); ++it)
        std::cout << it->area << std::endl; // and whatever you want.

    // Wait for user input.
    cv::waitKey();
}

3. 出错原因

    1) VS版本与OpenCV VS版本不匹配

    2) Opencv与Debug与Release与VS工程的配置不一致


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值