示例#1
0
def main():
    usage = "%s [options]  <MSS File> <MSSout>" % (sys.argv[0])
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-t',
                       '--head',
                       dest='head',
                       type='int',
                       default=None,
                       help='use first h as target')

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    sc = exSC()
    mss = MSS()
    mss.load(args[1])
    keypoints = mss.getAllPoints()
    if (options.head == None):
        hl = len(keypoints)
    else:
        hl = options.head
    sc.ExtractFeature(keypoints, range(hl))
    mss.save(args[2])
示例#2
0
def main():

    usage = "%prog [options] <feature_file1> <feature_file2>\nMatch two sequence using Needleman Wusche algorithm"
    version = "%prog 0.2\nLongbin Chen, 08/31/2009,  [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-o', '--output', dest = 'output', default = None, help = 'output file')
    oparser.add_option('-m', '--model', dest = 'model', default = None, help = 'model file') 


    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    mss1 = MSS()
    mss1.load(args[1])
    mss2 = MSS()
    mss2.load(args[2])

    ######## Typical usage of Needleman-Wunsch algorithm
    ######## seq1, seq2 are two lists 
    matcher = NWMatch()
    cost, matchX, matchY = matcher.Align(mss1.seqs[0], mss2.seqs[0])
    print cost
    if (options.output):
       f = open(options.output, "w")
       for i in range(len(matchX)):
           f.write("%d\t%d\n" %(matchX[i], matchY[i]))
       f.close()
示例#3
0
def main():

    usage = "%prog [options] <msshape> <outputmss>"
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-a',
                       '--angle',
                       dest='angle',
                       default=False,
                       action='store_true',
                       help='generate angle feature')
    oparser.add_option('-d',
                       '--das',
                       dest='das',
                       default=False,
                       action='store_true',
                       help='generate das feature')
    oparser.add_option('-s',
                       '--sc',
                       dest='sc',
                       default=False,
                       action='store_true',
                       help='generate shape context feature')
    oparser.add_option('-o',
                       '--offset',
                       dest='offset',
                       default=False,
                       action='store_true',
                       help='generate offset feature')

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    if (not options.angle and not options.das and not options.sc
            and not options.offset):
        options.angle = True
        options.das = True
        options.sc = True
        options.offset = True

    das = exDAS()
    agl = exAngle()
    sc = exSC()
    mss = MSS()
    mss.load(args[1])
    for seq in mss.seqs:
        if (options.das):
            das.ExtractFeature(seq.points, None)
        if (options.angle):
            agl.ExtractFeature(seq.points, None)
    if (options.sc):
        keypoints = mss.getAllPoints()
        sc.ExtractFeature(keypoints, None)
    if (options.offset):
        oft = exOffset()
        oft.ExtractFeature(keypoints, None)
    mss.save(args[2])
示例#4
0
def main():

    usage = "%prog [options] <msshape> <outputmss>"
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)

    agl = exAngle()
    mss = MSS()
    mss.load(args[1])
    for seq in mss.seqs:
        agl.ExtractFeature(seq.points, None)
    mss.save(args[2])
示例#5
0
def main():

    usage = "%prog [options] <msshape> <outputmss>"
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)

    agl = exAngle()
    mss = MSS()
    mss.load(args[1])
    for seq in mss.seqs:
        agl.ExtractFeature(seq.points, None)
    mss.save(args[2])
示例#6
0
def main():

    usage = "%prog [options] <msshape> <outputmss>"
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    #oparser.add_option('-c', '--shapecontext', action="store_false",dest = 'shapecontext', default = True,  help = 'extract shape context  features(default true)')
    #oparser.add_option('-w', '--das', action="store_false",dest = 'das', default = True,  help = 'extract DAS features(default true)')

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)

    das = exDAS()
    mss = MSS()
    mss.load(args[1])
    for seq in mss.seqs:
        das.ExtractFeature(seq.points, None)
    mss.save(args[2])
