def hull_speed(xy,verbose=False): """ >>> xy = npy.asarray([[0,0],[0,1],[1,1],[1,0]]) >>> print hull_speed(xy) (0.25, 0.35355339059327379, 0.0625, 0.35355339059327379) """ hull_xy = qhull(xy) #max dist inside hull d = pdist(hull_xy, 'euclidean') dmax_idx = npy.argmax(d) #total length tot_length = npy.sum(npy.diag(squareform(d),1)) #hull_surf p3 = npy.mean(hull_xy,axis=0) n_hull = hull_xy.shape[0] hull_surf = 0.0 for k in range(n_hull): p1 = hull_xy[k,:] p2 = hull_xy[(k+1)%n_hull,:] a = area_of_triangle(p1,p2,p3) hull_surf += a if verbose: import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') plt.scatter(xy[:,0],xy[:,1]) plt.plot(hull_xy[:,0],hull_xy[:,1]) plt.show() return (hull_surf/xy.shape[0],d[dmax_idx]/xy.shape[0],hull_surf/tot_length**2,d[dmax_idx]/tot_length)
def draw(self,screen): #Raw camera feed capture_img = self.diffp.get_curr_capture() if self.settings.points_enable: draw=ImageDraw.Draw(capture_img) for point in (point for point in self.settings.points.data if None is not point): draw.ellipse((point[0]-2,point[1]-2)+(point[0]+2,point[1]+2),outline='red',fill=True) capture = pygame.image.fromstring(capture_img.tostring(),capture_img.size,'RGB') capture = capture.convert() self.raw_cam_surface.blit(capture,(0,0)) #Modified feed capture_img = self.diffp.get_curr_capture() if self.settings.brightness_enable: capture_img=ImageEnhance.Brightness(capture_img).enhance(self.settings.brightness) if self.settings.contrast_enable: capture_img=ImageEnhance.Contrast(capture_img).enhance(self.settings.contrast) if self.settings.threshold_enable: capture_img=capture_img.convert('I').convert('RGB') capture_img=capture_img.point(lambda x: [255,0][x<=self.settings.threshold]) if self.settings.points_enable: if 4==len([point for point in self.settings.points.data if None is not point]): points=list(self.settings.points.data) points.sort() capture_img=capture_img.transform(capture_img.size,Image.QUAD,self.get_points(points)) # capture_img=capture_img.filter(ImageFilter.BLUR) # capture_img=capture_img.filter(ImageFilter.CONTOUR) # capture_img=capture_img.filter(ImageFilter.DETAIL) # capture_img=capture_img.filter(ImageFilter.EDGE_ENHANCE) # capture_img=capture_img.filter(ImageFilter.EDGE_ENHANCE_MORE) # capture_img=capture_img.filter(ImageFilter.EMBOSS) capture_img=capture_img.filter(ImageFilter.FIND_EDGES) capture_img=capture_img.filter(ImageFilter.SMOOTH) # capture_img=capture_img.filter(ImageFilter.SMOOTH_MORE) # capture_img=capture_img.filter(ImageFilter.SHARPEN) # capture_img=capture_img.convert('L').convert('RGB') self.capture_img = capture_img data=list(capture_img.convert('L').getdata()) width=self.diffp.get_capture_size()[0] height=self.diffp.get_capture_size()[1] #capture_img.convert('L').save('test.png') # print (data[0],data[1],data[2],data[width],data[width+1],data[width+2]) points=[[col,row] for row in xrange(1,height-1) for col in xrange(1,width-1) if 255==data[col+width*row]] from quickhull2d import qhull from Numeric import array # print array(points) # print points new_points=[tuple(i) for i in qhull(array(points)).tolist()] # print new_points # print new_points #if len(new_points)>2: #draw=ImageDraw.Draw(capture_img) #draw.polygon(new_points,outline='red') capture=pygame.image.fromstring(capture_img.tostring(),capture_img.size,'RGB') capture=capture.convert() self.mod_cam_surface.blit(capture,(0,0)) #Invalidate the ImageMaps that show the surfaces so they will get redrawn self.raw_cam_window.child.invalidate(pygame.Rect(0,0,self.diffp.get_capture_size()[0],self.diffp.get_capture_size()[1])) self.mod_cam_window.child.invalidate(pygame.Rect(0,0,self.diffp.get_capture_size()[0],self.diffp.get_capture_size()[1])) self.renderer.update()