Exemple #1
0
def main():
    points = list(pcd.read('david2/pcd/david2_1317518872.840330800.pcd'))
    sk = Skeleton(boneData())
    skBones = sk.Bones()
    segments = dict((key,[]) for key in skBones.keys()) # setup
    for p in points:
        minDist = 1e20 # big
        bestBone = 'T' # torso by default
        for bName,bone in skBones.iteritems(): # for all bones
            src,dst = bone
            boneDir = subtract(dst, src)
            offset = subtract(p, src)
            dist = crossNormSqr(boneDir,offset)/dot(offset,offset)
            if dist < minDist:
                minDist = dist
                bestBone = bName
        
        if sqrt(minDist) < 10:
            segments[bestBone].append(p)
    
    f = open('segmented.obj', 'w')
    for segName,points in segments.iteritems():
        print segName, len(points)
        if segName in ('LE2H', 'RE2H', 'LK2F', 'RK2F'):
            color = (1,0,0)
        elif segName in ('LS2E', 'RS2E', 'LH2K', 'RH2K'):
            color = (0,1,0)
        elif segName == 'T':
            color = (0,0,1)
        elif segName == 'N2H':
            color = (0,1,1)
        for p in points:
            col = blend(p[3:], color, 0.25) # tint
            f.write('v %f %f %f %f %f %f\n'%(p[0],p[1],p[2],col[0],col[1],col[2]))
Exemple #2
0
def main():
    assert len(sys.argv) >= 4
    pcdFile = sys.argv[1]
    yamlFile = sys.argv[2]
    outputFile = sys.argv[3]
    if len(sys.argv) == 5:
        offset = float(sys.argv[4])/2 # for displaying several together, non overlapping
    else:
        offset = 0
    
    assert pcdFile.endswith('pcd')
    assert yamlFile.endswith('yaml')
    assert outputFile.endswith('obj')
    weightFile = 'temp-weights'
    
    cmd = '../segmentation/build/sharpSegmentation %s %s %s'%(pcdFile,yamlFile,weightFile)
    assert os.system(cmd) == 0
    
    skel = Skeleton.fromFunnyYaml(yamlFile, relative=False)
    # save it so that they all use the same skel
    canonFile = 'canon.pickle'
    if os.path.exists(canonFile):
        canon = pickle.load(open(canonFile,'r'))
    else:
        canon = skel.Duplicate()
        canon.Canonicalize()
        #canon.sk = None #safe?
        pickle.dump(canon, open(canonFile,'w'))
    
    points = list(pcd.read(pcdFile))
    weights = ReadWeights(weightFile)
    
    I = ((1,0,0),(0,1,0),(0,0,1))
    newPoints = [[offset,0,0,r,g,b] for (_,_,_,r,g,b) in points]
    
    if True: # the right code
        for jointName,skin in weights.iteritems():
            src = Frame(skel.GetRot(jointName), skel.GetPos(jointName))
            dst = Frame(I, canon.GetPos(jointName))
            print jointName,src.o,dst.o
            for index,weight in skin:
                plusEq(newPoints[index], mult(absolute(dst, relative(src, points[index])), weight))
    else: # tesing code
        j = 0
        for jointName,skin in weights.iteritems():
            src = Frame(skel.GetRot(jointName), skel.GetPos(jointName))
            dst = Frame(I, canon.GetPos(jointName))
            print jointName,src.o,dst.o
            for index,weight in skin:
                plusEq(newPoints[index], relative(src, points[index]))
                plusEq(newPoints[index], (j,0,0))
            j += 0.5
        
    
    f = open(outputFile, 'w')
    for row in newPoints:
        if row[0] == row[0]:
            f.write('v %f %f %f %f %f %f\n'%tuple(row))
    f.close()
    print 'output to',outputFile
def main():
    assert len(sys.argv) >= 4
    pcdFile = sys.argv[1]
    yamlFile = sys.argv[2]
    outputFile = sys.argv[3]
    if len(sys.argv) == 5:
        offset = float(
            sys.argv[4]
        ) / 2  # for displaying several together, non overlapping
    else:
        offset = 0

    assert pcdFile.endswith('pcd')
    assert yamlFile.endswith('yaml')
    assert outputFile.endswith('obj')
    weightFile = 'temp-weights'

    cmd = '../segmentation/build/sharpSegmentation %s %s %s' % (
        pcdFile, yamlFile, weightFile)
    assert os.system(cmd) == 0

    skel = Skeleton.fromFunnyYaml(yamlFile, relative=False)
    # save it so that they all use the same skel
    canonFile = 'canon.pickle'
    if os.path.exists(canonFile):
        canon = pickle.load(open(canonFile, 'r'))
    else:
        canon = skel.Duplicate()
        canon.Canonicalize()
        #canon.sk = None #safe?
        pickle.dump(canon, open(canonFile, 'w'))

    points = list(pcd.read(pcdFile))
    weights = ReadWeights(weightFile)

    I = ((1, 0, 0), (0, 1, 0), (0, 0, 1))
    newPoints = [[offset, 0, 0, r, g, b] for (_, _, _, r, g, b) in points]

    if True:  # the right code
        for jointName, skin in weights.iteritems():
            src = Frame(skel.GetRot(jointName), skel.GetPos(jointName))
            dst = Frame(I, canon.GetPos(jointName))
            print jointName, src.o, dst.o
            for index, weight in skin:
                plusEq(
                    newPoints[index],
                    mult(absolute(dst, relative(src, points[index])), weight))
    else:  # tesing code
        j = 0
        for jointName, skin in weights.iteritems():
            src = Frame(skel.GetRot(jointName), skel.GetPos(jointName))
            dst = Frame(I, canon.GetPos(jointName))
            print jointName, src.o, dst.o
            for index, weight in skin:
                plusEq(newPoints[index], relative(src, points[index]))
                plusEq(newPoints[index], (j, 0, 0))
            j += 0.5

    f = open(outputFile, 'w')
    for row in newPoints:
        if row[0] == row[0]:
            f.write('v %f %f %f %f %f %f\n' % tuple(row))
    f.close()
    print 'output to', outputFile