zoukankan      html  css  js  c++  java
  • 图像边缘检测,sobel,scharr

    #include <opencv2/opencv.hpp>
    #include <iostream>
    #include <math.h>
    using namespace cv;
    using namespace std;
    
    Mat src, dst,dst2,gray_src;
    char* INPUT_WIN = "input image";
    char* OUTPUT_WIN = "binary image";
    int threshold_value = 127;
    int threshold_max = 255;
    int type_value = 2;
    int type_max = 4;
    
    
    int main()
    {
    
        src = imread(".//pic//kate.png");
    
        namedWindow(INPUT_WIN, CV_WINDOW_AUTOSIZE);
        namedWindow(OUTPUT_WIN, CV_WINDOW_AUTOSIZE);
        imshow(INPUT_WIN, src);
        
        GaussianBlur(src, dst, Size(3, 3), 0, 0);
        Mat gray_src;
        cvtColor(dst, gray_src, CV_BGR2GRAY); 
        imshow(OUTPUT_WIN, gray_src);
    
        Mat xgrad, ygrad;
        //cv_16s 输出图像的深度
        //X方向1阶导,Y方向不求导
        //kernel大小是3
        /*Sobel(gray_src, xgrad, CV_16S, 1,0, 3);
        Sobel(gray_src, ygrad, CV_16S, 0, 1, 3);*/
    
        //Scharr算子:中心元素占的权重更重,边缘得到更大加强
        Scharr(gray_src, xgrad, CV_16S, 1, 0, 3);
        Scharr(gray_src, ygrad, CV_16S, 0, 1, 3);
        //图像增强
        convertScaleAbs(xgrad, xgrad,1.5,10);
        convertScaleAbs(ygrad, ygrad);
        imshow("xgrad", xgrad);
        imshow("ygrad", ygrad);
    
        //x,y方向都加进来
        Mat res;
        addWeighted(xgrad, 0.5, ygrad, 0.5, 0, res);
        imshow("res", res);
        
    
        waitKey(0);
        return 0; 
    }
  • 相关阅读:
    蓝桥杯2016初赛
    蓝桥杯2016初赛
    蓝桥杯2016初赛
    蓝桥杯2015初赛
    关于VS本身遇到的一些相关问题
    VS的一些常用快捷键
    蓝桥杯2015初赛
    Luogu P1704 寻找最优美做题曲线
    POI2009 LYZ-Ice Skates
    Luogu P4313 文理分科
  • 原文地址:https://www.cnblogs.com/xiaochi/p/12010171.html
Copyright © 2011-2022 走看看