示例#1
0
def sequence(n_img):
	# get following variables from the parameters:
	# n_camera, seq_first, seq_last, base_name
	sequenceParams = par.SequenceParams(n_img, path = par.temp_path)
	sequenceParams.read()
	(base_name, seq_first, seq_last) = (sequenceParams.base_name, sequenceParams.first, sequenceParams.last)

	print ("Starting sequence action")
	
	ptv.py_sequence_init(0)
	stepshake=ptv.py_get_from_sequence_init()
	if not stepshake:
		stepshake=1
	print stepshake
	temp_img=np.array([],dtype=np.ubyte)
	for i in range(seq_first,seq_last+1,stepshake):
		if i<10:
			seq_ch="%01d" % i
		elif i<100:
			seq_ch="%02d" % i
		else:
			seq_ch="%03d" % i
		for j in range (n_img):
			img_name=base_name[j]+seq_ch
			print ("Setting image: ",img_name)
			try:
				temp_img=imread(img_name).astype(np.ubyte)
			except:
				print "Error reading file"
				   
			ptv.py_set_img(temp_img,j)
		
		ptv.py_sequence_loop(0,i)
示例#2
0
def sequence(n_img):
	# get following variables from the parameters:
	# n_camera, seq_first, seq_last, base_name
	sequenceParams = par.SequenceParams(n_img, path = par.temp_path)
	sequenceParams.read()
	(base_name, seq_first, seq_last) = (sequenceParams.base_name, sequenceParams.first, sequenceParams.last)

	print ("Starting sequence action")
	
	ptv.py_sequence_init(0)
	stepshake=ptv.py_get_from_sequence_init()
	if not stepshake:
		stepshake=1
	print stepshake
	temp_img=np.array([],dtype=np.ubyte)
	for i in range(seq_first,seq_last+1,stepshake):
		if i<10:
			seq_ch="%01d" % i
		elif i<100:
			seq_ch="%02d" % i
		else:
			seq_ch="%03d" % i
		for j in range (n_img):
			img_name=base_name[j]+seq_ch
			print ("Setting image: ",img_name)
			try:
				temp_img=imread(img_name).astype(np.ubyte)
			except:
				print "Error reading file"
				   
			ptv.py_set_img(temp_img,j)
		
		ptv.py_sequence_loop(0,i)
示例#3
0
    def sequence_action(self, info):
        """sequence action - implements binding to C sequence function. Original function was split into 2 parts:
			1) initialization - binded by ptv.py_sequence_init(..) function
			2) main loop processing - binded by ptv.py_sequence_loop(..) function
		"""
        extern_sequence = info.object.plugins.sequence_alg
        if extern_sequence != 'default':
            try:
                current_path = os.path.abspath(
                    os.getcwd())  # save working path
                os.chdir(software_path
                         )  #change to software path, to load tracking module
                seq = __import__(
                    extern_sequence)  #import choosen tracker from software dir
            except:
                print "Error loading " + extern_sequence + ". Falling back to default sequence algorithm"
                extern_sequence = 'default'
            os.chdir(current_path)  # change back to working path
        if extern_sequence == 'default':
            n_camera = len(info.object.camera_list)
            print("Starting sequence action (default algorithm)")
            seq_first = info.object.exp1.active_params.m_params.Seq_First
            seq_last = info.object.exp1.active_params.m_params.Seq_Last
            print seq_first, seq_last
            base_name = []
            for i in range(n_camera):
                exec(
                    "base_name.append(info.object.exp1.active_params.m_params.Basename_%d_Seq)"
                    % (i + 1))
                print base_name[i]

            ptv.py_sequence_init(0)  #init C sequence function
            stepshake = ptv.py_get_from_sequence_init(
            )  #get parameters and pass to main loop
            if not stepshake:
                stepshake = 1

            print stepshake
            temp_img = np.array([], dtype=np.ubyte)
            # main loop - format image name, read it and call v.py_sequence_loop(..) for current step
            for i in range(seq_first, seq_last + 1, stepshake):
                seq_ch = "%04d" % i

                for j in range(n_camera):
                    img_name = base_name[j] + seq_ch
                    print("Setting image: ", img_name)
                    try:
                        temp_img = imread(img_name).astype(np.ubyte)
                    except:
                        print "Error reading file"

                    ptv.py_set_img(temp_img, j)
                    ptv.py_sequence_loop(0, i)
        else:
            print "Sequence by using " + extern_sequence
            sequence = seq.Sequence(ptv=ptv,
                                    exp1=info.object.exp1,
                                    camera_list=info.object.camera_list)
            sequence.do_sequence()
示例#4
0
def sequence_tracking(n_img, track_backward=True):
    # get following variables from the parameters:
    # n_camera, seq_first, seq_last, base_name
    import ptv1 as ptv

    sequenceParams = par.SequenceParams(n_img, path=par.temp_path)
    sequenceParams.read()
    (base_name, seq_first,
     seq_last) = (sequenceParams.base_name, sequenceParams.first,
                  sequenceParams.last)

    print("Starting sequence action")

    ptv.py_sequence_init(0)
    stepshake = ptv.py_get_from_sequence_init()
    if not stepshake:
        stepshake = 1
    print stepshake
    temp_img = np.array([], dtype=np.ubyte)
    for i in range(seq_first, seq_last + 1, stepshake):
        if i < 10:
            seq_ch = "%01d" % i
        elif i < 100:
            seq_ch = "%02d" % i
        else:
            seq_ch = "%03d" % i
        for j in range(n_img):
            img_name = base_name[j] + seq_ch
            print("Setting image: ", img_name)
            try:
                temp_img = imread(img_name).astype(np.ubyte)
            except:
                print "Error reading file"

            ptv.py_set_img(temp_img, j)

        ptv.py_sequence_loop(0, i)


