Beispiel #1
0
def annotate_image( ellipses=None, old_pts=None, thickness=params.ellipse_thickness ):
    """Draw stuff on image."""

    # draw ellipses
    if ellipses is None:
        linesegs = []
    else:
        linesegs = draw_ellipses( ellipses )

    # draw tails
    if old_pts is not None:

        prevpts = {}
        for frame_pts in old_pts:
            for pt in frame_pts:
                if prevpts.has_key(pt[2]):
                    prevpt = prevpts[pt[2]]
                    color = params.colors[pt[2]%len(params.colors)]
                    linesegs.append([prevpt[0]+1,prevpt[1]+1,
                                     pt[0]+1,pt[1]+1,color])
                prevpts[pt[2]] = pt[0:2]

    return linesegs
    def ShowImage(self):

        im, stamp = params.params.movie.get_frame( int(self.show_frame) )
        windowsize = [self.img_panel.GetRect().GetHeight(),self.img_panel.GetRect().GetWidth()]

        self.GetBgImage()
            
        if self.img_chosen == SHOW_UNFILTERED_OBSERVATIONS:
            obs_unfiltered = self.GetObsUnfiltered()
            plot_linesegs = ell.draw_ellipses(obs_unfiltered)
            
        elif self.img_chosen == SHOW_FILTERED_OBSERVATIONS:
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = ell.draw_ellipses(obs_filtered)
            
        elif self.img_chosen == SHOW_SMALL_OBSERVATIONS:
            obs_unfiltered = self.GetObsUnfiltered()
            obs_small = []
            for obs in obs_unfiltered:
                if obs.area < params.params.minshape.area:
                    obs_small.append(obs)
            plot_linesegs = ell.draw_ellipses(obs_small)
            
        elif self.img_chosen == SHOW_LARGE_OBSERVATIONS:
            obs_unfiltered = self.GetObsUnfiltered()
            obs_large = []
            for obs in obs_unfiltered:
                if obs.area > params.params.maxshape.area:
                    obs_large.append(obs)
            plot_linesegs = ell.draw_ellipses(obs_large)

        elif self.img_chosen == SHOW_DELETED_OBSERVATIONS:
            (obs_unfiltered,diddelete) = self.GetObsUnfiltered('diddelete')
            obs_deleted = []
            for (i,v) in enumerate(diddelete):
                if v: obs_deleted.append(obs_unfiltered[i])
            plot_linesegs = ell.draw_ellipses(obs_deleted)

        elif self.img_chosen == SHOW_SPLIT_OBSERVATIONS:
            (obs_unfiltered,didsplit) = self.GetObsUnfiltered('didsplit')
            colors = []
            obs_split = []
            for (i,v) in enumerate(didsplit):
                if len(v)>1:
                    for j in v:
                        colors.append(params.params.colors[i % len(params.params.colors)])
                        obs_split.append(obs_unfiltered[j])
            plot_linesegs = ell.draw_ellipses(obs_split)

        elif self.img_chosen == SHOW_MERGED_OBSERVATIONS:
            (obs_unfiltered,didmerge) = self.GetObsUnfiltered('didmerge')
            colors = []
            obs_merge = []
            for (i,v) in enumerate(didmerge):
                if len(v)>1:
                  obs_merge.append(obs_unfiltered[i])
            plot_linesegs = ell.draw_ellipses(obs_merge)

        elif self.img_chosen == SHOW_LOWERED_OBSERVATIONS:
            (obs_unfiltered,didlowerthresh) = self.GetObsUnfiltered('didlowerthresh')
            obs_lowered = []
            for (i,v) in enumerate(didlowerthresh):
                if v: obs_lowered.append(obs_unfiltered[i])
            plot_linesegs = ell.draw_ellipses(obs_lowered)

        # MAXJUMP
        elif self.img_chosen == SHOW_MAXJUMP:

            # either grab or compute observations
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = ell.draw_ellipses(obs_filtered)

            # draw circles
            for i,obs in enumerate(obs_filtered):
                plot_new_stuff = imagesk.draw_circle(obs.center.x,
                                                     obs.center.y,params.params.max_jump,
                                                     params.params.colors[i%len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)
                

        elif self.img_chosen == SHOW_MOTIONMODEL:

            (target_prev,target_curr,target_pred) = self.GetTargetMotion()

            # show the next frame, if there is one
            nextframe = num.minimum(int(self.show_frame+1),params.params.n_frames-1)
            im, stamp = params.params.movie.get_frame(nextframe)

            # draw previous positions
            plot_linesegs = ell.draw_ellipses(target_prev)

            # draw current positions
            plot_new_stuff = ell.draw_ellipses(target_curr,colors=[[255,255,0]])
            plot_linesegs.extend(plot_new_stuff)

            # draw predicted positions
            plot_new_stuff = ell.draw_ellipses(target_pred)
            plot_linesegs.extend(plot_new_stuff)

            scaleunit = params.params.max_jump / params.params.DRAW_MOTION_SCALE
            parcolor = [0,255,0]
            perpcolor = [0,255,0]
            anglecolor = [0,0,255]

            for i in target_pred.iterkeys():
                # compute direction of motion
                vx = target_pred[i].center.x - target_curr[i].center.x
                vy = target_pred[i].center.y - target_curr[i].center.y
                thetamotion = num.arctan2(vy,vx)

                # angle
                theta = target_pred[i].angle
                
                # we want to choose to add pi if that makes difference from motion direction smaller
                dtheta = abs( ((theta - thetamotion + num.pi) % (2.*num.pi)) - num.pi )
                if dtheta > (num.pi/2.):
                    theta += num.pi

                # compute end points of parallel motion
                x0 = target_pred[i].center.x + scaleunit*num.cos(theta)
                x1 = target_pred[i].center.x - scaleunit*num.cos(theta)
                y0 = target_pred[i].center.y + scaleunit*num.sin(theta)
                y1 = target_pred[i].center.y - scaleunit*num.sin(theta)

                # add parallel motion annotation line
                plot_new_stuff = imagesk.draw_line(x0+1,y0+1,x1+1,y1+1,parcolor)
                plot_linesegs.extend(plot_new_stuff)

                # compute end points of perpendicular motion
                x0 = target_pred[i].center.x + scaleunit*num.cos(num.pi/2.+theta)
                x1 = target_pred[i].center.x - scaleunit*num.cos(num.pi/2.+theta)
                y0 = target_pred[i].center.y + scaleunit*num.sin(num.pi/2.+theta)
                y1 = target_pred[i].center.y - scaleunit*num.sin(num.pi/2.+theta)
                
                # add perpendicular motion annotation line
                plot_new_stuff = imagesk.draw_line(x0+1,y0+1,x1+1,y1+1,perpcolor)
                plot_linesegs.extend(plot_new_stuff)
                

                # compute end points of angular motion
                if params.params.ang_dist_wt > 0:
                    
                    dtheta = scaleunit*num.sqrt(1./params.params.ang_dist_wt)
                    if dtheta >= (num.pi/2.):
                        print 'dtheta is more than pi/2'
                    else:
                        theta0 = theta - dtheta
                        theta1 = theta + dtheta
                        
                        # draw arc
                        plot_new_stuff = imagesk.draw_arc(target_pred[i].center.x,
                                                          target_pred[i].center.y,
                                                          scaleunit/2,
                                                          theta0,theta1,
                                                          anglecolor)
                        plot_linesegs.extend(plot_new_stuff)
                   
        im = imagesk.double2mono8(im,donormalize=False)
        linesegs,im = imagesk.zoom_linesegs_and_image(plot_linesegs,im,self.zoomaxes)
        (linesegs,linecolors) = imagesk.separate_linesegs_colors(linesegs)
        
        self.img_wind.update_image_and_drawings('trackset',
                                                im,
                                                format='MONO8',
                                                linesegs=linesegs,
                                                lineseg_colors=linecolors
                                                )

        self.img_wind.Refresh(eraseBackground=False)

        self.frame_number_text.SetLabel('Frame %d'%self.show_frame)