import cv
import cv2
capture = cv.CaptureFromCAM(0)
#cv.NamedWindow("Live Video",1)
'''
templ = cv. LoadImage ('handHW.PNG',cv.CV_LOAD_IMAGE_GRAYSCALE)
threshold = 150
cv.Threshold(templ,templ,threshold,255,cv.CV_THRESH_BINARY)
'''
count = 0
storage =cv.CreateMemStorage(0)
while count < 200:
#get the frame, convert to HSV and dilate
frame = cv.QueryFrame(capture)
cv.CvtColor(frame, frame,cv.CV_BGR2HSV)
cv.Dilate(frame,frame,None,1)
#store standard size of the frame
size = cv.GetSize(frame)
frameCopy = cv.CloneImage(frame)
image = cv.CreateImage(size,cv.IPL_DEPTH_32F,3)
cv.ConvertScale(frameCopy,image)
image_2 = cv.CreateImage(size,cv.IPL_DEPTH_32F,1)
#cv.CvtColor(image_2,image_2,cv.CV_BGR2HSV)
new_image = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
cv.ConvertScale(image_2,new_image)
points = []
bound_rect_list= []
contours= cv.FindContours(new_image,storage,cv.CV_RETR_LIST,cv.CV_CHAIN_APPROX_SIMPLE,(0,0))
while contours:
bound_rect =cv.BoundingRect(list(contours))
point1 = ( bound_rect[0], bound_rect[1] )
point2 = ( bound_rect[0] + bound_rect[2], bound_rect[1] + bound_rect[3] )
bound_rect_list.append((point1,point2))
approx = cv.ApproxPolyDP(points,0.1*cv.ArcLength(cnt,True),True)
hull = cv.ConvexHull2(points,storage,cv.CV_CLOCKWISE,1)
poly_points = cv.ApproxPoly(list(contours),storage,cv.CV_POLY_APPROX_DP)
for i in range (count):
cv.Circle(image,points[i],2,(0,0,255,0),cv.CV_FILLED,cv.CV_AA,0)
cv.PolyLine(image_2,[hull],1,cv.CV_RGB(0,255,0),1,cv.CV_AA)
#cv.DrawContours(frameCopy,contours,(255,255,0),(0,255,255),2,8,(0,0))
contours = contours.h_next()
cv.ShowImage("LIVE CAM",frameCopy)
cv.ShowImage('SEARCH AREA',image)
This post has been edited by JavaLilly: 11 December 2012 - 04:25 PM

New Topic/Question
Reply



MultiQuote


|