示例#1
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])
示例#2
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])
示例#3
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()