Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #program to draw polygon
- import cv
- image=cv.CreateImage((400,400),cv.IPL_DEPTH_8U,1)
- vertices = [ (10,10),(100,40),(200,200),(70,250) ]
- # Draw the polygon and fill inside with white color so you get a binary image.
- cv.FillConvexPoly(image,vertices,255)
- # Now access all points inside polygon and find percentage of white pixels
- points = []
- white = 0
- for i in range(image.height):
- for j in range(image.width):
- if (cv.Get2D(image,j,i)[0]== 255.0):
- points.append([j,i])
- white = white + 1
- print "no of white pixels =",white
- area = (white*100)/(image.height*image.width)
- print "percentage area of tetragon =",area
- print points
- while(1):
- cv.ShowImage("image",image)
- if cv.WaitKey(0)==27:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement