Ejemplo n.º 1
0
    def getAutomatchResults(self, mission, roll, frame):
        """
        Returns existing automatch results for a given ISS ID.
        """
        centerPointSource = None
        lonNew = None
        latNew = None
        confidence = None
        
        mrf = self._missionRollFrameToMRF(mission, roll, frame)
        cmd=('SELECT centerLon, centerLat, matchConfidence, centerPointSource FROM'
             +' geocamTiePoint_automatchresults WHERE issMRF="'+mrf+'"')
        #print cmd
        rows = self._executeCommand(cmd)
        if len(rows) > 1:
            raise Exception('ERROR: Found '+ str(len(rows)) + ' entries for ' + mrf)

        if len(rows) == 1:
            print 'Found: ' + str(rows)
            lonNew = rows[0][0] # TODO: Handle null values
            latNew = rows[0][1]
            centerPointSource = rows[0][3]
            confidence = registration_common.confidenceFromString(rows[0][2])
        else:
            print 'Did not find ' + mrf + ' in our DB'
        
        return (lonNew, latNew, confidence, centerPointSource)
Ejemplo n.º 2
0
    def findNearbyGoodResults(self, timestamp, frameLimit, mission=None):
        '''Find all good results nearby a given time.
           If mission is provided restrict to the mission.'''

        # We get one set each of manual and auto results.
        # - There probably won't be too many manual results.
        MAX_TIME_DIFF = 60*30 # 30 minutes
        results = self.findNearbyManualResults(timestamp, MAX_TIME_DIFF, missionIn=mission)

        # Find the N closest frames with a maximum difference of 10 minutes.
        cmd = ('SELECT * FROM geocamTiePoint_automatchresults WHERE matchConfidence="HIGH" '
                               + ' AND abs(TIMESTAMPDIFF(second, capturedTime, "'+timestamp+'"))<1800')
        if mission:
            cmd += ' AND issMRF LIKE "%'+mission+'%"'
        cmd += ' ORDER BY abs(TIMESTAMPDIFF(second, capturedTime, "'+timestamp+'"))'
        cmd += ' LIMIT ' + str(frameLimit)
        print cmd
        rows = self._executeCommand(cmd)

        for row in rows:
            mission, roll, frame      = self._MRFToMissionRollFrame(row[2])
            confidence                = registration_common.confidenceFromString(row[4])
            resultsDict = json.loads(row[5])
            imageToProjectedTransform = self._textToTransform(resultsDict['imageToProjectedTransform'])
            imageInliers              = resultsDict['imageInliers']
            gdcInliers                = resultsDict['gdcInliers']

            results[frame] = (imageToProjectedTransform, confidence, imageInliers, gdcInliers)

        return results  
Ejemplo n.º 3
0
    def getRegistrationResult(self, mission, roll, frame):
        '''Fetches a result from the database and packs it into a dictionary'''

        # If we have a manual result, use that!
        manualResult = self.getManualRegistrationResult(mission, roll, frame)
        if manualResult:
            return manualResult

        # No manual result, check the auto results.
        mrf = self._missionRollFrameToMRF(mission, roll, frame)
        cmd = 'SELECT matchConfidence, registrationMpp, extras, centerPointSource FROM geocamTiePoint_automatchresults WHERE issMRF="'+mrf+'"'
        rows = self._executeCommand(cmd)

        if len(rows) != 1: # Data not found
            return {}
        row = rows[0]

        confidence                = registration_common.confidenceFromString(row[0])
        registrationMpp           = row[1]
        resultsDict = json.loads(row[2])
        #imageToProjectedTransform = self._textToTransform(resultsDict.imageToProjectedTransform)
        imageInliers              = resultsDict['imageInliers']
        gdcInliers                = resultsDict['gdcInliers']
        centerPointSource         = row[3]
        # Currently we don't read the date
        
        return {'confidence':confidence, 'imageInliers':imageInliers,
                'gdcInliers':gdcInliers, 'registrationMpp':registrationMpp, 
                'isManual':False, 'centerPointSource': centerPointSource}
Ejemplo n.º 4
0
 def doWeHaveResult(self, mission, roll, frame, overwriteLevel):
     '''Returns True if we have a result for the given frame, otherwise False.
        If overwriteLevel is specified, return False if we have that confidence or less'''
     self._dbCursor.execute('select CONFIDENCE from Results where MISSION=? and ROLL=? and FRAME=?',
                            (mission, roll, frame))
     rows = self._dbCursor.fetchall()
     if len(rows) != 1: # Data not found
         return False
     if not overwriteLevel:
         return True
     # Otherwise compare the level
     level = registration_common.confidenceFromString(rows[0][0])
     return (level > overwriteLevel)
Ejemplo n.º 5
0
 def findNearbyGoodResults(self, mission, roll, frame, frameLimit):
     '''Find all good results within a range of frames from a given frame'''
     
     results = dict()
     self._dbCursor.execute('select * from Results where MISSION=? and ROLL=?'
                            + ' and CONFIDENCE="HIGH"'
                            + ' and ABS(CAST(FRAME as int)-?) < ?',
                            (mission, roll, frame, frameLimit))
     rows = self._dbCursor.fetchall()
     
     for row in rows:
         frame                     = row[2]
         confidence                = registration_common.confidenceFromString(row[4])
         imageToProjectedTransform = self._textToTransform(row[5])
         imageInliers              = self._textToPoints(row[6])
         gdcInliers                = self._textToPoints(row[7])
         results[frame] = (imageToProjectedTransform, confidence, imageInliers, gdcInliers)
         
     return results
