Exemple #1
0
def extract_dir(inputdir, outputdir, options):
    if (inputdir[-1] == "/"):
       inputdir = inputdir[:-1]
    if (outputdir[-1] == "/"):
       outputdir = outputdir[:-1]
    ct = CurvePoint()
    sc = CntSC()
    das = CntDAS()
    agl  = CntAngle()
    allfile = os.listdir(inputdir)
    to_file = options.ter
    start_file = options.start
    if (to_file == -1):
        to_file = len(allfile)
    if (to_file > len(allfile)):
        to_file = len(allfile)
    if (start_file < 0):
       start_file = 0

    for i in range(start_file, to_file):
        f = allfile[i]
        inputfile = inputdir + "/"+ f
        outputfile = outputdir + "/" + f
        ct.LoadCont(inputfile)
        for c in ct.allselected:
            if (options.shapecontext):
                sc.ExtractFeature(c)
            if (options.angle):
                agl.ExtractFeature(c, 0)
            if (options.das):
                das.ExtractFeature(c, 0)
        ct.Save(outputfile)
Exemple #2
0
def main():

    ct = CurvePoint()
    sc = CntSC()

    usage = "%prog [options] <pointfile>"
    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')

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

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

    ct.LoadCont(args[1])
    allkeys = []
    for c in ct.allselected:
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)

    if (options.output):
        ct.Save(options.output)
Exemple #3
0
def extract_file(input, output, options):
    ct = CurvePoint()
    sc = CntSC()
    das = CntDAS()
    agl  = CntAngle()
    
    ct.LoadCont(input)
    for c in ct.allselected:
        if (options.shapecontext):
           sc.ExtractFeature(c)
        if (options.angle):
           agl.ExtractFeature(c, 0)
        if (options.das):
           das.ExtractFeature(c, 0)
    ct.Save(output)
def main():

    ct1 = CurvePoint()
    ct2 = CurvePoint()
    sc = CntSC()
    ang = CntAngle()
     
    
    usage = "%prog [options] <imgfile1> <imgfile2>"
    version = "%prog 0.2\nLongbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-d', '--display', action="store_true", dest = 'display', default = False, help = 'display the image')
    oparser.add_option('-n', '--number', dest = 'num',  type="int", default = 200 , help = 'the number of feature points')
    oparser.add_option('-s', '--save', dest = 'save', default = None, help = 'save the img file')

    oparser.add_option('-o', '--output', dest = 'output', default = None, help = 'output file')

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

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

    ct1.GetContour(args[1], options.num)
    allkeys = []
    for c in ct1.allselected:
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)
    ang.ExtractFeature(allkeys,0); 
    allkeys = []
    ct2.GetContour(args[2], options.num)
    for c in ct2.allselected:
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)
    ang.ExtractFeature(allkeys,0); 

    sumscore = []
    matcher = SmithWaterman()
    ct1.bDrawNumber = 0
    ct2.bDrawNumber = 0
    if (options.display):
        ct1.DrawKeyPoints()
        ct2.DrawKeyPoints()
    myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
    idx = -1
    putoriginal(args[1], ct1.drawimg)
    putoriginal(args[2], ct2.drawimg)
    cv.cvNot(ct1.drawimg, ct1.drawimg)
    cv.cvNot(ct2.drawimg, ct2.drawimg)
    for c1 in ct1.allselected:
        idx += 1
        cscore = -100000000
        cpt1 =   getdata(c1)
        bX = []
        bY = []
        bestcurve = None
        for c2 in ct2.allselected:
            cpt2 =   getdata(c2)
            cost,align,X,Y = matcher.Align(cpt1, cpt2)
            normalized_score = cost - log10(len(c2) + 1) * 1000
            print len(c1), len(c2),cost, normalized_score, cscore
            if (normalized_score > cscore):
                cscore = normalized_score
                bX = X[:]
                bY = Y[:]
                bestcurve = c2
        if (options.display):
            ptcount = 0
            for i in range(len(bX)):
                xi = bX[i]
                yi = bY[i]
                #if (xi == -1):
                    #cv.cvDrawCircle(ct2.drawimg, cv.cvPoint(int(bestcurve[yi].x), int(bestcurve[yi].y)),4, cv.cvScalar(255,0,0,0))
                    #cv.cvPutText(ct2.drawimg, 'O', cv.cvPoint(int(c2[yi].x), int(c2[yi].y)), myfont, cv.cvScalar(255, 0, 0,0))
                #if (yi == -1):
                    #cv.cvDrawCircle(ct1.drawimg, cv.cvPoint(int(c1[xi].x), int(c1[xi].y)),4, cv.cvScalar(255,0,0,0))
                    #cv.cvPutText(ct1.drawimg, 'O', cv.cvPoint(int(c1[xi].x), int(c1[xi].y)), myfont, cv.cvScalar(255, 0, 0,0))
                if (xi != -1 and yi != -1):
                    ptcount  += 1
                    cv.cvDrawCircle(ct1.drawimg, cv.cvPoint(int(c1[xi].x), int(c1[xi].y)),2, clrs[idx])
                    cv.cvPutText(ct1.drawimg, str(ptcount), cv.cvPoint(int(c1[xi].x), int(c1[xi].y)), myfont, clrs[idx])
                    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(bestcurve[yi].x), int(bestcurve[yi].y)), myfont, clrs[idx])
        sumscore.append(cscore)
    print sumscore
    if (options.display):            
	    highgui.cvNamedWindow ("contour1", 1)
	    highgui.cvNamedWindow ("contour2", 1)
	    highgui.cvShowImage ("contour1", ct1.drawimg)
	    highgui.cvShowImage ("contour2", ct2.drawimg)
	    highgui.cvWaitKey (0)       
    if (options.save):
        mergeimg = mergeimage_83(ct1.drawimg, ct2.drawimg)
        highgui.cvSaveImage("_sw_result.bmp", mergeimg)
