def test_full_instantiate(self):
     """Instantiate a SequenceParams object from keywords."""
     spar = SequenceParams(
         image_base=['test1', 'test2'], frame_range=(1, 100))
     self.failUnless(spar.get_img_base_name(0) == "test1") 
     self.failUnless(spar.get_img_base_name(1) == "test2")
     self.failUnless(spar.get_first() == 1)
     self.failUnless(spar.get_last() == 100)
 def test_full_instantiate(self):
     """Instantiate a SequenceParams object from keywords."""
     spar = SequenceParams(
         image_base=['test1', 'test2'], frame_range=(1, 100))
     
     print(spar.get_img_base_name(0))
     self.failUnless(spar.get_img_base_name(0) == b"test1") 
     self.failUnless(spar.get_img_base_name(1) == b"test2")
     self.failUnless(spar.get_first() == 1)
     self.failUnless(spar.get_last() == 100)
 def test_rich_compare(self):
     self.seq_obj2 = SequenceParams(num_cams=4)
     self.seq_obj2.read_sequence_par(self.input_sequence_par_file_name, 4)
     
     self.seq_obj3 = SequenceParams(num_cams=4)
     self.seq_obj3.read_sequence_par(self.input_sequence_par_file_name, 4)
            
     self.failUnless(self.seq_obj2 == self.seq_obj3)
     self.failIf(self.seq_obj2 != self.seq_obj3)
         
     self.seq_obj2.set_first(-999)
     self.failUnless(self.seq_obj2 != self.seq_obj3)
     self.failIf(self.seq_obj2 == self.seq_obj3)
         
     with self.assertRaises(TypeError):
         var = (self.seq_obj2 > self.seq_obj3)
Example #4
0
 def test_rich_compare(self):
     self.seq_obj2 = SequenceParams(4)
     self.seq_obj2.read_sequence_par(self.input_sequence_par_file_name, 4)
     
     self.seq_obj3 = SequenceParams(4)
     self.seq_obj3.read_sequence_par(self.input_sequence_par_file_name, 4)
            
     self.failUnless(self.seq_obj2 == self.seq_obj3)
     self.failIf(self.seq_obj2 != self.seq_obj3)
         
     self.seq_obj2.set_first(-999)
     self.failUnless(self.seq_obj2 != self.seq_obj3)
     self.failIf(self.seq_obj2 == self.seq_obj3)
         
     with self.assertRaises(TypeError):
         var = (self.seq_obj2 > self.seq_obj3)
Example #5
0
 def setUp(self):
     self.input_sequence_par_file_name = "testing_fodder/sequence_parameters/sequence.par"
     self.temp_output_directory = "testing_fodder/sequence_parameters/testing_output"
     
     # create a temporary output directory (will be deleted by the end of test)
     if not os.path.exists(self.temp_output_directory):
         os.makedirs(self.temp_output_directory)
         
     # create an instance of SequencParams class
     self.seq_obj = SequenceParams(4)
Example #6
0
def py_start_proc_c(n_cams):
    """ Read parameters """

    # Control parameters
    cpar = ControlParams(n_cams)
    cpar.read_control_par(b'parameters/ptv.par')

    # Sequence parameters
    spar = SequenceParams(num_cams=n_cams)
    spar.read_sequence_par(b'parameters/sequence.par', n_cams)

    # Volume parameters
    vpar = VolumeParams()
    vpar.read_volume_par(b'parameters/criteria.par')

    # Tracking parameters
    track_par = TrackingParams()
    track_par.read_track_par(b'parameters/track.par')

    # Target parameters
    tpar = TargetParams(n_cams)
    tpar.read(b'parameters/targ_rec.par')

    # Examine parameters, multiplane (single plane vs combined calibration)
    epar = par.ExamineParams()
    epar.read()

    # Calibration parameters
    cals = []
    for i_cam in range(n_cams):
        cal = Calibration()
        tmp = cpar.get_cal_img_base_name(i_cam)
        cal.from_file(tmp + b'.ori', tmp + b'.addpar')
        cals.append(cal)

    return cpar, spar, vpar, track_par, tpar, cals, epar
Example #7
0
    def setUp(self):
        with open("testing_fodder/track/conf.yaml") as f:
            yaml_conf = yaml.load(f)
        seq_cfg = yaml_conf['sequence']

        cals = []
        img_base = []
        for cix, cam_spec in enumerate(yaml_conf['cameras']):
            cam_spec.setdefault('addpar_file', None)
            cal = Calibration()
            cal.from_file(cam_spec['ori_file'], cam_spec['addpar_file'])
            cals.append(cal)
            img_base.append(seq_cfg['targets_template'].format(cam=cix + 1))

        cpar = ControlParams(len(yaml_conf['cameras']), **yaml_conf['scene'])
        vpar = VolumeParams(**yaml_conf['correspondences'])
        tpar = TrackingParams(**yaml_conf['tracking'])
        spar = SequenceParams(image_base=img_base,
                              frame_range=(seq_cfg['first'], seq_cfg['last']))

        self.tracker = Tracker(cpar, vpar, tpar, spar, cals, framebuf_naming)
 def setUp(self):
     self.input_sequence_par_file_name = "testing_fodder/sequence_parameters/sequence.par"
         
     # create an instance of SequencParams class
     self.seq_obj = SequenceParams(num_cams=4)
class Test_SequenceParams(unittest.TestCase):
    def setUp(self):
        self.input_sequence_par_file_name = "testing_fodder/sequence_parameters/sequence.par"
            
        # create an instance of SequencParams class
        self.seq_obj = SequenceParams(num_cams=4)
        
    def test_read_sequence(self):
        # Fill the SequenceParams object with parameters from test file
        self.seq_obj.read_sequence_par(self.input_sequence_par_file_name, 4)
        
        # check that all parameters are equal to the contents of test file
        self.failUnless(self.seq_obj.get_img_base_name(0) == "dumbbell/cam1_Scene77_") 
        self.failUnless(self.seq_obj.get_img_base_name(1) == "dumbbell/cam2_Scene77_")
        self.failUnless(self.seq_obj.get_img_base_name(2) == "dumbbell/cam3_Scene77_")
        self.failUnless(self.seq_obj.get_img_base_name(3) == "dumbbell/cam4_Scene77_")
        self.failUnless(self.seq_obj.get_first() == 497)
        self.failUnless(self.seq_obj.get_last() == 597)
      
    def test_getters_setters(self):
        cams_num = 4
        for cam in range(cams_num):
            newStr = str(cam) + "some string" + str(cam)
            self.seq_obj.set_img_base_name(cam, newStr)
            self.failUnless(self.seq_obj.get_img_base_name(cam) == newStr)
             
        self.seq_obj.set_first(1234)
        self.failUnless(self.seq_obj.get_first() == 1234)
        self.seq_obj.set_last(5678)
        self.failUnless(self.seq_obj.get_last() == 5678)
       
    # testing __richcmp__ comparison method of SequenceParams class
    def test_rich_compare(self):
        self.seq_obj2 = SequenceParams(num_cams=4)
        self.seq_obj2.read_sequence_par(self.input_sequence_par_file_name, 4)
        
        self.seq_obj3 = SequenceParams(num_cams=4)
        self.seq_obj3.read_sequence_par(self.input_sequence_par_file_name, 4)
               
        self.failUnless(self.seq_obj2 == self.seq_obj3)
        self.failIf(self.seq_obj2 != self.seq_obj3)
            
        self.seq_obj2.set_first(-999)
        self.failUnless(self.seq_obj2 != self.seq_obj3)
        self.failIf(self.seq_obj2 == self.seq_obj3)
            
        with self.assertRaises(TypeError):
            var = (self.seq_obj2 > self.seq_obj3)
    
    def test_full_instantiate(self):
        """Instantiate a SequenceParams object from keywords."""
        spar = SequenceParams(
            image_base=['test1', 'test2'], frame_range=(1, 100))
        self.failUnless(spar.get_img_base_name(0) == "test1") 
        self.failUnless(spar.get_img_base_name(1) == "test2")
        self.failUnless(spar.get_first() == 1)
        self.failUnless(spar.get_last() == 100)
