Simple example of image processing [OpenCV Note 1]

Source: Internet
Author: User
Tags scale image

A few simple procedures for getting started, and the corresponding cmakelist, although a simple re-test it is also good to write a bit.

CMake Tutorial Portal

Image display

Showimage.cxx

#include <opencv2/opencv.hpp><opencv2/highgui/highgui.hpp><opencv2/imgcodecs/ imgcodecs.hpp>int  main () {    = Cv::imread ("1.jpg");    Imshow ("Original Image", srcimage);    Cv::waitkey (0);     return 0 ;}

CMakeLists.txt

2.8 ) Project (ShowImage) find_package (OpenCV REQUIRED) include_directories (${opencv_include_dirs}) # Add the Executableadd_executable (ShowImage showimage.cxx) target_link_libraries (ShowImage opencv_core Opencv_highgui OpenCV _IMGCODECS)

Image corrosion

Erodeimage.cxx

#include <opencv2/opencv.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgcodecs/imgcodecs.hpp>#include<opencv2/imgproc/imgproc.hpp>intMain () {//Read ImageCv::mat srcimage = Cv::imread ("1.jpg"); //Show Original ImageImshow ("Original Image", Srcimage); //Erode ImageCv::mat element = Getstructuringelement (Cv::morph_rect, Cv::size ( the, the));    Cv::mat Dstimage;        Erode (Srcimage, dstimage, Element); //Show ResultsImshow ("Image Erosion", Dstimage); Cv::waitkey (0); return 0;}

CMakeList.txt

2.8find  OpenCV packagesfind_package (OpenCV REQUIRED) include_directories (${opencv_ Include_dirs}) # Add the executableadd_executable (erodeimage erodeimage.cxx) target_link_libraries (ErodeImage opencv_ Core Opencv_highgui Opencv_imgproc opencv_imgcodecs)

Image Blur

Blurimage.cxx

#include <opencv2/opencv.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgcodecs/imgcodecs.hpp>#include<opencv2/imgproc/imgproc.hpp>intMain () {//Read ImageCv::mat srcimage = Cv::imread ("1.jpg"); //Show Original ImageImshow ("Original Image", Srcimage); //Blur ImageCv::mat Dstimage; Blur (Srcimage, Dstimage, Cv::size (7,7)); //Show ResultsImshow ("Image Blurring", Dstimage); Cv::waitkey (0); return 0;}

CMakeList.txt

2.8find  OpenCV packagesfind_package (OpenCV REQUIRED) include_directories (${opencv_ Include_dirs}) # Add the executableadd_executable (blurimage blurimage.cxx) target_link_libraries (BlurImage opencv_ Core Opencv_highgui Opencv_imgproc opencv_imgcodecs)

Canny edge Detection

Cannyedgedetection.cxx

#include <opencv2/opencv.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgcodecs/imgcodecs.hpp>#include<opencv2/imgproc/imgproc.hpp>intMain () {//Read ImageCv::mat srcimage = Cv::imread ("1.jpg"); //Show Original ImageImshow ("Original Image", Srcimage); //Blur ImageCv::mat dstimage, Edge, grayimage; //Create a matrix the same size as Srcimagedstimage.create (Srcimage.size (), Srcimage.type ()); //Convert color image to Gray-scale image//OpenCV2//Cv::cvtcolor (Srcimage, Grayimage, Cv::cv_bgr2gray); //OpenCV3Cv::cvtcolor (Srcimage, Grayimage, Cv::color_bgr2gray); //denoisingBlur (Srcimage, Dstimage, Cv::size (3,3)); //Apply Canny operatorCanny (Dstimage, Edge,3,9,3); //Show ResultsImshow ("Canny Edge Detection", Edge); Cv::waitkey (0); return 0;}

CMakeList.txt

2.8find  OpenCV packagesfind_package (OpenCV REQUIRED) include_directories (${opencv_ Include_dirs}) # Add the executableadd_executable (cannyedgedetection cannyedgedetection.cxx) target_link_libraries ( Cannyedgedetection opencv_core Opencv_highgui opencv_imgproc opencv_imgcodecs)

Simple example of image processing [OpenCV Note 1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.