Exemple #5
0
def main():

    ct1 = CurvePoint()
    ct2 = CurvePoint()
    agl = CntAngle()
    sc = CntSC()

    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:dn:es", ["help", "output=", "draw", "num=", "even", "save"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    output = None
    bDraw = 0
    bSave = 0
    bOriginal = 0
    npoint = 100

    for o, a in opts:
        if o == "-v":
            ct1.verbose = 1
            ct2.verbose = 1
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-o", "--output"):
            output = a
        if o in ("-d", "--draw"):
            bDraw = 1
        if o in ("-s", "--save"):
            bSave = 1
        if o in ("-r", "--original"):
            bOriginal = 1
        if o in ("-n", "--num"):
            npoint = string.atoi(a)
        if o in ("-e", "--even"):
            ct1.bEven = 1
            ct2.bEven = 1
    if (len(args)) != 2:
        usage()
        sys.exit(2)

    ct1.GetContour(args[0], npoint)
    allkeys = []
    for c in ct1.allselected:
        # agl.ExtractFeature(c, ct1.drawimg)
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)

    allkeys = []
    ct2.GetContour(args[1], npoint)
    for c in ct2.allselected:
        # agl.ExtractFeature(c, ct2.drawimg)
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)

    sumscore = []
    matcher = SmithWaterman()
    ct1.bDrawNumber = 0
    ct2.bDrawNumber = 0
    if bDraw:
        ct1.DrawKeyPoints()
        ct2.DrawKeyPoints()
    myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
    idx = -1
    putoriginal(args[0], ct1.drawimg)
    putoriginal(args[1], ct2.drawimg)
    cv.cvNot(ct1.drawimg, ct1.drawimg)
    cv.cvNot(ct2.drawimg, ct2.drawimg)
    for c1 in ct1.allselected:
        idx += 1
        cscore = -100000000
        cpt1 = getdata(c1)
        bX = []
        bY = []
        bestcurve = None
        for c2 in ct2.allselected:
            cpt2 = getdata(c2)
            cost, align, X, Y = matcher.Align(cpt1, cpt2)
            normalized_score = cost - log10(len(c2) + 1) * 1000
            print len(c1), len(c2), cost, normalized_score, cscore
            if normalized_score > cscore:
                cscore = normalized_score
                bX = X[:]
                bY = Y[:]
                bestcurve = c2
        if bDraw:
            ptcount = 0
            for i in range(len(bX)):
                xi = bX[i]
                yi = bY[i]
                # if (xi == -1):
                # cv.cvDrawCircle(ct2.drawimg, cv.cvPoint(int(bestcurve[yi].x), int(bestcurve[yi].y)),4, cv.cvScalar(255,0,0,0))
                # cv.cvPutText(ct2.drawimg, 'O', cv.cvPoint(int(c2[yi].x), int(c2[yi].y)), myfont, cv.cvScalar(255, 0, 0,0))
                # if (yi == -1):
                # cv.cvDrawCircle(ct1.drawimg, cv.cvPoint(int(c1[xi].x), int(c1[xi].y)),4, cv.cvScalar(255,0,0,0))
                # cv.cvPutText(ct1.drawimg, 'O', cv.cvPoint(int(c1[xi].x), int(c1[xi].y)), myfont, cv.cvScalar(255, 0, 0,0))
                if xi != -1 and yi != -1:
                    ptcount += 1
                    cv.cvDrawCircle(ct1.drawimg, cv.cvPoint(int(c1[xi].x), int(c1[xi].y)), 2, clrs[idx])
                    cv.cvPutText(ct1.drawimg, str(ptcount), cv.cvPoint(int(c1[xi].x), int(c1[xi].y)), myfont, clrs[idx])
                    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(bestcurve[yi].x), int(bestcurve[yi].y)),
                        myfont,
                        clrs[idx],
                    )
        sumscore.append(cscore)
    print sumscore
    if bDraw:
        highgui.cvNamedWindow("contour1", 1)
        highgui.cvNamedWindow("contour2", 1)
        highgui.cvShowImage("contour1", ct1.drawimg)
        highgui.cvShowImage("contour2", ct2.drawimg)
        highgui.cvWaitKey(0)
    if bSave:
        mergeimg = mergeimage_83(ct1.drawimg, ct2.drawimg)
        highgui.cvSaveImage("_sw_result.bmp", mergeimg)