Example #10
0
def run_batch(new_seq_first, new_seq_last):
    """ this file runs inside exp_path, so the other names are
    prescribed by the OpenPTV type of a folder:
        /parameters
        /img
        /cal
        /res
    """
    # read the number of cameras
    with open('parameters/ptv.par', 'r') as f:
        n_cams = int(f.readline())

    # Control parameters
    cpar = ControlParams(n_cams)
    cpar.read_control_par(b'parameters/ptv.par')

    # Sequence parameters
    spar = SequenceParams(num_cams=n_cams)
    spar.read_sequence_par(b'parameters/sequence.par', n_cams)
    spar.set_first(new_seq_first)
    spar.set_last(new_seq_last)

    # Volume parameters
    vpar = VolumeParams()
    vpar.read_volume_par(b'parameters/criteria.par')

    # Tracking parameters
    track_par = TrackingParams()
    track_par.read_track_par(b'parameters/track.par')

    # Target parameters
    tpar = TargetParams()
    tpar.read(b'parameters/targ_rec.par')

    #

    # Calibration parameters

    cals = []
    for i_cam in range(n_cams):
        cal = Calibration()
        tmp = cpar.get_cal_img_base_name(i_cam)
        cal.from_file(tmp + b'.ori', tmp + b'.addpar')
        cals.append(cal)

    # sequence loop for all frames
    for frame in range(new_seq_first, new_seq_last + 1):
        print("processing frame %d" % frame)

        detections = []
        corrected = []
        for i_cam in range(n_cams):
            imname = spar.get_img_base_name(i_cam) + str(frame)
            img = imread(imname)
            hp = simple_highpass(img, cpar)
            targs = target_recognition(hp, tpar, i_cam, cpar)
            print(targs)

            targs.sort_y()
            detections.append(targs)
            mc = MatchedCoords(targs, cpar, cals[i_cam])
            pos, pnr = mc.as_arrays()
            print(i_cam)
            corrected.append(mc)

        #        if any([len(det) == 0 for det in detections]):
        #            return False

        # Corresp. + positions.
        sorted_pos, sorted_corresp, num_targs = correspondences(
            detections, corrected, cals, vpar, cpar)

        # Save targets only after they've been modified:
        for i_cam in xrange(n_cams):
            detections[i_cam].write(spar.get_img_base_name(i_cam), frame)


        print("Frame " + str(frame) + " had " \
              + repr([s.shape[1] for s in sorted_pos]) + " correspondences.")

        # Distinction between quad/trip irrelevant here.
        sorted_pos = np.concatenate(sorted_pos, axis=1)
        sorted_corresp = np.concatenate(sorted_corresp, axis=1)

        flat = np.array([corrected[i].get_by_pnrs(sorted_corresp[i]) \
                         for i in xrange(len(cals))])
        pos, rcm = point_positions(flat.transpose(1, 0, 2), cpar, cals, vpar)

        if len(cals) < 4:
            print_corresp = -1 * np.ones((4, sorted_corresp.shape[1]))
            print_corresp[:len(cals), :] = sorted_corresp
        else:
            print_corresp = sorted_corresp

        # Save rt_is
        rt_is = open(default_naming['corres'] + '.' + str(frame), 'w')
        rt_is.write(str(pos.shape[0]) + '\n')
        for pix, pt in enumerate(pos):
            pt_args = (pix + 1, ) + tuple(pt) + tuple(print_corresp[:, pix])
            rt_is.write("%4d %9.3f %9.3f %9.3f %4d %4d %4d %4d\n" % pt_args)
        rt_is.close()
    # end of a sequence loop

    tracker = Tracker(cpar, vpar, track_par, spar, cals, default_naming)
    tracker.full_forward()
