Example #1
0
    def buildZoomFrame(self):
        ''' create a zoom_img (that gets attached to -> self.zoomFrame) based on zoomRect.
            we're concerned with modulo-zero resizes in here, when the zoomFrame is below
            a certain size.
        '''

        if self.zoomRect is None:
            
            #TODO - only create this once
            zoom_img = np.zeros(self.frame.shape)
            zoom_img = draw_text(zoom_img, "n/a")
        
        else:
            
            zoom_img = crop_img( self.getOrigFrame()
                                ,self.absRect(
                                    tuple( 
                                     self.scaleMainToOrig(p) for p in self.zoomRect
                                        )
                                    )
                                )
            
            # this does not alter pixels, it is still directly derived
            # from origFrame
        
        widthZoom, heightZoom = self.widthZoomWindow,self.heightZoomWindow
        
        if self.zoomRect is not None:
            
            if any(map(lambda x: x < self.modZeroSize, 
                        self.rectMainToOrig(self.zoomRect)[2:4])):

                # find a whole number multiple of zoomRect into 320,
                # use that for resize factor
                widthZoom = int( int(self.widthZoomWindow / self.zoomRect[2]) 
                                      * self.zoomRect[2])
        
        if zoom_img.shape[0] < 1 or zoom_img.shape[1] < 1:
            #sanity check / temporary hack. really shouldn't get here
            # self.zoomRect = None
            # return None
            zoom_img = np.zeros(self.frame.shape)
            zoom_img = draw_text(zoom_img, "n/a")
        
        zoom_img  = resize_img(zoom_img, True, (widthZoom, heightZoom))

        # resize_img always (?) choses width to resize by, and maintains aspect ratio.
        # Since the zoom_img is always resize larger, if modulo == 0, then every pixel
        # is (presumably?) scaled the exact same amount e.g. 3.0x increase has a 1 pixel 
        # becoming a 3x3 square of the same data-values.
        
        return zoom_img
Example #2
0
    def buildScoreFrame(self):
        ''' create a score_img (that gets attached to -> self.scoreFrame) based on scoreRect.
            this is a clone of buildZoomFrame()
        '''

        if self.scoreRect is None:
            
            score_img = np.zeros(self.frame.shape, dtype='uint8')
            score_img = draw_text(score_img, "n/a")
        
        else:
            
            score_img = crop_img( self.getOrigFrame()
                                  ,self.absRect(
                                    tuple( 
                                     self.scaleMainToOrig(p) for p in self.scoreRect
                                        )
                                    )
                                )
        
        widthZoom, heightZoom = self.widthZoomWindow,self.heightZoomWindow

        if self.scoreRect is not None:
            
            if any(map(lambda x: x < self.modZeroSize, 
                        self.rectMainToOrig(self.scoreRect)[2:4])):

                #still ensure mod0 in score window
                widthZoom = int( int(self.widthZoomWindow / self.scoreRect[2]) 
                                      * self.scoreRect[2])
        
        if score_img.shape[0] < 1 or score_img.shape[1] < 1:
            score_img = np.zeros(self.frame.shape)
            score_img = draw_text(score_img, "n/a")
        
        score_img  = resize_img(score_img, True, (widthZoom, heightZoom))

        return score_img
Example #3
0
    def alterScoreFrame(self):
        ''' make annotation to scoreFrame, but not resize; 
            need to call this each time you do a buildScoreFrame().        
        '''        

        if self.scoreRect is None or self.scoreFrame is None:
            return

        msg = str(self.scoreFrame.shape[:2])
        msg += " <- "
        msg += str(self.rectMainToOrig(self.scoreRect)[2:4][::-1])
        
        if self.scoreFrame.shape[1] % self.rectMainToOrig(self.scoreRect)[2] == 0:
            msg += " mod0"
        
        if self.zoomAnnotateSize:
            self.scoreFrame = draw_text(self.scoreFrame, msg, fontscale = 0.5
                                       ,color= (0,0,0), b_bottom=True)
