Sobel Edge Detection

void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )

Parameters:
  • src – input image.
  • dst – output image of the same size and the same number of channels as src .
  • ddepth
    output image depth; the following combinations of src.depth() and ddepth are supported:
    • src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F
    • src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F
    • src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F
    • src.depth() = CV_64F, ddepth = -1/CV_64F
    when ddepth=-1, the destination image will have the same depth as the source; in the case of 8-bit input images it will result in truncated derivatives.
  • xorder – order of the derivative x.
  • yorder – order of the derivative y.
  • ksize – size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
  • scale – optional scale factor for the computed derivative values; by default, no scaling is applied (see getDerivKernels() for details).
  • delta – optional delta value that is added to the results prior to storing them in dst.
  • borderType – pixel extrapolation method (see borderInterpolate() for details).

Functions:

 
This is a code from OpenCV documentation. I have made some changes to it.

Example:

--------------
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"

using namespace cv;
using namespace std;

int main( )
{
    Mat src1;
    src1 = imread("lena.jpg", CV_LOAD_IMAGE_COLOR);
    namedWindow( "Original image", CV_WINDOW_AUTOSIZE );
    imshow( "Original image", src1 );

    Mat grey;
    cvtColor(src1, grey, CV_BGR2GRAY);

    Mat sobelx;
    Sobel(grey, sobelx, CV_32F, 1, 0);

    double minVal, maxVal;
    minMaxLoc(sobelx, &minVal, &maxVal); //find minimum and maximum intensities
    cout << "minVal : " << minVal << endl << "maxVal : " << maxVal << endl;

    Mat draw;
    sobelx.convertTo(draw, CV_8U, 255.0/(maxVal - minVal), -minVal * 255.0/(maxVal - minVal));

    namedWindow("image", CV_WINDOW_AUTOSIZE);
    imshow("image", draw);

    waitKey(0);                                        
    return 0;
} 

--------------
Result:


5 comments:

  1. Hi do you have any tutorials regarding how to detect tables and crop and save those tables as images?

    ReplyDelete
  2. How can I do a YUV444 to YUV422 resampling and vice versa using an opencv function?
    I did not find this function.

    ReplyDelete
  3. Affordable research paper writing services
    are very difficult to complete because they require extensive research and most students lack the appropriate skills of researching,thats why students opt to find help from writing companies.

    ReplyDelete
  4. Having such countless fascinating points on your site is exceptionally amazing. It is exceptionally valuable to me. For more data about the various sorts of click counters, if it's not too much trouble, visit the Online tally counter profile there you will get free internet based click counter software.

    ReplyDelete