Sobel derivative in OpenCV

后端 未结 3 1630
梦如初夏
梦如初夏 2020-11-30 15:49

I have been tasked with making my own Sobel method, and not use the cv::Sobel found in OpenCV. I tried implementing one I found at Programming techniques

<
3条回答
  •  囚心锁ツ
    2020-11-30 16:22

    thanks for the post, I was able to generate gradiant map using the above kernel, and using openCV code filter2D getting from Using custom kernel in opencv 2DFilter - causing crash ... convolution how?

    to convolve the image with the kernel. the code that I used is

        #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include 
    #include 
    #include 
    
    using namespace cv;
    using namespace std;
    
    int main(int argc, char** argv) {
    
        //Loading the source image
        Mat src;
        //src = imread("1.png");
        src = cv::imread("E:\\Gray_Image.bmp", 0);
        //Output image of the same size and the same number of channels as src.
        Mat dst1,dst2,grad;
        //Mat dst = src.clone();   //didn't help...
    
        //desired depth of the destination image
        //negative so dst will be the same as src.depth()
        int ddepth = -1;
    
        //the convolution kernel, a single-channel floating point matrix:
    
    
        //Mat kernel = imread("kernel.png");
    
        Mat kernel_x = (Mat_(3, 3) << -1, 0, 1, -2, 0, 2, -1, 0, 1);
    
        Mat kernel_y = (Mat_(3, 3) << -1, -2, -1, 0, 0, 0, 1, 2, 1);
        kernel_x.convertTo(kernel_x, CV_32F);  kernel_y.convertTo(kernel_y, CV_32F);   //<

提交回复
热议问题