Creating Art or image using Arrays and Numpy

Creating Art or image using Arrays and Numpy

In this articles , we will see how to create an image by yourself using the numpy array using Opencv.

So first we have to create the simple image using the numpy array the simple image using the numpy array and need to import required libraries.

Import cv2
Import numpy as np
Import matplotlib.pyplot as        

  • Creating a simple black image using numpy array

blank_img =np.zeros((600 ,600 ,3))

cv2.imshow?('dark', blank_img)
cv2.waitKey()
cv2.destroyAllWindows()        

In python Open cv this statement show the creating blank image destroyAllWindows () function allows users to destroy all windows at any time and imshow function is show the image and waitKey() function is hold the image.

  • after creating blank image we draw some line on the blank image help of line function.

img=cv2.line(blank_img ,(10,20),(600, 20),(0,0,255),4
img=cv2.line(blank_img, (10,80), (600, 80), (0,0,255), 4)

cv2.imshow("hi",img)
cv2.waitKey()
cv2.destroyAllWindows()        
No alt text provided for this image

  • after this we put some text into our image using the putText function.

font= cv2.FONT_HERSHEY_SIMPLE
image=cv2.putText(blank_img ,'Image by Vicky',(90,50),font, 0.8, (255,0,0),2, cv2.LINE_AA)
image=cv2.putText(blank_img, '******* IMAGE********',(90,125),font,0.8, (0,255,0), 2, cv2.LINE_AA)
        
No alt text provided for this image

  • After this we drawing some other shape like rectangle and circle for creating the own image using cv2.

cv2.rectangle(img, (550,400), (400,200), (255,0,0),cv2.FILLED
cv2.rectangle(img, (420,300), (500,200), (255,255,0),cv2.FILLED)
cv2.circle(img, (430,250),10,(0,255,255),cv2.FILLED)
cv2.line(img ,(400,200),(570, 200),(0,255,255),12)
cv2.line(img ,(20,400),(570, 400),(0,0,255),9)
cv2.rectangle(img, (20,300), (400,400), (0,255,0),cv2.FILLED)
cv2.circle(img, (100,400),50,(255,0,0),cv2.FILLED)
cv2.circle(img, (450,400),50,(255,0,0),cv2.FILLED))        
No alt text provided for this image

Thank you for see my article

I would like to have your feedback and suggestions and hope you will finds this article helphul.







To view or add a comment, sign in

Explore content categories