美文网首页
轮廓发现

轮廓发现

作者: samychen | 来源:发表于2018-02-24 14:29 被阅读0次

轮廓发现

  轮廓发现是基于图像边缘提取的基础寻找对象轮廓的方法,所以边缘提取的阈值选定会影响最终轮廓发现结果。
相关API:
findContours发现轮廓
drawContours绘制轮廓

操作步骤:

  • 输入图像转为灰度图像
  • 使用Canny进行边缘提取,得到二值图像
  • 使用findContours寻找轮廓
  • 使用drawContours绘制轮廓
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <math.h>
using namespace cv;
using namespace std;
void contours(int, void *);
int thread_value = 100;
int thread_max = 255;
RNG rng;
int main(int argc, int ** argv)
{
    src = imread("F:/circle.png");
    if (!src.data) {
        printf("无法加载图片\n");
        return -1;
    }
    namedWindow("input img", CV_WINDOW_AUTOSIZE);
    namedWindow("output img", CV_WINDOW_AUTOSIZE);
    
    cvtColor(src, src, CV_BGR2GRAY);
    imshow("input img", src);
    const char* title = "thread value";
    createTrackbar(title, "output img", &thread_value, thread_max, contours);
    contours(0, 0);
    waitKey(0);
    return 0;
}
void contours(int, void *)
{
    vector<vector<Point>> contours;
    vector<Vec4i> hierarchy;
    Canny(src, dst, thread_value, thread_value * 2, 3, false);
    findContours(dst, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
    Mat drawImg = Mat::zeros(dst.size(), CV_8UC3);
    for (size_t i = 0; i < contours.size(); i++)
    {
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        drawContours(drawImg, contours, i, color, 2, LINE_8, hierarchy, 0, Point(0, 0));
    }
    imshow("output img", drawImg);
}
阈值100.png
阈值204.png

相关文章

  • 轮廓发现

    轮廓发现   轮廓发现是基于图像边缘提取的基础寻找对象轮廓的方法,所以边缘提取的阈值选定会影响最终轮廓发现结果。相...

  • findContours(轮廓发现)

    概念 对于图像中的物体寻找轮廓(外围或全部),这里使用OpenCV里的findContours进行提取,并结合dr...

  • 20、轮廓发现

    轮廓填充 基于Canny边缘提取

  • 028-Opencv笔记-轮廓发现

    轮廓发现 轮廓发现是基于图像边缘提取的基础寻找对象轮廓的方法。所以边缘提取的阈值选定会影响最终轮廓发现结果API介...

  • opencv+python -- 轮廓发现

    轮廓发现是基于图像边缘提取的基础寻找对象轮廓的方法,所以边缘提取的阈值选定会影响最终轮廓发现结果 Code 运行结...

  • Android智能识别 - 银行卡区域裁剪(原理篇)

    在 Android智能识别 - 银行卡区域裁剪 一文中我们用了如下几行代码,获取发现银行卡的轮廓: 轮廓发现是图像...

  • Android智能识别 - 银行卡区域裁剪(原理篇)

    在 Android智能识别 - 银行卡区域裁剪 一文中我们用了如下几行代码,获取发现银行卡的轮廓: 轮廓发现是图像...

  • 轮廓

    随手翻了一下近两个月写的文字,五花八门,奇形怪状。有点像间歇性精神病人,更像跳跃不定的心电图,一惊一乍,没个谱。有...

  • 轮廓

    我们相拥的地方变得凄凉,星光璀璨的夜空不再明亮,雨后的烟雾更加荒诞,夜晚的公园让人害怕。在凌晨两点的马路,我点燃...

  • 轮廓

    脸蛋的轮廓一开始是圆润的 后来消瘦,下巴是尖的 最终,是融化的黄油块 塌掉的胶原蛋白在时光的照片里 安详地枕着岁月匆忙

网友评论

      本文标题:轮廓发现

      本文链接:https://www.haomeiwen.com/subject/vwrstftx.html