Canny Edge Detection

void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false )
Parameters:
  • image – single-channel 8-bit input image.
  • edges – output edge map; it has the same size and type as image .
  • threshold1 – first threshold for the hysteresis procedure.
  • threshold2 – second threshold for the hysteresis procedure.
  • apertureSize – aperture size for the Sobel() operator.
  • L2gradient – a flag, indicating whether a more accurate L_2 norm =\sqrt{(dI/dx)^2 + (dI/dy)^2} should be used to calculate the image gradient magnitude ( L2gradient=true ), or whether the default L_1 norm =|dI/dx|+|dI/dy| is enough ( L2gradient=false ).
 A good example for Canny Edge Detection is provided in OpenCV Documentation..

Functions:

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 gray, edge, draw;
    cvtColor(src1, gray, CV_BGR2GRAY);

    Canny( gray, edge, 50, 150, 3);

    edge.convertTo(draw, CV_8U);
    namedWindow("image", CV_WINDOW_AUTOSIZE);
    imshow("image", draw);

    waitKey(0);                                       
    return 0;
} 

-------------

Result:

9 comments:

  1. fatal error LNK1169: one or more multiply defined symbols found .. can u help me with this ?

    ReplyDelete
  2. forgot to mention m using visual basic c++ , with header file
    #include "stdafx"
    which is #include "stdafx.h"


    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }

    ReplyDelete
  3. Error 1 error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function _main
    Error 14 fatal error LNK1120: 13 unresolved externals
    can u help me with this?
    thanks

    ReplyDelete
  4. Hi Kahna, Could you please upload a Tutorial on "Canny Edge Detection during live video capture". I am trying to figure out using: VideoCapture cap(0); code // and unable to implement it.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. Currently Python is the most popular Language in IT. Python adopted as a language of choice for almost all the domain in IT including Web Development, Cloud Computing (AWS, OpenStack, VMware, Google Cloud, etc.. ),Read More

    myTectra the Market Leader in Artificial intelligence training in Bangalore
    myTectra offers Artificial intelligence training in Bangalore using Class Room. myTectra offers Live Online Design Patterns Training Globally.Read More



    myTectra the Market Leader in Machine Learning Training in Bangalore myTectra offers Machine Learning Training in Bangalore using Class Room. myTectra offers Live Online Machine Learning Training Globally. Read More

    ReplyDelete