Example #4
0
    def drawOntoPane(self, frame, data, coordsRelative, color, thick, b_annotate=False):
        ''' draw both circle and ray shapes within [score]data onto a frame here:

                frame - (np.array) reference to the frame to be dwarn upon
                data - (ScoreSchema) either inputScore or outputScore
                coordsRelative (str) the type of coords transform to perform before draw
                color (str), thick (int) - formatting params
        '''

        for _circleObj in data.getListType('circle'):

            _circleEnum, _circleData = _circleObj
                
            if coordsRelative == 'origToMain':
                rect = self.roiToMain(input_rect = _circleData)
            
            elif coordsRelative == 'origToZoom':
                rect = self.roiToZoom(input_rect = _circleData)

            elif coordsRelative == 'origToScore':
                rect = self.roiToScore(input_rect= _circleData)

            x, y, radius = self.rectToCircle(rect)
        
            frame = draw_circle(frame
                                ,x
                                ,y
                                ,radius
                                ,color = color
                                ,thick = thick
                                )
            
            if b_annotate:
                frame = draw_text(frame
                                 ,msg = str(_circleEnum)
                                 ,fontscale = 0.5
                                 ,color = convert_color(color)
                                 ,pos = self.annotatePointFromRect(rect)
                                 )
                

        for _rayObj in data.getListType('ray'):
                
            _rayEnum, _rayData = _rayObj
            
            if coordsRelative == 'origToMain':
                xy0 = tuple(self.scaleOrigToMain(x) for x in _rayData[0])
                xy1 = tuple(self.scaleOrigToMain(x) for x in _rayData[1])
            elif coordsRelative == 'origToZoom':
                xy0 = self.pointOrigToZoom(_rayData[0])
                xy1 = self.pointOrigToZoom(_rayData[1])
            elif coordsRelative == 'origToScore':
                xy0 = self.pointOrigToScore(_rayData[0])
                xy1 = self.pointOrigToScore(_rayData[1])
        
            frame = draw_ray(frame
                            ,xy0
                            ,xy1
                            ,color = color
                            ,thick = thick
                            #TODO - bOffsetRay so you can see the motion blur
                            )
            
            if b_annotate:
                frame = draw_text(frame
                                 ,msg = str(_rayEnum)
                                 ,fontscale = 0.5
                                 ,color = convert_color(color)
                                 ,pos = self.annotatePointFromRect(
                                            self.pointsToRelativeRect(xy0, xy1)
                                            )
                                 )
Example #5
0
    def alterFrame(self):
        ''' make changes to frame, including resize. also, build zoomFrame and scoreFrame.
            need to call this every new frame and on resetOperators
        '''        
        
        if self.frameResize:
            self.frame = resize_img(self.frame, True, 
                                    (self.widthMainWindow,self.heightMainWindow))

        if self.frameAnnotateFn:
            self.frame = draw_text(self.frame, self.annotateMsg)

        #TODO
        # if self.frameAnnotateTrackSuccess:
        #     _color = 'blue' if self.circleTrack is not None else 'red'
        #     self.frame = draw_rect(self.frame, (2,2,10,10), color = _color)

        if not(self.scoreOff):
            
            protoZoomRect = None
            
            
            if self.inputScore.getData(self.scoreDisplayObjEnum) is not None:               
                protoZoomRect = self.inputScore.getObjRect(self.scoreDisplayObjEnum)
                zoomFct = 0.1
                
            elif self.trackScore.checkHasContents():    
                protoZoomRect = self.trackScore.getObjRect(self.scoreDisplayObjEnum)
                zoomFct = 0.3   

            if self.zoomFct is not None:
                zoomFct = self.zoomFct
            
            if protoZoomRect is None:
                self.scoreRect = None
            
            elif protoZoomRect[2] < 1 or protoZoomRect[3] < 1:
                self.scoreRect = None
                
            else:

                protoZoomRect = self.minDimsForRect(
                                             protoZoomRect
                                            ,self.getOrigFrameDims()
                                            ,min_scalar_width = 10
                                            ,max_multiple_width = 3
                                                    )

                self.scoreRect =  self.rectOrigToMain(
                                    self.zoomInRect( protoZoomRect
                                                    ,b_zoomout = True
                                                    ,zoomFct = zoomFct
                                                    )
                                                )

        if self.zoomOn: 
            self.zoomFrame = self.buildZoomFrame()
            self.alterZoomFrame()

        if ((self.scoreOn and not(self.scoreOff) and self.bShowScoring)
            or self.trackOn):
            self.scoreFrame = self.buildScoreFrame()
            self.alterScoreFrame()