Ejemplo n.º 6
0
 def getResult(self, mission, roll, frame):
     '''Fetches a result from the database.
        Returns None if there is no data for this frame.'''
     
     self._dbCursor.execute('select * from Results where MISSION=? and ROLL=? and FRAME=?',
                            (mission, roll, frame))
     rows = self._dbCursor.fetchall()
     print rows
     if len(rows) != 1: # Data not found
         return (None, None, None, None)
     row = rows[0]
     
     confidence                = registration_common.confidenceFromString(row[4])
     imageToProjectedTransform = self._textToTransform(row[5])
     imageInliers              = self._textToPoints(row[6])
     gdcInliers                = self._textToPoints(row[7])
     # Currently we don't read the date
     
     return (imageToProjectedTransform, confidence, imageInliers, gdcInliers)
Ejemplo n.º 7
0
  def doWeHaveResult(self, mission, roll, frame, overwriteLevel=None):
      '''Returns True if we have a result for the given frame, otherwise False.
         If overwriteLevel is specified, return False if we have that confidence or less'''
      
      # If we have a manual result there will be a center point in the overlay table.
      (lonManual, latManual) = self.getManualGeorefCenterPoint(mission, roll, frame)
      if (lonManual != None) and (latManual != None):
          return True
 
      # If we don't have a manual center point, check the autoregistration results.
      mrf = self._missionRollFrameToMRF(mission, roll, frame)
      cmd=('SELECT matchConfidence FROM geocamTiePoint_automatchresults WHERE issMRF="'+mrf+'"')
      rows = self._executeCommand(cmd)
      if len(rows) != 1: # Data not found
          return False
      if not overwriteLevel:
          return True
      # Otherwise compare the level
      level = registration_common.confidenceFromString(rows[0][0])
      return (level > overwriteLevel)
def registrationProcessor(options):
    """
    The main function that gets called with options.
    """
    # Handle overwrite options
    options.overwrite = False
    if options.overwriteLevel:
        options.overwriteLevel = registration_common.confidenceFromString(options.overwriteLevel)
        options.overwrite      = True

    print '---=== Registration Processor has started ===---'

    # TODO: Turn the input DB into a full wrapper.
    sourceDb = sqlite3.connect(settings.DB_PATH)
    sourceDbCursor = sourceDb.cursor()
    georefDb = georefDbWrapper.DatabaseLogger()
    
    print 'Finished opening databases.'

    if options.printStats:
        print_stats(options, sourceDbCursor, georefDb)
        sourceDb.close()
        return 0

    # TODO: Set up logging

    # Initialize the multi-threading worker pool
    print 'Setting up worker pool with ' + str(options.numThreads) +' threads.'
    pool = multiprocessing.Pool(options.numThreads, initWorker)

    # Don't let our list of pending jobs get too enormous.
    jobLimit = options.limit
    if (jobLimit < 1) or (jobLimit > 60):
        jobLimit = 60

    readyFrames = []
    jobList  = []
    count = 0
    
    try:
        while True:
            # Wait here if our work queue is full
            sleepOnNumJobs(jobList, jobLimit)
        
            # If we are out of ready frames, find a new set.
            if not readyFrames:
                print '============================================================='
                print 'Frame update!'
                
                print 'In progress frames:'
                for job in jobList:
                    print job[0]
                
                readyFrames = findReadyImages(options, sourceDbCursor, georefDb, jobLimit)
    
                if not readyFrames:
                    print 'Registration Processor found no more data!'
                    #TODO maybe it should sleep.
                    break
    
                # Delete all frames from the readyFrames list that are already
                #  assigned to a job in the jobList.
                copyFrames = readyFrames
                for job in jobList:
                    for frame in copyFrames:
                        if job[0] == frame.getIdString():
                            print 'Remove in progress: ' + frame.getIdString()
                            readyFrames.remove(frame)

                if not readyFrames:
                    print 'Registration Processor found no more data!'
                    #TODO maybe it should sleep.
                    break

                print 'Remaining frames:'
                for frame in readyFrames:
                    print frame.getIdString()

                #if count > 0:
                #    raise Exception('DEBUG!!!')

                print '============================================================='
    
            frameInfo = readyFrames.pop() # Grab one of the ready frames from the list
    
            print 'Registration Processor assigning job: ' + frameInfo.getIdString()

            # Add this process to the processing pool
            processResult = pool.apply_async(processFrame, args=(options, frameInfo, options.localSearch))

            # Hang on to the process handle and the associated frame ID
            jobList.append((frameInfo.getIdString(), processResult))
    
            ## If that did not succeed, try to register to a local image.
            #if confidence < registration_common.CONFIDENCE_HIGH:
            #    confidence = processFrame(sourceImagePath, frameInfo, searchNearby=True)
    
            count += 1
    
            if options.frame or (options.limit and (count >= options.limit)):
                print 'Registration Processor has started processing the requested number of images.'
                break
    
    
        if pool: # Wait for all the tasks to complete
            print('Waiting for processes to complete...')
            for job in jobList:
                confidence = job[1].get()

    except KeyboardInterrupt:
        print "Caught KeyboardInterrupt, terminating workers"
        pool.terminate()
        pool.join()

    POOL_KILL_TIMEOUT = 5 # The pool should not be doing any work at this point!
    if pool:
        print('Cleaning up the processing thread pool...')
        # Give the pool processes a little time to stop, them kill them.
        pool.close()
        time.sleep(POOL_KILL_TIMEOUT)
        pool.terminate()
        pool.join()


    sourceDb.close()
    print '---=== Registration Processor has stopped ===---'