def main():

    ct1 = CurvePoint()
    ct2 = CurvePoint()
    sc = CntSC()
    ang = CntAngle()

    usage = "%prog [options] <imgfile1> <imgfile2>"
    version = "%prog 0.2\nLongbin Chen, [email protected]"
    oparser = optparse.OptionParser(usage=usage, version=version)
    oparser.add_option('-d',
                       '--display',
                       action="store_true",
                       dest='display',
                       default=False,
                       help='display the image')
    oparser.add_option('-n',
                       '--number',
                       dest='num',
                       type="int",
                       default=200,
                       help='the number of feature points')
    oparser.add_option('-s',
                       '--save',
                       dest='save',
                       default=None,
                       help='save the img file')

    oparser.add_option('-o',
                       '--output',
                       dest='output',
                       default=None,
                       help='output file')

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

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

    ct1.GetContour(args[1], options.num)
    allkeys = []
    for c in ct1.allselected:
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)
    ang.ExtractFeature(allkeys, 0)
    allkeys = []
    ct2.GetContour(args[2], options.num)
    for c in ct2.allselected:
        allkeys = allkeys + c
    sc.ExtractFeature(allkeys)
    ang.ExtractFeature(allkeys, 0)

    sumscore = []
    matcher = SmithWaterman()
    ct1.bDrawNumber = 0
    ct2.bDrawNumber = 0
    if (options.display):
        ct1.DrawKeyPoints()
        ct2.DrawKeyPoints()
    myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
    idx = -1
    putoriginal(args[1], ct1.drawimg)
    putoriginal(args[2], ct2.drawimg)
    cv.cvNot(ct1.drawimg, ct1.drawimg)
    cv.cvNot(ct2.drawimg, ct2.drawimg)
    for c1 in ct1.allselected:
        idx += 1
        cscore = -100000000
        cpt1 = getdata(c1)
        bX = []
        bY = []
        bestcurve = None
        for c2 in ct2.allselected:
            cpt2 = getdata(c2)
            cost, align, X, Y = matcher.Align(cpt1, cpt2)
            normalized_score = cost - log10(len(c2) + 1) * 1000
            print len(c1), len(c2), cost, normalized_score, cscore
            if (normalized_score > cscore):
                cscore = normalized_score
                bX = X[:]
                bY = Y[:]
                bestcurve = c2
        if (options.display):
            ptcount = 0
            for i in range(len(bX)):
                xi = bX[i]
                yi = bY[i]
                #if (xi == -1):
                #cv.cvDrawCircle(ct2.drawimg, cv.cvPoint(int(bestcurve[yi].x), int(bestcurve[yi].y)),4, cv.cvScalar(255,0,0,0))
                #cv.cvPutText(ct2.drawimg, 'O', cv.cvPoint(int(c2[yi].x), int(c2[yi].y)), myfont, cv.cvScalar(255, 0, 0,0))
                #if (yi == -1):
                #cv.cvDrawCircle(ct1.drawimg, cv.cvPoint(int(c1[xi].x), int(c1[xi].y)),4, cv.cvScalar(255,0,0,0))
                #cv.cvPutText(ct1.drawimg, 'O', cv.cvPoint(int(c1[xi].x), int(c1[xi].y)), myfont, cv.cvScalar(255, 0, 0,0))
                if (xi != -1 and yi != -1):
                    ptcount += 1
                    cv.cvDrawCircle(ct1.drawimg,
                                    cv.cvPoint(int(c1[xi].x), int(c1[xi].y)),
                                    2, clrs[idx])
                    cv.cvPutText(ct1.drawimg, str(ptcount),
                                 cv.cvPoint(int(c1[xi].x), int(c1[xi].y)),
                                 myfont, clrs[idx])
                    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(bestcurve[yi].x), int(bestcurve[yi].y)),
                        myfont, clrs[idx])
        sumscore.append(cscore)
    print sumscore
    if (options.display):
        highgui.cvNamedWindow("contour1", 1)
        highgui.cvNamedWindow("contour2", 1)
        highgui.cvShowImage("contour1", ct1.drawimg)
        highgui.cvShowImage("contour2", ct2.drawimg)
        highgui.cvWaitKey(0)
    if (options.save):
        mergeimg = mergeimage_83(ct1.drawimg, ct2.drawimg)
        highgui.cvSaveImage("_sw_result.bmp", mergeimg)