~bertrand-nouvel/pycvf-keypoints/trunk

« back to all changes in this revision

Viewing changes to nodes/plot_onimage.py

  • Committer: tranx
  • Date: 2010-10-01 16:56:14 UTC
  • Revision ID: tranx@havane-20101001165614-u938mdd1y1fgd0o5
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
import os, numpy, scipy, hashlib
 
3
from pycvf.core import genericnode
 
4
from pycvfext.image.datatypes import image
 
5
import Image, ImageDraw
 
6
import pylab
 
7
 
 
8
class KPDraw:
 
9
  def __init__(self,*args,**kwargs):
 
10
      self.model_node=None
 
11
  def set_model_node(self,model):
 
12
        self.model_node=model
 
13
        while (self.model_node.parent_node!=None):
 
14
           self.model_node=self.model_node.parent_node
 
15
  def on_model_destroy(self,model):
 
16
        self.model_node=None        
 
17
  def process(self,cpl):
 
18
      oimg,kpts=cpl
 
19
      oimg=numpy.require(oimg,numpy.uint8,'C')
 
20
      I=Image.fromarray(oimg) 
 
21
      draw = ImageDraw.Draw(I)
 
22
      cm=pylab.cm.jet
 
23
      
 
24
      
 
25
      for k in kpts:
 
26
         x,y=k[0],k[1]
 
27
         #print x,y         
 
28
         X,Y=x+2,y+2
 
29
         x,y=x-2,y-2
 
30
         x=max(0,min(x,oimg.shape[1]))
 
31
         y=max(0,min(y,oimg.shape[0]))
 
32
         X=max(0,min(X,oimg.shape[1]))
 
33
         Y=max(0,min(Y,oimg.shape[0]))
 
34
         z=cm(k[-1])[:3] 
 
35
         zc=(z[0]*255,z[1]*255,z[2]*255)
 
36
         #print x,y,z
 
37
         draw.ellipse( ((x,y),(X,Y)), outline=zc,fill=zc)
 
38
     
 
39
      del draw
 
40
      oimg=numpy.asarray(I)    
 
41
      return oimg
 
42
  
 
43
Node=genericnode.pycvf_node_class(None,image.Datatype())(KPDraw)
 
44
__call__=Node