7 #include <opencv/highgui.h> 11 std::cout <<
"\nThis is a demo that shows an anhanced canny edge detection\n" 13 " ./canny file # for a single image\n" 14 " ./canny file # for camera usage\n";
17 int main (
int argc,
char *argv[] ) {
24 if ( !cap.isOpened() ) {
25 std::cout <<
"***Could not initialize capturing...***\n";
29 cap.set ( CV_CAP_PROP_FRAME_WIDTH, 800 );
30 cap.set ( CV_CAP_PROP_FRAME_HEIGHT, 600 );
31 std::cout <<
"Video " <<
32 ": width=" << cap.get ( CV_CAP_PROP_FRAME_WIDTH ) <<
33 ", height=" << cap.get ( CV_CAP_PROP_FRAME_HEIGHT ) <<
34 ", nframes=" << cap.get ( CV_CAP_PROP_FRAME_COUNT ) << std::endl;
36 if ( !cap.isOpened() ) {
37 printf (
"%s\n", argv[1] );
38 imgSrc = cv::imread ( argv[1] );
42 if ( imgSrc.empty() ) {
43 std::cout <<
"***image...***\n";
46 cv::cvtColor ( imgSrc, imgGray, CV_RGB2GRAY );
48 cv::Mat imgGauss, imgCanny, imgGradient, imgDirection;
49 cv::namedWindow (
"src",1 );
50 cv::namedWindow (
"img",1 );
51 cv::namedWindow (
"canny",1 );
52 cv::namedWindow (
"gradient",1 );
53 cv::namedWindow (
"direction",1 );
55 if ( cap.isOpened() ) {
57 cv::cvtColor ( imgSrc, imgGray, CV_RGB2GRAY );
59 if ( imgSrc.empty() ) {
62 cv::GaussianBlur ( imgGray, imgGauss, cv::Size ( 7,7 ), 1.5, 1.5 );
63 V4R::Canny ( imgGauss, imgCanny, imgGradient, imgDirection, 0, 30, 3 );
64 cv::imshow (
"src", imgGray );
65 cv::imshow (
"img", imgGray );
66 cv::imshow (
"canny", imgCanny );
67 cv::imshow (
"gradient", ( imgGradient*65335/360 ) );
68 cv::imshow (
"direction", ( imgDirection*65335/360 ) );
69 }
while ( cv::waitKey ( 30 ) < 0 ) ;
void Canny(const cv::Mat &image, cv::Mat &edges, cv::Mat &gradient, cv::Mat &direction, cv::Mat &sobel_dx, cv::Mat &sobel_dy, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false)
int main(int argc, char *argv[])