Go to the documentation of this file.00001 #include <cstdio>
00002 #include <stdlib.h>
00003 #include <iostream>
00004 #include <string>
00005
00006 #include <opencv/cv.h>
00007 #include <opencv/highgui.h>
00008 #include "tuw_utils/canny.h"
00009
00010 void help() {
00011 std::cout << "\nThis is a demo that shows an anhanced canny edge detection\n"
00012 "Usage: \n"
00013 " ./canny file # for a single image\n"
00014 " ./canny file # for camera usage\n";
00015 }
00016
00017 int main ( int argc, char *argv[] ) {
00018
00019 cv::VideoCapture cap;
00020 cv::Mat imgSrc;
00021 cv::Mat imgGray;
00022 if ( argc != 2 ) {
00023 cap.open ( 0 );
00024 if ( !cap.isOpened() ) {
00025 std::cout << "***Could not initialize capturing...***\n";
00026 help();
00027 return -1;
00028 }
00029 cap.set ( CV_CAP_PROP_FRAME_WIDTH, 800 );
00030 cap.set ( CV_CAP_PROP_FRAME_HEIGHT, 600 );
00031 std::cout << "Video " <<
00032 ": width=" << cap.get ( CV_CAP_PROP_FRAME_WIDTH ) <<
00033 ", height=" << cap.get ( CV_CAP_PROP_FRAME_HEIGHT ) <<
00034 ", nframes=" << cap.get ( CV_CAP_PROP_FRAME_COUNT ) << std::endl;
00035 }
00036 if ( !cap.isOpened() ) {
00037 printf ( "%s\n", argv[1] );
00038 imgSrc = cv::imread ( argv[1] );
00039 } else {
00040 cap >> imgSrc;
00041 }
00042 if ( imgSrc.empty() ) {
00043 std::cout << "***image...***\n";
00044 return -1;
00045 }
00046 cv::cvtColor ( imgSrc, imgGray, CV_RGB2GRAY );
00047
00048 cv::Mat imgGauss, imgCanny, imgGradient, imgDirection;
00049 cv::namedWindow ( "src",1 );
00050 cv::namedWindow ( "img",1 );
00051 cv::namedWindow ( "canny",1 );
00052 cv::namedWindow ( "gradient",1 );
00053 cv::namedWindow ( "direction",1 );
00054 do {
00055 if ( cap.isOpened() ) {
00056 cap >> imgSrc;
00057 cv::cvtColor ( imgSrc, imgGray, CV_RGB2GRAY );
00058 }
00059 if ( imgSrc.empty() ) {
00060 continue;
00061 }
00062 cv::GaussianBlur ( imgGray, imgGauss, cv::Size ( 7,7 ), 1.5, 1.5 );
00063 V4R::Canny ( imgGauss, imgCanny, imgGradient, imgDirection, 0, 30, 3 );
00064 cv::imshow ( "src", imgGray );
00065 cv::imshow ( "img", imgGray );
00066 cv::imshow ( "canny", imgCanny );
00067 cv::imshow ( "gradient", ( imgGradient*65335/360 ) );
00068 cv::imshow ( "direction", ( imgDirection*65335/360 ) );
00069 } while ( cv::waitKey ( 30 ) < 0 ) ;
00070
00071 return 0;
00072 }
00073