Exemplo n.º 1
0
 def save_calib(self):
     print('Saving calibration to ', self.output_dir)
     np.save(os.path.join(self.output_dir, 'dc.npy'),
             np.asarray(self.calibrator.distortion, np.float32))
     np.save(os.path.join(self.output_dir, 'cm.npy'),
             np.asarray(self.calibrator.intrinsics, np.float32))
     cv.Save(os.path.join(self.output_dir, 'camera_matrix.xml'),
             self.calibrator.intrinsics)
     cv.Save(os.path.join(self.output_dir, 'distortion_coefficients.xml'),
             self.calibrator.distortion)
 def do_save(self):
     print('{0}.do_save'.format(self.__class__))
     numpy.save('dc.npy', numpy.asarray(self.distortion, numpy.float32))
     numpy.save('cm.npy', numpy.asarray(self.intrinsics, numpy.float32))
     cv.Save('camera_matrix.xml', self.intrinsics)
     cv.Save('distortion_coefficients.xml', self.distortion)
     filename = 'calibrationdata.tar.gz'
     tf = tarfile.open(filename, 'w:gz')
     self.do_tarfile_save(tf)  # Must be overridden in subclasses
     tf.close()
     print "Wrote calibration data to", filename
Exemplo n.º 3
0
    def invoke(self, arg, from_tty):
        args = gdb.string_to_argv(arg)

        v = gdb.parse_and_eval(args[0])
        strType = gdb.execute("print " + args[0] + ".type()", False, True)
        # strType contains gdb answers as a string of the form "$2 = 42"
        img = cv.CreateMat(v['rows'], v['cols'], int(strType.split(" ")[2]))

        # convert v['data'] to char*
        char_type = gdb.lookup_type("char")
        char_pointer_type = char_type.pointer()
        buffer = v['data'].cast(char_pointer_type)

        # read bytes from inferior's process memory
        buf = v['step']['buf']
        bytes = buf[0] * v['rows']
        inferior = gdb.selected_inferior()
        mem = inferior.read_memory(buffer, bytes)

        # set the matrix raw data
        cv.SetData(img, mem)

        # save matrix as an xml file and open it with matrix viewer
        cv.Save("/tmp/dump.xml", img, "matrix")
        call(["matrix-viewer", "/tmp/dump.xml"])
Exemplo n.º 4
0
 def subspace_project(self, test_features):
     projected_file = os.path.join(self.model_dir, 'proj.xml')
     # creating copy of subspace file since we over write the same file
     temp_subspace_file = os.path.join(
         self.model_dir, 'temp_subspace_file_%s.xml' % datetime.utcnow())
     shutil.copy(self.subspace_file, temp_subspace_file)
     # create a feature file
     feature_file = os.path.join(self.model_dir, 'test_features.xml')
     la = np.asarray([[-1] * test_features.shape[0]])
     cv_feats = np.transpose(np.concatenate(
         (la, test_features.transpose())))
     mat_to_save = cv_feats.transpose().copy()
     cv.Save(feature_file, cv.fromarray(mat_to_save))
     # call binary
     bin_dir = config.bin_dir()
     run_cmd([
         os.path.join(bin_dir, 'aff_face_subspace_project'), feature_file,
         temp_subspace_file, projected_file
     ])
     return temp_subspace_file, projected_file
Exemplo n.º 5
0
 def train(self, features, labels):
     '''
         features = all the features for the faces, each row is a feature
         labels = a list of labels representing the id
             for each corresponding row in the features array
     '''
     if not self._is_trained:
         assert len(labels) == features.shape[0]
         self.model_dir = mkdtemp()
         # create feature file with given features
         # feature file needs to be such that the first dim in the label and
         # then each row in a feature
         self.feature_file = os.path.join(self.model_dir, 'features.xml')
         la = np.asarray([labels])
         cv_feats = np.transpose(np.concatenate((la, features.transpose())))
         mat_to_save = cv_feats.transpose().copy()
         # nFaces = mat_to_save->cols;
         # nDesc  = mat_to_save->rows-1;
         cv.Save(self.feature_file, cv.fromarray(mat_to_save))
         self.subspace_file = os.path.join(self.model_dir,
                                           'learned_subspace.xml')
         self.face_subspace()
         self._is_trained = True
Exemplo n.º 6
0
    for i in range(0, image.height):
        for j in range(0, image.width):
            # keep closer object
            if cv.GetReal2D(disparity, i, j) > threshold:
                cv.Set2D(disparity, i, j, cv.Get2D(image, i, j))


# loading the stereo pair
left = cv.LoadImage('scene_l.bmp', cv.CV_LOAD_IMAGE_GRAYSCALE)
right = cv.LoadImage('scene_r.bmp', cv.CV_LOAD_IMAGE_GRAYSCALE)

disparity_left = cv.CreateMat(left.height, left.width, cv.CV_16S)
disparity_right = cv.CreateMat(left.height, left.width, cv.CV_16S)

# data structure initialization
state = cv.CreateStereoGCState(16, 2)
# running the graph-cut algorithm
cv.FindStereoCorrespondenceGC(left, right, disparity_left, disparity_right,
                              state)

disp_left_visual = cv.CreateMat(left.height, left.width, cv.CV_8U)
cv.ConvertScale(disparity_left, disp_left_visual, -16)
cv.Save("disparity.pgm", disp_left_visual)
# save the map

# cutting the object farthest of a threshold (120)
cut(disp_left_visual, left, 120)

cv.NamedWindow('Disparity map', cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage('Disparity map', disp_left_visual)
cv.WaitKey()