CREATING IMAGE USING PYTHON CODE

PRE-REQUITIES ::

* Install cv2 modulecommand: pip install OpenCV-python

|| OpenCV is a cross-platform library using which we can develop real-time computer vision applications.

**It mainly focuses on image processing, video capture and analysis including features like face detection and object detection.

|| OpenCV-Python makes use of Numpy , which is a highly optimized library for numerical operations with a MATLAB-style syntax.

1.Import cv2 and numpy.

2. Create an Blank image using numpy.

command : numpy.zeros((height , width , 3))* numpy.zeros : fills with zero which means black color
i.e., (B , G , R) = (0 , 0 , 0)
* '3' : BGR color

3. Start to draw the image as per your wish using some functions.

A. To draw any shapes * Use "drawContours()" with boundary pointsSYNTAX: cv2.drawContours(<img>, <contours>, <contourIdx>, <colour>, <thickness>)
Where
- img : Name of the image
- contours : All the input contours.
- contourIdx : Parameter indicating a contour to draw. If it is negative, all the contours are drawn.
- color : Color of the contours (B , G , R)
- thickness is how thick are the lines drawing the contour

* To specify boundary points use "array()"

SYNTAX: numpy.array()
B. To draw circle on image : cv2.circle()SYNTAX: cv2.circle(<img>, (‘center_coordinates’), (‘circle_radius’), (‘color_in_bgr’), ‘stroke_thickness’)
C. To draw rectangle on image : cv2.rectangle()SYNTAX: cv2.rectangle(imageObjectName, (‘top_left_vertex_coordinates’), (‘lower_right_vertex_coordinates’), (‘stroke_color_in_bgr’), ‘stroke_thickness’)
D. To draw line on image : cv2.line()SYNTAX: cv2.line(imageObjectName, (‘start_coordinates’), (‘end_coordinates’), (‘color_in_bgr’), ‘line_thickness’)

4. To write on image

SYNTAX: cv2.putText(imageObjectName, ‘TextContent’, (‘text_starting_point_coordinates’), ‘fontToBeUsed’, ‘font_size’, (‘text_color’, ‘text_thickness’, ‘line_type’)

5. Now see the output.

Syntax: cv2.imshow(window_name, image)
cv2.waitkey(time in ms)
cv2.destroyAllWindows()

FINAL CODE :

OUTPUT:

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Surviving a Coding Bootcamp

Time Attributes in Apache Flink

How Software Development tracking is broken

Scheduling Jobs with cron.yaml in Golang App

Wednesday update from PointPay

Autoware on Yonohub — Part 1

Testing in Go

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saranya. S

Saranya. S

More from Medium

Full Installation Guide of MySQL 8.0 on Ubuntu Machine

Capture Date, Phone and Email From Text With Regular Expression in Python

The best of two worlds: working with VSCode and Windows Subsystem for Linux (Python)

Getting Started with Kivy: How to Code Desktop and Mobile Apps with Python

Screen Shot 2022-03-09 at 2.27.30 PM.png