from 0 to combat opencv N (4) - framing the image, graphics and text Videos

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

from 0 to combat opencv N (4) - framing the image, graphics and text Videos

 

Additional extra to the image border or mask, painted graphics and text

1, the additional extra frame (often used in convolution)

函数:copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );

parameter:

src: the original image

dst: destination image

top, bottom, left, right: the width of each border, herein defined as 5% of the original image size.

borderType: boundary type, where the boundary may be selected or copied constant boundary.

value: If the type is borderType BORDER_CONSTANT, the boundary value is used to fill pixels.

2, and corresponds to the additional framing mask 0

Result.row (0) .setTo (Scalar (0)); // the boundary

Result.row (Result.rows-1) .setTo (Scalar (0)); // the lower boundary

Result.col (0) .setTo (Scalar (0)); // left border

Result.col (Result.cols-1) .setTo (Scalar (0)); // right border

 

3, draw graphics and text

Graphics functions:

2D Point defined point in the image

Function line () draw a straight line

Function Ellipse () draw the ellipse

Rectangle function () draw a rectangle

Function circle () painted round

Function fillPoly () plotted filled polygons

Text function:

putText( image, "Testing text ", org, rng.uniform(0,8),

rng.uniform(0,100)*0.05+0.1, randomColor(rng), rng.uniform(1, 10), lineType);

Example:

Draw text "Testing text" on the image.

The lower left corner of the text with the specified point org.

Font parameter is an integer between one defined.

Scale font with expression rng.uniform (0, 100) x0.05 + 0.1 specification (which range is represented).

Font color is random (referred to as randomColor (rng)).

Font thickness range is from 1 to 10, expressed as rng.uniform (1,10).

4, test:

Scalar value;

RNG rng(12345);



void main()

{

    Mat src, dst;



    /// 装载图像

    src = imread("2.jpg");

    imshow("src", src);



    putText(src,"opencv goes from 0 to N",Point(80,80),1,1.5,Scalar(0,255,0),1,8);

    rectangle(src,Rect(10,10,50,50), Scalar(0, 255, 0), 1, 8);

    int top = (int)(0.05*src.rows),bottom = (int)(0.05*src.rows);

    int left = (int)(0.05*src.cols),right = (int)(0.05*src.cols);

    dst = src;

    value = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));

    copyMakeBorder(src, dst, top, bottom, left, right, BORDER_CONSTANT, value);



    imshow("dst", dst);



    waitKey(0);

}

 

5 results:

Guess you like

Origin blog.csdn.net/qq_34106574/article/details/93770938