Пример #1
0
def is_scene_separable(diff,fps,program_mode,check_mode,img1,img2):
    if diff>1: return True
    DIST_TRESH = None
    TIMEDIFF_TRESH = None
    DISTANCE_TRESH_CHECK_SIFT = None
    if program_mode == 'scenes': 
        DIST_TRESH = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_SCENECUT
        TIMEDIFF_TRESH = settings.TIMEDIFF_TRESH_MODE_SCENECUT
        DISTANCE_TRESH_CHECK_SIFT = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_SCENECUT_CHECK_SIFT
    elif program_mode == 'joined': 
        DIST_TRESH = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_JOINCUT
        TIMEDIFF_TRESH = settings.TIMEDIFF_TRESH_MODE_JOINCUT
        DISTANCE_TRESH_CHECK_SIFT = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_JOINCUT_CHECK_SIFT
        
    results = []
        
    if 'time_diff' in check_mode:
        time_diff = frame_diff_to_milisecs(diff,fps)
        if time_diff>(float(TIMEDIFF_TRESH)*1000.0):
            results.append(True)
        else:
            results.append(False)
    
    was_separated_by_dist = False
    if 'dist' in check_mode:
        dist = img1.get_distance(img2,from_object=True)
        # print 'img1',img1.get_only_num(),'img2',img2.get_only_num(),'dist',dist,'DIST_TRESH',DIST_TRESH
        if dist > DIST_TRESH:
            was_separated_by_dist = True
            results.append(True)
        else:
            results.append(False)

    if 'sift' in check_mode and img1 and img2:
        if not was_separated_by_dist:
            dist = img1.get_distance(img2,from_object=True)
            if dist > DISTANCE_TRESH_CHECK_SIFT:
                img1 = prepare_img_for_sift(img1)
                img2 = prepare_img_for_sift(img2)
                loc_desc1 = (img1.loc, img1.desc)
                loc_desc2 = (img2.loc, img2.desc)
                im1, im2, mscores,qom,mpercent = get_kpm(loc_desc1, loc_desc2, mode='only_match')
                # print 'img1',img1.get_only_num(),'img2',img2.get_only_num(),'qom',qom,'QOM_MINIMUM_SCENECUT',settings.QOM_MINIMUM_SCENECUT
                if qom < settings.QOM_MINIMUM_SCENECUT:
                    results.append(True)
                else:
                    results.append(False)            
                
    if 'AND' in check_mode:
        if False in results: return False
        else: return True
    if 'OR' in check_mode:
        if True in results: return True
        else: return False
Пример #2
0
 def SIFT_matching(self,objects_num,verbose):
     ########### SIFT 
     # minden kepet osszehasonlitok a settingsben beallitott mennyiseguvel/modon..
     if verbose:print '\nSIFT reclustering..'
             
     
     total_attempts = objects_num
     # objektum egyezesek keresese
     if verbose:print '\nSearching for SIFT matchings...'
     LS = settings.LESS_MATCHES_ATTEMPT_SOURCE
     LC = settings.LESS_MATCHES_ATTEMPT_COMPARED
     S=1
     C=1
     if LS>1: S = int(math.ceil(1.0*total_attempts/(1.0*LS)))
     else: S = total_attempts
     if LC>1: C = int(math.ceil(1.0*(total_attempts)/(1.0*LC)))
     else: C = total_attempts
     if LS<2: LS = 0        
     if LC<2: LC = 0
     
     total_attempts = (S*(C-1))/2
     co = 0
     
     # egyelore mindet mindennel (kiveve magaval)
     # lehetne maskepp, pl mindet csak ref pointokkal
     matches_num = 0
     for counter_source_cluster, cluster in enumerate(self.clusters):            
         for counter_source, source in enumerate(cluster):                
             if (LS==0 or (LS!=0 and counter_source % LS == 0)):
                 for counter_compared_cluster, cluster2 in enumerate(self.clusters):            
                     for counter_compared, compared in enumerate(cluster2):
                         if source.get_only_filename() != compared.get_only_filename():
                             if (LC==0 or (LC!=0 and counter_compared % LC == 0)):
                                 # ha meg ez a source file nem volt osszehasonlitva a compareddel
                                 # k*(k-1)/2 osszehasonlitas, teljes graf. odavissza nem hasonlitok...kicsi ertelme lehetne SIFT miatt talan,
                                 # de igy fele annyi futasi ido
                                 if not source.get_only_filename() in compared.was_matched_with:
                                     co += 1
                                     print '\n(', co, 'of approx.', total_attempts, ') matching attempt'
                                     loc_desc1 = (source.loc, source.desc)
                                     loc_desc2 = (compared.loc, compared.desc)
                                     im1, im2, mscores,qom,mpercent = get_kpm(loc_desc1, loc_desc2, mode='only_match')
                                     if qom > settings.QOM_minimum:
                                         if verbose: print 'matched images:', source.get_only_filename(), '<->', compared.get_only_filename()
                                         matches_num += 1
                                         if source.matching_qom:
                                             if source.matching_qom < qom:
                                                 if verbose: print 'Better QOM image match found'
                                                 source.matched = compared
                                                 source.matching_qom = qom                                                    
                                         else:
                                             source.matched = compared
                                             source.matching_qom = qom                                
                                     if source.matched and (source.matched.get_only_filename() == compared.get_only_filename()):
                                         if source.matching_qom <= qom:    
                                             if not source.matched in cluster:
                                                 # mikor rakjuk at masik clusterbe?:
                                                 '''
                                                 dist_fromClusterRefpoint = source.get_distance(self.get_ref_point(cluster))
                                                 dist_toClusterRefpoint = source.get_distance(self.get_ref_point(cluster2))
                                                 '''
                                                 # print cluster[0].get_only_filename(),dist_fromClusterRefpoint,cluster2[0].get_only_filename(),dist_toClusterRefpoint
                                                 '''if dist_fromClusterRefpoint > dist_toClusterRefpoint:'''
                                                 if verbose: print "* Image flagged to move"                                                    
                                                 source.flag_move_from_clusternum = counter_source_cluster
                                                 source.flag_move_to_clusternum = counter_compared_cluster
                                 source.was_matched_with.append(compared.get_only_filename())                                  
                                 
     # reclustering
     # moving flagged objects to the right cluster
     moved = 0
     for counter_cluster, cluster in enumerate(self.clusters):
         for counter_image, image in enumerate(cluster):
             if image.flag_move_to_clusternum and (image.flag_move_to_clusternum != counter_cluster):
                 moved += 1
                 # TODO: melyiket rakjam melyikbe? mi alapjan? cluster meretek? tav a centroidtol?
                 # ha 1 marad csak a clusterben, azt is inkabb elrakjam?
                 # 1 meret clusterek a legnagyobb QOMeshez at?
                 img_to_move = cluster.pop(counter_image)                
                 self.clusters[image.flag_move_to_clusternum].append(img_to_move)
     if verbose: print '\n\nMoving', moved, 'images to other clusters done'
                         
     if verbose:print 'Found SIFT matchings SUM:', matches_num
     if verbose:print '\nSearching for SIFT matchings done'        
     
     if verbose:print 'SIFT reclustering ended\n'
