opencv轮廓检测之椭圆检测-----算法篇(1)

首先轮廓(contour)的定义?

       轮廓的定义有很多种,  也就是包围物体的边缘.  不管是哪种定义,  轮廓是与边缘紧密联系的. 那

那什么是边缘(edge)?

          Simple answer: discontinuities in intensity.

边缘的分类?

  1. Step edge
  2. Ramp edge
  3. Ridge edge
  4. Roof edge
边缘的描述?
    • Edge descriptors
        – Edge normal: unit vector in the direction of maximum intensity change.
        – Edge direction: unit vector along edge (perpendicular to edge normal).
        – Edge position or center: the image position at which the edge is located.
        – Edge strength or magnitude: local image contrast along the normal.

边缘的获取?
        1.Sobel 算子
#include <opencv2/opencv.hpp>
#include <iostream>
 
  
int main(int argc, char ** argv)
{
    if(argc < 2)
        return -1;
    cv::Mat img = cv::imread(argv[1],0);
    cv::Mat dst1 , dst2, dst3 ,dst;
    cv::GaussianBlur(img, img, cv::Size(5,5), 1.0, 1.0);// Smooth before Applying Derivative Operator!Or combine
                                                        // them together
    cv::Sobel(img,dst1,-1,1,0,1);
    cv::Sobel(img,dst2,-1,0,1,1);
    dst3 = dst1 + dst2;
    cv::Sobel(img,dst,-1,1,0,1);
    cv::Sobel(img,dst,-1,0,1,1);
 
  
 
  
    cv::namedWindow("dst1",cv::WINDOW_AUTOSIZE);
    cv::namedWindow("dst2",cv::WINDOW_AUTOSIZE);
 
  
    cv::namedWindow("dst3",cv::WINDOW_AUTOSIZE);
    cv::namedWindow("dst",cv::WINDOW_AUTOSIZE);
    cv::imshow("dst1",dst1);
    cv::imshow("dst2",dst2);
    cv::imshow("dst3",dst3);
    cv::imshow("dst",dst);
    for(;;)
    {
        if(cv::waitKey(0)==27)
            break;
 
  
    }
    return 0;
 
  
}
opencv轮廓检测之椭圆检测-----算法篇(1)_第1张图片
opencv轮廓检测之椭圆检测-----算法篇(1)_第2张图片
opencv轮廓检测之椭圆检测-----算法篇(1)_第3张图片


下面这段代码实际上与上面等价
只是上面程序中由于经验不足gaussian参数没有选好
#include <opencv2/opencv.hpp>
#include <iostream>
 
  
int main(int argc, char ** argv)
{
    if(argc < 2)
        return -1;
    cv::Mat img = cv::imread(argv[1],0);
    cv::Mat dst1 , dst2, dst3 ,dst;
//    cv::GaussianBlur(img, img, cv::Size(5,5), 1.0, 1.0);// Smooth before Applying Derivative Operator!Or combine
                                                        // them together
    cv::Sobel(img,dst1,-1,1,0,3);
    cv::Sobel(img,dst2,-1,0,1,3);
    dst3 = dst1 + dst2;
    cv::Sobel(img,dst,-1,1,1,3);
//    cv::Sobel(img,dst,-1,0,1,1);
 
  
 
  
    cv::namedWindow("dst1",cv::WINDOW_AUTOSIZE);
    cv::namedWindow("dst2",cv::WINDOW_AUTOSIZE);
 
  
    cv::namedWindow("dst3",cv::WINDOW_AUTOSIZE);
    cv::namedWindow("dst",cv::WINDOW_AUTOSIZE);
    cv::imshow("dst1",dst1);
    cv::imshow("dst2",dst2);
    cv::imshow("dst3",dst3);
    cv::imshow("dst",dst);
    for(;;)
    {
        if(cv::waitKey(0)==27)
            break;
 
  
    }
    return 0;
 
  
}
 
  
opencv轮廓检测之椭圆检测-----算法篇(1)_第4张图片opencv轮廓检测之椭圆检测-----算法篇(1)_第5张图片

你可能感兴趣的:(算法,opencv,轮廓检测,opencv2)