From: Ana Huaman Date: Tue, 21 Jun 2011 05:06:25 +0000 (+0000) Subject: Reorganized code and added Morphology 2 cpp code X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~6893 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2819438fe6ffab4958ae8025e0826ff5c4740201;p=platform%2Fupstream%2Fopencv.git Reorganized code and added Morphology 2 cpp code --- diff --git a/samples/cpp/tutorial_code/Basic/DisplayImage.cpp b/samples/cpp/tutorial_code/Basic/DisplayImage.cpp deleted file mode 100644 index 99ce674..0000000 --- a/samples/cpp/tutorial_code/Basic/DisplayImage.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @file DisplayImage.cpp - * @brief Sample code that show how to read and display an image in a OpenCV window - * @author OpenCV team - */ -#include -#include - -using namespace cv; - -int main( int argc, char** argv ) -{ - Mat image; - image = imread( argv[1], 1 ); - - if( argc != 2 || !image.data ) - { - printf( "No image data \n" ); - return -1; - } - - namedWindow( "Display Image", CV_WINDOW_AUTOSIZE ); - imshow( "Display Image", image ); - - waitKey(0); - - return 0; -} diff --git a/samples/cpp/tutorial_code/Basic/LoadSaveImage.cpp b/samples/cpp/tutorial_code/Basic/LoadSaveImage.cpp deleted file mode 100644 index 69db8e3..0000000 --- a/samples/cpp/tutorial_code/Basic/LoadSaveImage.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @file LoadSaveImage.cpp - * @brief Sample code that load an image, modify it and save the new image. - * @author OpenCV team - */ - -#include -#include - -using namespace cv; - -/** - * @function main - * @brief Self-explanatory - */ -int main( int argc, char** argv ) -{ - /// Get the name of the file to be loaded - char* imageName = argv[1]; - - /// Create a Mat object - Mat image; - - /// Load the image using imread - image = imread( imageName, 1 ); - - /// Verify that the image was loaded - if( argc != 2 || !image.data ) - { - printf( " No image data \n " ); - return -1; - } - - /// Change the image to Grayscale - Mat gray_image; - cvtColor( image, gray_image, CV_RGB2GRAY ); - - /// Save our gray image - imwrite( "../images/Gray_Image.png", gray_image ); - - /// Create a couple of windows and show our images - namedWindow( imageName, CV_WINDOW_AUTOSIZE ); - namedWindow( "Gray image", CV_WINDOW_AUTOSIZE ); - - imshow( imageName, image ); - imshow( "Gray image", gray_image ); - - /// Wait until user finish the application - waitKey(0); - - return 0; -} diff --git a/samples/cpp/tutorial_code/Basic/Drawing_1.cpp b/samples/cpp/tutorial_code/CxCore/Matrix/Drawing_1.cpp similarity index 100% rename from samples/cpp/tutorial_code/Basic/Drawing_1.cpp rename to samples/cpp/tutorial_code/CxCore/Matrix/Drawing_1.cpp diff --git a/samples/cpp/tutorial_code/Basic/Drawing_2.cpp b/samples/cpp/tutorial_code/CxCore/Matrix/Drawing_2.cpp similarity index 100% rename from samples/cpp/tutorial_code/Basic/Drawing_2.cpp rename to samples/cpp/tutorial_code/CxCore/Matrix/Drawing_2.cpp diff --git a/samples/cpp/tutorial_code/Basic/AddingImagesTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp similarity index 100% rename from samples/cpp/tutorial_code/Basic/AddingImagesTrackbar.cpp rename to samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp diff --git a/samples/cpp/tutorial_code/Basic/BasicLinearTransformsTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp similarity index 100% rename from samples/cpp/tutorial_code/Basic/BasicLinearTransformsTrackbar.cpp rename to samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp diff --git a/samples/cpp/tutorial_code/Basic/AddingImages.cpp b/samples/cpp/tutorial_code/ImgProc/AddingImages.cpp similarity index 100% rename from samples/cpp/tutorial_code/Basic/AddingImages.cpp rename to samples/cpp/tutorial_code/ImgProc/AddingImages.cpp diff --git a/samples/cpp/tutorial_code/Basic/BasicLinearTransforms.cpp b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp similarity index 100% rename from samples/cpp/tutorial_code/Basic/BasicLinearTransforms.cpp rename to samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp diff --git a/samples/cpp/tutorial_code/Image_Processing/Morphology_1.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp similarity index 100% rename from samples/cpp/tutorial_code/Image_Processing/Morphology_1.cpp rename to samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp diff --git a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp new file mode 100644 index 0000000..12388d0 --- /dev/null +++ b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp @@ -0,0 +1,80 @@ +/** + * @file Morphology_2.cpp + * @brief Advanced morphology Transformations sample code + * @author OpenCV team + */ + +#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui/highgui.hpp" +#include +#include + +using namespace cv; + +/// Global variables +Mat src, dst; + +int morph_elem = 0; +int morph_size = 0; +int morph_operator = 0; +int const max_operator = 4; +int const max_elem = 2; +int const max_kernel_size = 21; + +char* window_name = "Morphology Transformations Demo"; + + +/** Function Headers */ +void Morphology_Operations( int, void* ); + +/** + * @function main + */ +int main( int argc, char** argv ) +{ + /// Load an image + src = imread( argv[1] ); + + if( !src.data ) + { return -1; } + + /// Create window + namedWindow( window_name, CV_WINDOW_AUTOSIZE ); + + /// Create Trackbar to select Morphology operation + createTrackbar("Operator:\n 0: Opening - 1: Closing \n 2: Gradient - 3: Top Hat \n 4: Black Hat", window_name, &morph_operator, max_operator, Morphology_Operations ); + + /// Create Trackbar to select kernel type + createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name, + &morph_elem, max_elem, + Morphology_Operations ); + + /// Create Trackbar to choose kernel size + createTrackbar( "Kernel size:\n 2n +1", window_name, + &morph_size, max_kernel_size, + Morphology_Operations ); + + /// Default start + Morphology_Operations( 0, 0 ); + + waitKey(0); + return 0; +} + +/** + * @function Morphology_Operations + */ +void Morphology_Operations( int, void* ) +{ + + // Since MORPH_X : 2,3,4,5 and 6 + int operation = morph_operator + 2; + + Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) ); + + /// Apply the specified morphology operation + morphologyEx( src, dst, operation, element ); + imshow( window_name, dst ); +} + + diff --git a/samples/cpp/tutorial_code/Image_Processing/Smoothing.cpp b/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp similarity index 100% rename from samples/cpp/tutorial_code/Image_Processing/Smoothing.cpp rename to samples/cpp/tutorial_code/ImgProc/Smoothing.cpp