Example #11
0
class Test_SequenceParams(unittest.TestCase):
    def setUp(self):
        self.input_sequence_par_file_name = "testing_fodder/sequence_parameters/sequence.par"
        self.temp_output_directory = "testing_fodder/sequence_parameters/testing_output"
        
        # create a temporary output directory (will be deleted by the end of test)
        if not os.path.exists(self.temp_output_directory):
            os.makedirs(self.temp_output_directory)
            
        # create an instance of SequencParams class
        self.seq_obj = SequenceParams(4)
        
    def test_read_sequence(self):
        # Fill the SequenceParams object with parameters from test file
        self.seq_obj.read_sequence_par(self.input_sequence_par_file_name, 4)
        
        # check that all parameters are equal to the contents of test file
        self.failUnless(self.seq_obj.get_img_base_name(0) == "dumbbell/cam1_Scene77_") 
        self.failUnless(self.seq_obj.get_img_base_name(1) == "dumbbell/cam2_Scene77_")
        self.failUnless(self.seq_obj.get_img_base_name(2) == "dumbbell/cam3_Scene77_")
        self.failUnless(self.seq_obj.get_img_base_name(3) == "dumbbell/cam4_Scene77_")
        self.failUnless(self.seq_obj.get_first() == 497)
        self.failUnless(self.seq_obj.get_last() == 597)
      
    def test_getters_setters(self):
        cams_num = 4
        for cam in range(cams_num):
            newStr = str(cam) + "some string" + str(cam)
            self.seq_obj.set_img_base_name(cam, newStr)
            self.failUnless(self.seq_obj.get_img_base_name(cam) == newStr)
             
        self.seq_obj.set_first(1234)
        self.failUnless(self.seq_obj.get_first() == 1234)
        self.seq_obj.set_last(5678)
        self.failUnless(self.seq_obj.get_last() == 5678)
       
    # testing __richcmp__ comparison method of SequenceParams class
    def test_rich_compare(self):
        self.seq_obj2 = SequenceParams(4)
        self.seq_obj2.read_sequence_par(self.input_sequence_par_file_name, 4)
        
        self.seq_obj3 = SequenceParams(4)
        self.seq_obj3.read_sequence_par(self.input_sequence_par_file_name, 4)
               
        self.failUnless(self.seq_obj2 == self.seq_obj3)
        self.failIf(self.seq_obj2 != self.seq_obj3)
            
        self.seq_obj2.set_first(-999)
        self.failUnless(self.seq_obj2 != self.seq_obj3)
        self.failIf(self.seq_obj2 == self.seq_obj3)
            
        with self.assertRaises(TypeError):
            var = (self.seq_obj2 > self.seq_obj3)
     
    def tearDown(self):
        # remove the testing output directory and its files
        shutil.rmtree(self.temp_output_directory)
 def setUp(self):
     self.input_sequence_par_file_name = b"testing_fodder/sequence_parameters/sequence.par"
         
     # create an instance of SequencParams class
     self.seq_obj = SequenceParams(num_cams=4)
class Test_SequenceParams(unittest.TestCase):
    def setUp(self):
        self.input_sequence_par_file_name = b"testing_fodder/sequence_parameters/sequence.par"
            
        # create an instance of SequencParams class
        self.seq_obj = SequenceParams(num_cams=4)
        
    def test_read_sequence(self):
        # Fill the SequenceParams object with parameters from test file
        self.seq_obj.read_sequence_par(self.input_sequence_par_file_name, 4)
        
        # check that all parameters are equal to the contents of test file
        self.failUnless(self.seq_obj.get_img_base_name(0) == b"dumbbell/cam1_Scene77_") 
        self.failUnless(self.seq_obj.get_img_base_name(1) == b"dumbbell/cam2_Scene77_")
        self.failUnless(self.seq_obj.get_img_base_name(2) == b"dumbbell/cam3_Scene77_")
        self.failUnless(self.seq_obj.get_img_base_name(3) == b"dumbbell/cam4_Scene77_")
        self.failUnless(self.seq_obj.get_first() == 497)
        self.failUnless(self.seq_obj.get_last() == 597)
      
    def test_getters_setters(self):
        cams_num = 4
        for cam in range(cams_num):
            newStr = str(cam) + "some string" + str(cam)
            self.seq_obj.set_img_base_name(cam, newStr)
            self.failUnless(self.seq_obj.get_img_base_name(cam) == newStr.encode())
             
        self.seq_obj.set_first(1234)
        self.failUnless(self.seq_obj.get_first() == 1234)
        self.seq_obj.set_last(5678)
        self.failUnless(self.seq_obj.get_last() == 5678)
       
    # testing __richcmp__ comparison method of SequenceParams class
    def test_rich_compare(self):
        self.seq_obj2 = SequenceParams(num_cams=4)
        self.seq_obj2.read_sequence_par(self.input_sequence_par_file_name, 4)
        
        self.seq_obj3 = SequenceParams(num_cams=4)
        self.seq_obj3.read_sequence_par(self.input_sequence_par_file_name, 4)
               
        self.failUnless(self.seq_obj2 == self.seq_obj3)
        self.failIf(self.seq_obj2 != self.seq_obj3)
            
        self.seq_obj2.set_first(-999)
        self.failUnless(self.seq_obj2 != self.seq_obj3)
        self.failIf(self.seq_obj2 == self.seq_obj3)
            
        with self.assertRaises(TypeError):
            var = (self.seq_obj2 > self.seq_obj3)
    
    def test_full_instantiate(self):
        """Instantiate a SequenceParams object from keywords."""
        spar = SequenceParams(
            image_base=['test1', 'test2'], frame_range=(1, 100))
        
        print(spar.get_img_base_name(0))
        self.failUnless(spar.get_img_base_name(0) == b"test1") 
        self.failUnless(spar.get_img_base_name(1) == b"test2")
        self.failUnless(spar.get_first() == 1)
        self.failUnless(spar.get_last() == 100)