Sobel derivative in OpenCV

后端 未结 3 1629
梦如初夏
梦如初夏 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:21

    If i were you, i would almost always avoid using for loops(if possible). Unnecessary for loops tend to slow down the execution. Instead, reuse wherever possible. For example, the code below uses filter2D give 2d Correlation result:

    Mat kern = (Mat_(3,3)<<-1,0,1,-2,0,2,-1,0,1);
    Mat dest;
    cv::filter2D(src,dest,src.type(),kern);
    

    If you would like to get convolution results, you would need to flip the kernel 'kern' before filtering.

    cv::flip(kern,kern, -1);
    

    If you would like to squeeze more performance, you can use separable filters 'sepFilter2D'.

提交回复
热议问题