def ShowImage( self, evt=None ):
        
        """Draw circle on a color image (MxNx3 numpy array)."""

        #circlecolor = (0,0,0)
        #centercolor = (1,1,1,1)
        #edgecolor = (0,0,0,1)
        circlecolor = (255,0,0)
        centercolor = (0,1,0,1)
        edgecolor = (1,1,0,1)
        
        x = self.arena_center_x
        y = self.arena_center_y
        r = self.arena_radius
        edgepoint = self.edgepoint

        if edgepoint is None:
            edgepoint = [x+r,y]

        pointlist = [[x,y],edgepoint]
        pointcolors = [centercolor,edgecolor]
        pointsizes = [DCLICK/2,DCLICK/2]
        linesegs = imagesk.draw_circle(x,y,r,color=circlecolor)
        circlewidths = [CIRCLEWIDTH]*len(linesegs)
        (linesegs,linecolors) = imagesk.separate_linesegs_colors(linesegs)
        #img_8 = imagesk.double2mono8(self.image_shown,donormalize=True)
        self.img_wind.update_image_and_drawings('setarena',self.image_shown,
                                                format="RGB8",
                                                linesegs=linesegs,
                                                lineseg_colors=linecolors,
                                                points=pointlist,
                                                point_colors=pointcolors,
                                                point_radii=pointsizes,
                                                lineseg_widths=circlewidths)
        self.img_wind.Refresh(eraseBackground=False)
Exemple #2
0
    def ShowImage(self, evt=None):
        """Draw circle on a color image (MxNx3 numpy array)."""

        #circlecolor = (0,0,0)
        #centercolor = (1,1,1,1)
        #edgecolor = (0,0,0,1)
        circlecolor = (255, 0, 0)
        centercolor = (0, 1, 0, 1)
        edgecolor = (1, 1, 0, 1)

        x = self.arena_center_x
        y = self.arena_center_y
        r = self.arena_radius
        edgepoint = self.edgepoint

        if edgepoint is None:
            edgepoint = [x + r, y]

        pointlist = [[x, y], edgepoint]
        pointcolors = [centercolor, edgecolor]
        pointsizes = [DCLICK / 2, DCLICK / 2]
        linesegs = imagesk.draw_circle(x, y, r, color=circlecolor)
        circlewidths = [CIRCLEWIDTH] * len(linesegs)
        (linesegs, linecolors) = imagesk.separate_linesegs_colors(linesegs)
        #img_8 = imagesk.double2mono8(self.image_shown,donormalize=True)
        self.img_wind.update_image_and_drawings('setarena',
                                                self.image_shown,
                                                format="RGB8",
                                                linesegs=linesegs,
                                                lineseg_colors=linecolors,
                                                points=pointlist,
                                                point_colors=pointcolors,
                                                point_radii=pointsizes,
                                                lineseg_widths=circlewidths)
        self.img_wind.Refresh(eraseBackground=False)
    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)
Exemple #4
0
    def ShowImage(self):

        if DEBUG_TRACKINGSETTINGS: print 'ShowImage ' + str(self.show_frame)

        try:
            wx.Yield()
        except:
            pass  # can be recursive sometimes in Windows
        wx.BeginBusyCursor()
        im, stamp = self.bg_imgs.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:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_UNFILTERED_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            plot_linesegs = draw_ellipses(obs_unfiltered)

        elif self.img_chosen == SHOW_FILTERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_FILTERED_OBSERVATIONS'
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = draw_ellipses(obs_filtered)

        elif self.img_chosen == SHOW_SMALL_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print '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 = draw_ellipses(obs_small)

        elif self.img_chosen == SHOW_LARGE_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print '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 = draw_ellipses(obs_large)

        elif self.img_chosen == SHOW_DELETED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_DELETED_OBSERVATIONS'
            (obs_unfiltered, obs_deleted) = self.GetObsUnfiltered('diddelete')
            plot_linesegs = draw_ellipses(obs_deleted)

        elif self.img_chosen == SHOW_SPLIT_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_SPLIT_OBSERVATIONS'
            (obs_unfiltered, obs_split) = self.GetObsUnfiltered('didsplit')
            plot_linesegs = draw_ellipses(obs_split)

        elif self.img_chosen == SHOW_MERGED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MERGED_OBSERVATIONS'
            (obs_unfiltered, obs_merge) = self.GetObsUnfiltered('didmerge')
            plot_linesegs = draw_ellipses(obs_merge)

        elif self.img_chosen == SHOW_LOWERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_LOWERED_OBSERVATIONS'
            (obs_unfiltered,
             obs_lowered) = self.GetObsUnfiltered('didlowerthresh')
            plot_linesegs = draw_ellipses(obs_lowered)

        # MAXJUMP
        elif self.img_chosen == SHOW_MAXJUMP:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MAXJUMP'

            # either grab or compute observations
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = 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 * 2.,
                    params.params.colors[i % len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)
                plot_new_stuff = imagesk.draw_circle(
                    obs.center.x, obs.center.y, params.params.min_jump,
                    params.params.colors[i % len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)

        elif self.img_chosen == SHOW_MOTIONMODEL:
            if DEBUG_TRACKINGSETTINGS: print '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 = self.bg_imgs.movie.get_frame(nextframe)

            # draw previous positions
            plot_linesegs = draw_ellipses(target_prev)

            # draw current positions
            plot_new_stuff = draw_ellipses(target_curr)
            plot_linesegs.extend(plot_new_stuff)

            # draw predicted positions
            plot_new_stuff = 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)

        if self.info == True:
            self.ShowInfo(None, None)

        wx.EndBusyCursor()

        if DEBUG_TRACKINGSETTINGS: sys.stdout.flush()