Edge detection, 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()
{ 

    The src = imread ( " .//pic//kate.png " ); 

    namedWindow (INPUT_WIN, CV_WINDOW_AUTOSIZE); 
    namedWindow (OUTPUT_WIN, CV_WINDOW_AUTOSIZE); 
    imshow (INPUT_WIN, the src); 
    
    the Gaussian Blur (the src, DST, Size ( . 3 , . 3 ), 0 , 0 ); 
    Mat gray_src; 
    cvtColor (DST, gray_src, CV_BGR2GRAY); 
    imshow (OUTPUT_WIN, gray_src); 

    Mat xgrad, ygrad; 
    // depth of an output image cv_16s
     // X-direction a derivative, Y direction does not seek guide
     // Kernel size is. 3 
    / * the Sobel (gray_src, xgrad, CV_16S, 1,0,. 3); 
    the Sobel (gray_src, ygrad, CV_16S, 0,. 1,. 3); * / 

    //Scharr Operator: accounting center element heavier weight, greater edge reinforcing 
    Scharr (gray_src, xgrad, CV_16S, . 1 , 0 , . 3 ); 
    Scharr (gray_src, ygrad, CV_16S, 0 , . 1 , . 3 );
     // Image enhanced 
    convertScaleAbs (xgrad, xgrad, for 1.5 , 10 ); 
    convertScaleAbs (ygrad, ygrad); 
    imshow ( " xgrad " , xgrad); 
    imshow ( " ygrad " , ygrad); 

    // X, Y directions add to the mix 
     Mat res;
    addWeighted (xgrad, 0.5 , ygrad, 0.5 , 0, res);
    imshow("res", res);
    

    waitKey(0);
    return 0; 
}

 

Guess you like

Origin www.cnblogs.com/xiaochi/p/12010171.html