Opencv-adding borders to images (filling)

Source: Internet
Author: User

Fill the border of the image for filtering, convolution, and other operations related to image boundary processing.

# Include "opencv2/imgproc. HPP "# include" opencv2/highgui. HPP "# include <stdlib. h> # include <stdio. h> using namespace CV; // global variable mat SRC, DST; int top, bottom, left, right; // defines the boundary size int bordertype; // The boundary processing type scalar value; char * window_name = "copymakeborder Demo"; RNG (12345); int main (INT argc, char ** argv) {int C; // load the image src = imread (argv [1]); If (! SRC. data) {return-1; printf ("no data entered, please enter the path to an image file \ n ");} /// brief how-to for this program printf ("\ n \ t copymakeborder Demo: \ n"); printf ("\ t ------------------ \ n "); printf ("** press 'C' to set the border to a random constant value \ n "); printf ("** press 'R' to set the border to be replicated \ n"); printf ("** press 'esc 'to exit the program \ n "); // create a window named window (window_name, cv_window_autosize); // initialize the filter parameter Top = (INT) (0.05 * SRC. rows); bottom = (INT) (0.05 * SRC. rows); left = (INT) (0.05 * SRC. cols); Right = (INT) (0.05 * SRC. cols); DST = SRC; imshow (window_name, DST); While (true) {c = waitkey (500); If (char) C = 27) // Press ESC to exit the program {break;} else if (char) C = 'C') {bordertype = border_constant;} else if (char) C = 'R') {bordertype = border_replicate;} value = scalar (RNG. uniform (0,255), RNG. uniform (0,255), RNG. uniform (0,255); copymakeborder (SRC, DST, top, bottom, left, right, bordertype, value); imshow (window_name, DST);} return 0 ;}

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.