Пример #3
0
def are_scenes_joinable(diff,fps,dist,program_mode,check_mode,img1=None,img2=None, length_diff=None,similar_check=False):
    # h nem-e lognak egymasba
    if diff > 0:        
        DIST_TRESH = None
        TIMEDIFF_TRESH = None
        DISTANCE_TRESH_CHECK_SIFT = None
        if program_mode == 'scenes': 
            DIST_TRESH = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_SCENECUT
            if similar_check:
                DIST_TRESH = settings.CLUSTER_DISTANCE_TRESHOLD_SIMILAR_CHECK
            TIMEDIFF_TRESH = settings.TIMEDIFF_TRESH_MODE_SCENECUT
            LENGTH_TRESH = settings.LENGTH_TRESH_MODE_SCENECUT
            DISTANCE_TRESH_CHECK_SIFT = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_SCENECUT_CHECK_SIFT
        elif program_mode == 'joined': 
            DIST_TRESH = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_JOINCUT
            if similar_check:
                DIST_TRESH = settings.CLUSTER_DISTANCE_TRESHOLD_SIMILAR_CHECK
            TIMEDIFF_TRESH = settings.TIMEDIFF_TRESH_MODE_JOINCUT
            LENGTH_TRESH = settings.LENGTH_TRESH_MODE_JOINCUT
            DISTANCE_TRESH_CHECK_SIFT = settings.CLUSTER_DISTANCE_TRESHOLD_MODE_JOINCUT_CHECK_SIFT
        
        results = []
        
        was_joined_by_dist = False
        if 'dist' in check_mode:
            if dist < DIST_TRESH:
                results.append(True)
                was_joined_by_dist = True
            else:
                results.append(False)
        
        if 'sift' in check_mode and img1 and img2:
            if not was_joined_by_dist:
                dist = img1.get_distance(img2,from_object=True)
                if dist > DISTANCE_TRESH_CHECK_SIFT:
                    img1 = prepare_img_for_sift(img1)
                    img2 = prepare_img_for_sift(img2)
                    loc_desc1 = (img1.loc, img1.desc)
                    loc_desc2 = (img2.loc, img2.desc)
                    im1, im2, mscores,qom,mpercent = get_kpm(loc_desc1, loc_desc2, mode='only_match')
                    if qom > settings.QOM_MINIMUM_SCENEJOIN:
                        results.append(True)
                    else:
                        results.append(False)        
        
        if 'length' in check_mode:
            length_time = frame_diff_to_milisecs(length_diff,fps)
            if length_time <= float(LENGTH_TRESH)*1000.0:
                results.append(True)
            else:
                results.append(False)
            
        if 'time_diff' in check_mode:
            time_diff = frame_diff_to_milisecs(diff,fps)
            if time_diff<(float(TIMEDIFF_TRESH)*1000.0):
                results.append(True)
            else:
                results.append(False)
    
        if 'AND' in check_mode:
            if False in results: return False
            else: return True
        if 'OR' in check_mode:
            if True in results: return True
            else: return False
        
    else:
        return False