#	forward tracking
    run_info = ptv.py_trackcorr_init()
    print run_info.get_sequence_range()
    for step in range(*run_info.get_sequence_range()):
        print(step)
        try:
            ptv.py_trackcorr_loop(run_info, step, display=0)
        except:
            print('step', step)
            raise ValueError('cannot track anymore')

    ptv.py_trackcorr_finish(run_info, step + 1)
    print "tracking without display finished"

    # RON - back tracking is optional
    if track_backward:
        ptv.py_trackback_c()
        print "tracking backwards is finished"
示例#5
0
	def sequence_action(self,info):
		"""sequence action - implements binding to C sequence function. Original function was split into 2 parts:
			1) initialization - binded by ptv.py_sequence_init(..) function
			2) main loop processing - binded by ptv.py_sequence_loop(..) function
		"""
		
		extern_sequence=info.object.plugins.sequence_alg
		if extern_sequence!='default':
			try:
				current_path=os.path.abspath(os.getcwd()) # save working path
				os.chdir(software_path) #change to software path, to load tracking module
				seq=__import__(extern_sequence) #import choosen tracker from software dir
			except:
				print "Error loading "+extern_sequence+". Falling back to default sequence algorithm"
				extern_sequence='default'
			os.chdir(current_path) # change back to working path
		if extern_sequence=='default':
			n_camera=len(info.object.camera_list)
			print ("Starting sequence action (default algorithm)")
			seq_first=info.object.exp1.active_params.m_params.Seq_First
			seq_last=info.object.exp1.active_params.m_params.Seq_Last
			print seq_first,seq_last
			base_name=[]
			for i in range (n_camera):
				exec("base_name.append(info.object.exp1.active_params.m_params.Basename_%d_Seq)" %(i+1))
				print base_name[i]
	   
			ptv.py_sequence_init(0) #init C sequence function
			stepshake=ptv.py_get_from_sequence_init() #get parameters and pass to main loop
			if not stepshake:
				stepshake=1
			
			print stepshake
			temp_img=np.array([],dtype=np.ubyte)
			# main loop - format image name, read it and call v.py_sequence_loop(..) for current step
			for i in range(seq_first,seq_last+1,stepshake):
				seq_ch="%04d" % i
					
				for j in range (n_camera):
					img_name = base_name[j] + seq_ch
					print ("Setting image: ",img_name)
					try:
						temp_img=imread(img_name).astype(np.ubyte)
					except:
						print "Error reading file"
						   
					ptv.py_set_img(temp_img,j)
				
				ptv.py_sequence_loop(0,i)
		else:
			print "Sequence by using "+ extern_sequence
			sequence=seq.Sequence(ptv=ptv, exp1=info.object.exp1,camera_list=info.object.camera_list)
			sequence.do_sequence()
示例#6
0
def sequence_tracking(n_img):
    # get following variables from the parameters:
    # n_camera, seq_first, seq_last, base_name
    import ptv1 as ptv
    
    sequenceParams = par.SequenceParams(n_img, path=par.temp_path)
    sequenceParams.read()
    (base_name, seq_first, seq_last) = (
        sequenceParams.base_name, sequenceParams.first, sequenceParams.last)

    print ("Starting sequence action")

    ptv.py_sequence_init(0)
    stepshake = ptv.py_get_from_sequence_init()
    if not stepshake:
        stepshake = 1
    print stepshake
    temp_img = np.array([], dtype=np.ubyte)
    for i in range(seq_first, seq_last + 1, stepshake):
        if i < 10:
            seq_ch = "%01d" % i
        elif i < 100:
            seq_ch = "%02d" % i
        else:
            seq_ch = "%03d" % i
        for j in range(n_img):
            img_name = base_name[j] + seq_ch
            print ("Setting image: ", img_name)
            try:
                temp_img = imread(img_name).astype(np.ubyte)
            except:
                print "Error reading file"

            ptv.py_set_img(temp_img, j)

        ptv.py_sequence_loop(0, i)


#	forward tracking
    run_info = ptv.py_trackcorr_init()
    print run_info.get_sequence_range()
    for step in range(*run_info.get_sequence_range()):
        print step
        ptv.py_trackcorr_loop(run_info, step, display=0)

    ptv.py_trackcorr_finish(run_info, step + 1)
    print "tracking without display finished"
    # RON - cancled back tracking due to bug 
    ptv.py_trackback_c()
    print "tracking backwards is finished"
示例#7
0
 def test_sequencing(self):
     """Sequencing reproduces sample results"""
     os.mkdir("res/")
     
     py_init_proc_c()
     py_start_proc_c()
     py_sequence_init(0)
     
     for frame in xrange(497, 598):
         for cam in xrange(4):
             img = imread(
                 "scene83_event1/cam%d_Scene83_%04d" % (cam + 1, frame))
             py_set_img(img, cam)
             py_sequence_loop(0, frame)
     
     self.failUnless(compare_directories("res/", "after_sequencing/"))
     self.failUnless(compare_directories(
         "scene83_event1/", "after_sequencing_targets/",
         mask=re.compile("_targets$")))