コード例 #1
0
    def redraw(self,eraseBackground=False):
        """Scale data and draw on window."""

        if (not hasattr(self,'ellipse')) or \
           (not hasattr(self.ellipse,'hasItem')):
            return

        ind = self.spinner.GetValue()
        if not self.ellipse.hasItem(ind):
            blank = num.ones( (params.zoom_window_pix,
                               params.zoom_window_pix), num.uint8 )*127
            self.window.update_image_and_drawings(self.name,blank,format='MONO8')
        else:
            # get box around ellipse
            valx = self.ellipse[ind].center.x - params.zoom_window_pix/2
            valx = max( valx, 0 )
            valx = min( valx, self.data.shape[1] - params.zoom_window_pix )
            valy = self.ellipse[ind].center.y - params.zoom_window_pix/2
            valy = max( valy, 0 )
            valy = min( valy, self.data.shape[0] - params.zoom_window_pix )
            self.offset = (valx,valy)
            zoomaxes = [self.offset[0],self.offset[0]+params.zoom_window_pix-1,
                        self.offset[1],self.offset[1]+params.zoom_window_pix-1]
            linesegs = draw_ellipses([self.ellipse[ind],],
                                     colors=[params.colors[ind%len(params.colors)],])
            im = imagesk.double2mono8(self.data,donormalize=False)
            linesegs,im = imagesk.zoom_linesegs_and_image(linesegs,im,zoomaxes)
            (linesegs,linecolors) = imagesk.separate_linesegs_colors(linesegs)
            self.window.update_image_and_drawings(self.name,im,format='MONO8',
                                                  linesegs=linesegs,lineseg_colors=linecolors)
            self.window.Refresh( eraseBackground=eraseBackground )
コード例 #2
0
    def redraw(self,eraseBackground=False):
        """Scale data and draw on window."""

        ind = self.spinner.GetValue()

        if self.ellipse_size is None:
            wind_size = DEFAULT_WIND_SIZE
        else:
            wind_size = self.ellipse_size
        
        if not self.ellipses.hasItem(ind):
            blank = num.ones( (self.data.shape[0],self.data.shape[1]), num.uint8 )*127
            self.window.update_image_and_drawings(self.name,blank,format='MONO8')
        else:
            # get box around ellipse
            valx = self.ellipses[ind].center.x - self.ellipse_size/2
            valx = max( valx, 0 )
            valx = min( valx, self.data.shape[1] - self.ellipse_size )
            valy = self.ellipses[ind].center.y - self.ellipse_size/2
            valy = max( valy, 0 )
            valy = min( valy, self.data.shape[0] - self.ellipse_size )
            self.offset = (valx,valy)
            zoomaxes = [self.offset[0],self.offset[0]+self.ellipse_size-1,
                        self.offset[1],self.offset[1]+self.ellipse_size-1]
            linesegs = draw_ellipses([self.ellipses[ind],],
                                     colors=[params.colors[ind%len(params.colors)],])
            im = imagesk.double2mono8(self.data,donormalize=False)
            linesegs,im = imagesk.zoom_linesegs_and_image(linesegs,im,zoomaxes)
            (linesegs,linecolors) = imagesk.separate_linesegs_colors(linesegs)
            self.window.update_image_and_drawings(self.name,im,format='MONO8',
                                                  linesegs=linesegs,lineseg_colors=linecolors)
            self.window.Refresh( eraseBackground=eraseBackground )
コード例 #3
0
    def redraw(self, eraseBackground=False):
        """Scale data and draw on window."""
        if self.window.GetRect().GetHeight() < 1: return

        ind = self.spinner.GetValue()

        if self.ellipse_size is None:
            wind_size = DEFAULT_WIND_SIZE
        else:
            wind_size = self.ellipse_size

        if not self.ellipses.hasItem(ind):
            blank = num.ones(
                (self.data.shape[0], self.data.shape[1]), num.uint8) * 127
            self.window.update_image_and_drawings(self.name,
                                                  blank,
                                                  format='MONO8')
        else:
            # get box around ellipse
            valx = self.ellipses[ind].center.x - self.ellipse_size / 2
            valx = max(valx, 0)
            valx = min(valx, self.data.shape[1] - self.ellipse_size)
            valy = self.ellipses[ind].center.y - self.ellipse_size / 2
            valy = max(valy, 0)
            valy = min(valy, self.data.shape[0] - self.ellipse_size)
            self.offset = (valx, valy)
            zoomaxes = [
                self.offset[0], self.offset[0] + self.ellipse_size - 1,
                self.offset[1], self.offset[1] + self.ellipse_size - 1
            ]
            linesegs = draw_ellipses(
                [self.ellipses[ind]],
                colors=[params.colors[ind % len(params.colors)]])

            # add tail, if checked
            if self.show_tail:
                ax = self.ellipse_size * num.cos(self.ellipses[ind].angle)
                ay = self.ellipse_size * num.sin(self.ellipses[ind].angle)
                linesegs.append([
                    self.ellipses[ind].center.x, self.ellipses[ind].center.y,
                    self.ellipses[ind].center.x - ax,
                    self.ellipses[ind].center.y - ay,
                    params.colors[ind % len(params.colors)]
                ])

            im = imagesk.double2mono8(self.data, donormalize=False)
            linesegs, im = imagesk.zoom_linesegs_and_image(
                linesegs, im, zoomaxes)
            (linesegs, linecolors) = imagesk.separate_linesegs_colors(linesegs)
            linewidths = (params.ellipse_thickness, ) * len(linesegs)
            self.window.update_image_and_drawings(self.name,
                                                  im,
                                                  format='MONO8',
                                                  linesegs=linesegs,
                                                  lineseg_colors=linecolors,
                                                  lineseg_widths=linewidths)
            self.window.Refresh(eraseBackground=eraseBackground)
コード例 #4
0
    def redraw(self, eraseBackground=False):
        """Scale data and draw on window."""

        ind = self.spinner.GetValue()

        if self.ellipse_size is None:
            wind_size = DEFAULT_WIND_SIZE
        else:
            wind_size = self.ellipse_size

        if not self.ellipses.hasItem(ind):
            blank = num.ones(
                (self.data.shape[0], self.data.shape[1]), num.uint8) * 127
            self.window.update_image_and_drawings(self.name,
                                                  blank,
                                                  format='MONO8')
        else:
            # get box around ellipse
            valx = self.ellipses[ind].center.x - self.ellipse_size / 2
            valx = max(valx, 0)
            valx = min(valx, self.data.shape[1] - self.ellipse_size)
            valy = self.ellipses[ind].center.y - self.ellipse_size / 2
            valy = max(valy, 0)
            valy = min(valy, self.data.shape[0] - self.ellipse_size)
            self.offset = (valx, valy)
            zoomaxes = [
                self.offset[0], self.offset[0] + self.ellipse_size - 1,
                self.offset[1], self.offset[1] + self.ellipse_size - 1
            ]
            linesegs = draw_ellipses([
                self.ellipses[ind],
            ],
                                     colors=[
                                         params.colors[ind %
                                                       len(params.colors)],
                                     ])
            im = imagesk.double2mono8(self.data, donormalize=False)
            linesegs, im = imagesk.zoom_linesegs_and_image(
                linesegs, im, zoomaxes)
            (linesegs, linecolors) = imagesk.separate_linesegs_colors(linesegs)
            self.window.update_image_and_drawings(self.name,
                                                  im,
                                                  format='MONO8',
                                                  linesegs=linesegs,
                                                  lineseg_colors=linecolors)
            self.window.Refresh(eraseBackground=eraseBackground)
コード例 #5
0
    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)
コード例 #6
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()