OPENCV Official Document Learning record (12)

Source: Internet
Author: User
Tags scalar

Build boundaries;

Because the pixels at the edge of the image are not calculated according to the formula when making the convolution, it is necessary to construct the boundary at the edge to calculate;

The functions for constructing boundaries in OpenCV are: Copymakeborder (src,dst,top,bottom,left,right,bordertype,values);

First come the code:

1#include <opencv2/opencv.hpp>2#include <iostream>3#include <string>4 5 using namespacestd;6 using namespaceCV;7 8 intMainintargcChar**argv)9 {Ten     if((argc-2)!=0) One     { Acout<<"Usage:./makeborder \ "Image_name\""<<Endl; -         return 0; -     } the  -Mat Src=imread (argv[1]); -     if(Src.empty ()) -     { +cout<<"Have not found image"<<Endl; -         return-1; +     } A  atNamedwindow ("SRC", cv_window_autosize); -Imshow ("SRC", SRC); -  - Mat DST; -RNG RNG (12345); - Scalar values; in     inttop; -     intBottom; to     intLeft ; +     intRight ; -     CharC; the     intBordertype; *  $Top= (int)(0.05*src.rows);Panax NotoginsengBottom= (int)(0.05*src.rows); -Left= (int)(0.05*src.cols); theRight= (int)(0.05*src.rows); +  A      while(true) the     { +C=waitkey ( -); -         if((Char) c== -) $              Break; $         //bordertype=border_constant; -Bordertype=border_replicate; -Values=scalar (Rng.uniform (0,255), Rng.uniform (0,255), Rng.uniform (0,255)); the Copymakeborder (src,dst,top,bottom,left,right,bordertype,values); - WuyiNamedwindow ("Dst", cv_window_autosize); theImshow ("Dst", DST); -     } Wu  - Waitkey (); About     return 0; $}

The same CMakeLists.txt

1 2.8 )2Project (makeBorder.cpp)3find_package (OpenCV REQUIRED)4 add_executable (Makeborder makeBorder.cpp) 5 target_link_libraries (Makeborder ${opencv_libs})

When the Borderype types are evaluated separately, the results are:

You can see that the two parameters differ in that the former is populated with self-built pixels, which expand the edge pixels. Of course, it looks like the latter is more attractive.

The description of the function parameters is not much, literally can be understood.

Above.

OPENCV Official Document Learning record (12)

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.