Advertisement
Guest User

Drawing polygon

a guest
Jan 19th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #program to draw polygon
  2. import cv
  3. image=cv.CreateImage((400,400),cv.IPL_DEPTH_8U,1)
  4. vertices = [ (10,10),(100,40),(200,200),(70,250) ]
  5.  
  6. #   Draw the polygon and fill inside with white color so you get a binary image.
  7. cv.FillConvexPoly(image,vertices,255)
  8.  
  9. # Now access all points inside polygon and find percentage of white pixels
  10.  
  11. points = []
  12. white = 0
  13. for i in range(image.height):
  14.     for j in range(image.width):
  15.         if (cv.Get2D(image,j,i)[0]== 255.0):
  16.             points.append([j,i])
  17.             white = white + 1
  18.            
  19. print "no of white pixels =",white
  20. area = (white*100)/(image.height*image.width)
  21. print "percentage area of tetragon =",area
  22. print points
  23. while(1):
  24.     cv.ShowImage("image",image)
  25.     if cv.WaitKey(0)==27:
  26.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement