示例#1
0
 def xls_value_to_unicode(value, value_type):
     """
     Take a xls formatted value and try to make a unicode string
     representation.
     """
     if value_type == xlrd.XL_CELL_BOOLEAN:
         return u"TRUE" if value else u"FALSE"
     elif value_type == xlrd.XL_CELL_NUMBER:
         # Try to display as an int if possible.
         int_value = int(value)
         if int_value == value:
             return unicode(int_value)
         else:
             return unicode(value)
     elif value_type is xlrd.XL_CELL_DATE:
         # Warn that it is better to single quote as a string.
         # error_location = cellFormatString % (ss_row_idx, ss_col_idx)
         # raise Exception(
         #   "Cannot handle excel formatted date at " + error_location)
         datetime_or_time_only = xlrd.xldate_as_tuple(
             value, workbook.datemode)
         if datetime_or_time_only[:3] == (0, 0, 0):
             # must be time only
             return unicode(datetime.time(*datetime_or_time_only[3:]))
         return unicode(datetime.datetime(*datetime_or_time_only))
     else:
         # ensure unicode and replace nbsp spaces with normal ones
         # to avoid this issue:
         # https://github.com/modilabs/pyxform/issues/83
         return unicode(value).replace(unichr(160), ' ')
示例#2
0
def xls_value_to_unicode(value, value_type, datemode):
    """
    Take a xls formatted value and try to make a unicode string
    representation.
    """
    if value_type == xlrd.XL_CELL_BOOLEAN:
        return "TRUE" if value else "FALSE"
    elif value_type == xlrd.XL_CELL_NUMBER:
        # Try to display as an int if possible.
        int_value = int(value)
        if int_value == value:
            return unicode(int_value)
        else:
            return unicode(value)
    elif value_type is xlrd.XL_CELL_DATE:
        # Warn that it is better to single quote as a string.
        # error_location = cellFormatString % (ss_row_idx, ss_col_idx)
        # raise Exception(
        #   "Cannot handle excel formatted date at " + error_location)
        datetime_or_time_only = xlrd.xldate_as_tuple(value, datemode)
        if datetime_or_time_only[:3] == (0, 0, 0):
            # must be time only
            return unicode(datetime.time(*datetime_or_time_only[3:]))
        return unicode(datetime.datetime(*datetime_or_time_only))
    else:
        # ensure unicode and replace nbsp spaces with normal ones
        # to avoid this issue:
        # https://github.com/modilabs/pyxform/issues/83
        return unicode(value).replace(unichr(160), " ")
              file=sys.stderr)
        sys.exit(0)

    h5_file = h5py.File(sys.argv[1], "r")
    # h5py is not able to open that file. but scipy is
    train_test = scipy.io.loadmat(sys.argv[2])
    out_folder = sys.argv[3]

    test_images = set([int(x) for x in train_test["testNdxs"]])
    train_images = set([int(x) for x in train_test["trainNdxs"]])
    print("%d training images" % len(train_images))
    print("%d test images" % len(test_images))

    depth_raw = h5_file['rawDepths']
    depth_dense = h5_file['depths']

    print("reading", sys.argv[1])

    images = h5_file['images']
    scenes = [
        u''.join(unichr(c) for c in h5_file[obj_ref])
        for obj_ref in h5_file['sceneTypes'][0]
    ]

    print("processing images")
    for i, image in enumerate(images):
        print("image", i + 1, "/", len(images))
        convert_image(i, scenes[i], depth_raw[i, :, :].T, image.T,
                      depth_dense[i, :, :].T)

    print("Finished")