示例#7
0
def main():

    usage = "%prog [options] <msshape> <outputmss>"
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    #oparser.add_option('-c', '--shapecontext', action="store_false",dest = 'shapecontext', default = True,  help = 'extract shape context  features(default true)')
    #oparser.add_option('-w', '--das', action="store_false",dest = 'das', default = True,  help = 'extract DAS features(default true)')

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)

    das = exDAS()
    mss = MSS()
    mss.load(args[1])
    for seq in mss.seqs:
        das.ExtractFeature(seq.points, None)
    mss.save(args[2])
示例#8
0
def main():
    usage = "%s [options]  <MSS File> <MSSout>" % (sys.argv[0])
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-t', '--head', dest = 'head', type='int',default = None, help = 'use first h as target')

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    sc = exSC()
    mss = MSS()
    mss.load(args[1])
    keypoints = mss.getAllPoints()
    if (options.head == None):
        hl = len(keypoints)
    else:
        hl = options.head
    sc.ExtractFeature(keypoints, range(hl))
    mss.save(args[2])
示例#9
0
def main():

    usage = "%prog [options] <msshape> <outputmss>"
    version = "%prog 0.2\n Longbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-a', '--angle', dest = 'angle', default = False, action = 'store_true', help = 'generate angle feature')
    oparser.add_option('-d', '--das', dest = 'das', default = False, action = 'store_true', help = 'generate das feature')
    oparser.add_option('-s', '--sc', dest = 'sc', default = False, action = 'store_true', help = 'generate shape context feature')
    oparser.add_option('-o', '--offset', dest = 'offset', default = False, action = 'store_true', help = 'generate offset feature')


    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    if (not options.angle and not options.das and not options.sc and not options.offset):
        options.angle = True
        options.das   = True
        options.sc    = True
        options.offset= True

    das = exDAS()
    agl = exAngle()
    sc = exSC()
    mss = MSS()
    mss.load(args[1])
    for seq in mss.seqs:
        if (options.das):
            das.ExtractFeature(seq.points, None)
        if (options.angle):
            agl.ExtractFeature(seq.points, None)
    if (options.sc):
        keypoints = mss.getAllPoints()
        sc.ExtractFeature(keypoints, None)
    if (options.offset):
        oft = exOffset()
        oft.ExtractFeature(keypoints, None)
    mss.save(args[2])
示例#10
0
def main():

    usage = "%prog [options] <feature_file1> <feature_file2>\nMatch two sequence using Needleman Wusche algorithm"
    version = "%prog 0.2\nLongbin Chen, 08/31/2009,  [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-o',
                       '--output',
                       dest='output',
                       default=None,
                       help='output file')
    oparser.add_option('-m',
                       '--model',
                       dest='model',
                       default=None,
                       help='model file')

    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    mss1 = MSS()
    mss1.load(args[1])
    mss2 = MSS()
    mss2.load(args[2])

    ######## Typical usage of Needleman-Wunsch algorithm
    ######## seq1, seq2 are two lists
    matcher = NWMatch()
    cost, matchX, matchY = matcher.Align(mss1.seqs[0], mss2.seqs[0])
    print cost
    if (options.output):
        f = open(options.output, "w")
        for i in range(len(matchX)):
            f.write("%d\t%d\n" % (matchX[i], matchY[i]))
        f.close()
示例#11
0
def main():

    usage = "%prog [options] <mss_file1> <mss_file2>"
    version = "%prog 0.2\nLongbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-o', '--output', dest = 'output', default = None, help = 'output file')
    oparser.add_option('-i', '--image', dest = 'image', default = None, help = 'input image file, separated by comma')
    oparser.add_option('-m', '--drawnumber', action="store_true", dest = 'drawnumber', default = False, help = 'display the point numbers')
    oparser.add_option('-t', '--threshold', dest = 'threshold', type='int',default = 100 , help = 'the threshold for image binarification')
    oparser.add_option('-n', '--number', dest = 'num', type='int',default = 100 , help = 'the number of feature points')
    oparser.add_option('-b', '--bidirect', dest = 'bidirect', action="store_true", default = False, help = 'SW matching with two directions')


    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    tmss1 = MSS()
    tmss1.load(args[1])
    tmss2 = MSS()
    tmss2.load(args[2])
    mss1 = MSS()
    mss1.load(args[1])
    mss2 = MSS()
    mss2.load(args[2])
     
    
   
    sw = MSS_SW_Exact()
    #sw = MSS_SW()
    if (options.image):
        fimg1, fimg2 = options.image.split(",")
    else:
        fimg1 = None
        fimg2 = None
    sumsc, bX, bY, sfinal =  sw.align(mss1, mss2, options.bidirect, tmss1, tmss2, fimg1, fimg2)
    print sumsc[0]
    if options.output:
        print bX, bY
        fout = open(options.output, 'w')
        for it, b in enumerate(bX):
            fout.write("%d\t%d\t%d\t%d\n" %(b[0], b[1], bY[it][0],bY[it][1]))
        fout.close()
