Tuesday, 2 August 2016

TUT9: Drawing a POKER Face

Hello guys,
         
In this tutorial, we are going to see how to make a simple poker face ( Something like this → `_`).

Here's the code:


import cv2
import numpy as np

img=np.zeros((500,500,3), np.uint8)

cv2.circle(img, (100,100), 70, (255,0,255), 3)
cv2.circle(img, (400,100), 70, (255,0,255), 3)
cv2.circle(img, (250,250), 40, (0,255,255), 3)
cv2.line(img, (100,450), (400,450), (255,255,0), 3)

cv2.imshow('img',img)

cv2.waitKey(0)
cv2.destroyAllWindows()

Line 1-2: Import necessary libraries cv2 and numpy.

Line 3: Create a black surface using np.zeros(). Here, 500 is the height and width of window                           created which will support 3 color channels i.e. RGB.

Line 4: Draw a circle with center (100,100) and 70px radius. (255, 0, 255) will give pink color and 3                specifies the thickness of the circle. This circle is going to be the left eye of the poker face.

Line 5: Draw another circle with center (400,100) and 70px radius. This will be the right eye of the                 face.

Line 6: Draw another circle with center (250,250) and 40px radius. This will be the nose of the                        face.

Line 7: Draw a straight line from (100,450) to (400,450) co-ordinates.

Line 8: Display image using imshow() function.

Line 9-10: Hold image infinitely using waitKey(0) and close any open windows using                                           destroyAllWindows().


OUTPUT:


This will be generated when you run the code. 

That's it for this tutorial. In the next tutorial, we are going to perform some operations on image.

For any queries, use comment section below.

No comments:

Post a comment