Creating Image Using Python Code.

Step 1: Install cv2 Module.

command : pip install opencv-python.

|| OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision. ||

Step 2: Import cv2 and Numpy

Importing cv2 and numpy

Step 3: Create an Blank image using Numpy.

command : numpy.zeros((height,width,3))

numpy.zeros : It is having 3 colors in the form of

i.e , (B , G , R) = ( 0 , 0, 0 ) so ‘3’:BGR color

numpy.uint8 : Unsigned integer (0 to 255)

Step 4 : Start to draw the image as per your wish using some functions.

I have just created a nested for loop for assigning colors dividing the image

for i in range(h) : the range of height which we have given as 512

for j in range(w) : the range of width which we have given as 512

we have already intialized A in previous steps

Therefore, we start assigning colors to the given height and width.

step 4 : To see the output:

Syntax: cv2.imshow(window_name, image) #display image
cv2.waitkey(time in ms) # wait for a specific time in milliseconds
cv2.destroyAllWindows() # destroy the window after displaying the image

Output :

Hope you find it Intresting ..!!

Thank You..!!

--

--

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