示例#12
0
def main():

    usage = "%prog [options] <mss_file1> <mss_file2>"
    version = "%prog 0.2\nLongbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-o', '--output', dest = 'output', default = None, help = 'output file')
    oparser.add_option('-i', '--image', dest = 'image', action="store_true", default = False, help = 'input image file')
    oparser.add_option('-m', '--drawnumber', action="store_true", dest = 'drawnumber', default = False, help = 'display the point numbers')
    oparser.add_option('-t', '--threshold', dest = 'threshold', type='int',default = 100 , help = 'the threshold for image binarification')
    oparser.add_option('-n', '--number', dest = 'num', type='int',default = 100 , help = 'the number of feature points')


    (options, args) = oparser.parse_args(sys.argv)

    if len(args) != 3:
        oparser.parse_args([sys.argv[0], "--help"])
        sys.exit(1)
    if (options.image):
        das = exDAS()
        agl = exAngle()
        sc = exSC()
        ct1 = ExtractMSS()
        ct1.GetContour(args[1], options)
        ct1.DrawKeyPoints()
        mss1 = ct1.mss
        for seq in mss1.seqs:
             das.ExtractFeature(seq.points, None)
             agl.ExtractFeature(seq.points, None)
        sc.ExtractFeature(mss1)
        
        mss1.save("_1.tmp")

        ct2 = ExtractMSS()
        ct2.GetContour(args[2], options)
        ct2.DrawKeyPoints()
        mss2 = ct2.mss
        for seq in mss2.seqs:
             das.ExtractFeature(seq.points, None)
             agl.ExtractFeature(seq.points, None)
        sc.ExtractFeature(mss2)
        mss1.save("_2.tmp")
    else:
        mss1 = MSS()
        mss1.load(args[1])
        mss2 = MSS()
        mss2.load(args[2])
    sw = MSS_SW()
    sumsc, bX, bY, sfinal =  sw.align(mss1, mss2)
    print sumsc[0]
    if (options.image):
        myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
        ptcount = 0
        for i in range(len(bX)):
            xs, xi = bX[i]
            ys, yi = bY[i]
            if (xi != -1 and yi != -1):
                    ptcount  += 1
 #                   cv.cvDrawCircle(ct1.drawimg, cv.cvPoint(int(mss1.seq[xs].points[xi].x), int(mss1.seq[xs].points[xi].y)),2, clrs[idx])
                    cv.cvPutText(ct1.drawimg, str(ptcount), cv.cvPoint(int(mss1.seqs[xs].points[xi].x), int(mss1.seqs[xs].points[xi].y)), myfont,  cv.cvScalar(255,255,255,0))
#                    cv.cvDrawCircle(ct2.drawimg, cv.cvPoint(int(bestcurve[yi].x), int(bestcurve[yi].y)),2, clrs[idx])
                    cv.cvPutText(ct2.drawimg, str(ptcount), cv.cvPoint(int(mss2.seqs[ys].points[yi].x), int(mss2.seqs[ys].points[yi].y)), myfont,  cv.cvScalar(255,255,255,0))
        highgui.cvNamedWindow ("contour1", 1)
        highgui.cvNamedWindow ("contour2", 1)
        highgui.cvShowImage ("contour1", ct1.drawimg)
        highgui.cvShowImage ("contour2", ct2.drawimg)
        highgui.cvWaitKey (0)
    if options.output:
        print bX, bY
        fout = open(options.output, 'w')
        for it, b in enumerate(bX):
            fout.write("%d\t%d\t%d\t%d\n" %(b[0], b[1], bY[it][0],bY[it][1]))
        fout.close()