Drawing with OpenCV
CS-161: Software Project
Instructor: Rob Bruce
Spring 2016

SLIDE 1: Drawing in OpenCV

  • OpenCV provides basic functionality for drawing shapes such as:
    •  Points
    •  Lines
    •  Ellipses
    •  Rectangles
  • Drawing functionality is useful for diagnostic or debugging purposes.

SLIDE 2: Drawing a rectangle outline (1 pixel thick)

rectangle (source_image, point_1, point_2, CV_RGB(0, 255, 0), 1, 8, 0);

A green unfilled rectangle with upper left corner labeled as point 1 and lower right corner labeled as point 2.

SLIDE 3: Drawing a filled rectangle

rectangle (source_image, point_1, point_2, CV_RGB(0, 255, 0), -1, 8, 0);

A green filled rectangle with upper left corner labeled as point 1 and lower right corner labeled as point 2.

SLIDE 4: Drawing a blue line (5 pixels thick)

line (source_image, point_1, point_2, CV_RGB(0, 0, 255), 5, 8, 0);

A blue line that is 5 pixels thick labeled with left endpoint as point 1 and right endpoint labeled as point 2.

SLIDE 5: Drawing a magenta circle 9 pixels thick

circle (source_image, point_center, radius, CV_RGB(255, 0, 255), 9, 8, 0);

A magenta circle that is 9 pixels thick labeled with the circle's center as point center and the circle radius labled as radius.

SLIDE 6: Drawing a solid red circle

circle (source_image, point_center, radius, CV_RGB(255, 0, 0), -1, 8, 0);

A solid red circle labeled with the circle's center as point center and the circle radius labled as radius.

SLIDE 7: Drawing black text

putText (source_image, "Sample text", point_origin, FONT_HERSHEY_PLAIN, 3, CV_RGB(255, 0, 0), 1, 8, false);