コード例 #1
0
ファイル: nodes.py プロジェクト: janfrs/kwc-ros-pkg
				def circ(n): 
					pt  = cv.cvPoint(int(round(n[0,0])),int(round(n[1,0]))) 
					cv.cvCircle(self.disp.buffer, pt, size, 
							color_scalar, cv.CV_FILLED, cv.CV_AA) 
					pt2 = cv.cvPoint(pt.x + 2, pt.y + 2) 
					cv.cvPutText(self.disp.buffer, text, pt,  self.disp.font, cv.cvScalar(255,255,255)) 
					cv.cvPutText(self.disp.buffer, text, pt2, self.disp.font, cv.cvScalar(50,50,50)) 
コード例 #2
0
ファイル: nodes.py プロジェクト: Calm-wy/kwc-ros-pkg
 def circ(n):
     pt = cv.cvPoint(int(round(n[0, 0])), int(round(n[1, 0])))
     cv.cvCircle(self.disp.buffer, pt, size, color_scalar,
                 cv.CV_FILLED, cv.CV_AA)
     pt2 = cv.cvPoint(pt.x + 2, pt.y + 2)
     cv.cvPutText(self.disp.buffer, text, pt, self.disp.font,
                  cv.cvScalar(255, 255, 255))
     cv.cvPutText(self.disp.buffer, text, pt2, self.disp.font,
                  cv.cvScalar(50, 50, 50))
コード例 #3
0
 def DrawKeyPoints(self):
     ic = 0
     myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
     for ic, c in enumerate(self.mss.seqs):
         for k in c.points:
             if self.bDrawNumber:
                 cv.cvPutText(
                     self.drawimg, str(ic), cv.cvPoint(int(k.x), int(k.y)), myfont, cv.cvScalar(255, 255, 0, 0)
                 )
             cv.cvDrawCircle(self.drawimg, cv.cvPoint(int(k.x), int(k.y)), 4, cv.cvScalar(255, 0, 255, 0))
コード例 #4
0
ファイル: link.py プロジェクト: kingang1986/shapematching
    def DrawKeyPoints(self):
        if (not self.drawimg):
            self.drawimg = cv.cvCloneImage(self.img) 

        myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
        ic = 0
        for c in self.points:
            cv.cvPutText(self.drawimg, str(ic), cv.cvPoint(int(c.x), int(c.y)), myfont, cv.cvScalar(255, 255, 0,0))
            ic += 1
            cv.cvDrawCircle(self.drawimg, c, 4, cv.cvScalar(255,255,0,0))
コード例 #5
0
ファイル: link.py プロジェクト: kingang1986/shapematching
    def DrawKeyPoints(self):
        if (not self.drawimg):
            self.drawimg = cv.cvCloneImage(self.img)

        myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
        ic = 0
        for c in self.points:
            cv.cvPutText(self.drawimg, str(ic), cv.cvPoint(int(c.x), int(c.y)),
                         myfont, cv.cvScalar(255, 255, 0, 0))
            ic += 1
            cv.cvDrawCircle(self.drawimg, c, 4, cv.cvScalar(255, 255, 0, 0))
コード例 #6
0
def main(): # ctrl+c to end
    global h,s,v,h2,v2,s2,d,e
    highgui.cvNamedWindow("Camera 1", 1)
    highgui.cvNamedWindow("Orig", 1)
    highgui.cvCreateTrackbar("H", "Camera 1", h, 256, tb_h)
    highgui.cvCreateTrackbar("S", "Camera 1", s, 256, tb_s)
    highgui.cvCreateTrackbar("V", "Camera 1", v, 256, tb_v)
    highgui.cvCreateTrackbar("H2", "Camera 1", h2, 256, tb_h2)
    highgui.cvCreateTrackbar("S2", "Camera 1", s2, 256, tb_s2)
    highgui.cvCreateTrackbar("V2", "Camera 1", v2, 256, tb_v2)
    highgui.cvCreateTrackbar("Dilate", "Camera 1", d, 30, tb_d)
    highgui.cvCreateTrackbar("Erode", "Camera 1", e, 30, tb_e)
    
    cap = highgui.cvCreateCameraCapture(1)
    highgui.cvSetCaptureProperty(cap, highgui.CV_CAP_PROP_FRAME_WIDTH, IMGW)
    highgui.cvSetCaptureProperty(cap, highgui.CV_CAP_PROP_FRAME_HEIGHT, IMGH)
    c = 0
    t1 = tdraw = time.clock()
    t = 1
    font = cv.cvInitFont(cv.CV_FONT_HERSHEY_PLAIN, 1, 1)
    while c != 0x27:
        image = highgui.cvQueryFrame(cap)
        if not image:
            print "capture failed"
            break
            
        thresh = cv.cvCreateImage(cv.cvSize(IMGW,IMGH),8,1)
        cv.cvSetZero(thresh)
        cv.cvCvtColor(image,image,cv.CV_RGB2HSV)
        cv.cvInRangeS(image, (h,s,v,0), (h2,s2,v2,0), thresh)
        result = cv.cvCreateImage(cv.cvSize(IMGW,IMGH),8,3)
        cv.cvSetZero(result)
        
        cv.cvOr(image,image,result,thresh)
        for i in range(1,e):
            cv.cvErode(result,result)
        for i in range(1,d):
            cv.cvDilate(result,result)
            
        # floodfill objects back in, allowing threshold differences outwards
        
        t2 = time.clock()
        if t2 > tdraw+0.3:
            t = t2-t1
            tdraw=t2
        cv.cvPutText(result, "FPS: " + str(1 / (t)), (0,25), font, (255,255,255))
        t1 = t2
        highgui.cvShowImage("Orig", image)
        highgui.cvShowImage("Camera 1", result)
        c = highgui.cvWaitKey(10)
コード例 #7
0
ファイル: chroma.py プロジェクト: bmiro/vpc
def getBackground(frameWidht, frameHeight):
    cvNamedWindow("Background")
    
    text = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3)
    frame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3)
    background = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3)

    font = cvInitFont(CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0.0, 2)
    pt1 = cvPoint(50, 100)
    pt2 = cvPoint(50, 150)
    center = cvPoint(frameWidth/2, frameHeight/2)
    cvPutText(text, "Press enter, run away and wait", pt1, font, CV_RGB(150, 100, 150))
    cvPutText(text, str(delayS) + " seconds to capture background", pt2, font, CV_RGB(150, 100, 150))
    cvShowImage("Background", text)
        
    key = -1
    while key == -1:
        key = cvWaitKey(10)    
        
    like = False
    while not like:
        for i in range(delayS):
            cvZero(text)
            cvPutText(text, str(delayS-i), center, font, CV_RGB(150, 100, 150))
            cvShowImage("Background", text)
            cvWaitKey(1000)
    
        csut = camStartUpTime
        while (csut): # Stats capturing frames in order to give time to the cam to auto-adjust colors
            if not cvGrabFrame(CAM):
                print "Could not grab a frame"
                exit
            cvWaitKey(10)
            csut -= 1
        frame = cvQueryFrame(CAM)
        cvCopy(frame, background)
        
        cvCopy(frame, text)
        cvPutText(text, "Is correct? [y/n]", center, font, CV_RGB(150, 100, 150))

        cvShowImage("Background", text)
        
        key = -1
        while key != 'n' and key != 'y':
            key = cvWaitKey(10)
            if key == 'y': 
                like = True
                
    return background        
    cvDestroyWindow("Background")
コード例 #8
0
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)
コード例 #9
0
ファイル: CRSW_Img.py プロジェクト: ucsb-ilabs/shapematching
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)
コード例 #10
0
ファイル: plane2point.py プロジェクト: jlefley/igvrt-uiuc
        variable_base = v/10.0
    xmatch = size.width / 2 + 1
    ymatch = size.height / 2 + 1
    highgui.cvSetMouseCallback("depthmatch - left", mousecb)
    highgui.cvCreateTrackbar("ROI", "depthmatch - left", variable_roi, size.width, cb_roi)
    highgui.cvCreateTrackbar("Buffer", "depthmatch - left", variable_buf, size.width, cb_buf)
    highgui.cvCreateTrackbar("Focal Length", "depthmatch - left", variable_focal, 1000, cb_focal)
    highgui.cvCreateTrackbar("Baseline/10", "depthmatch - left", variable_base, 1000, cb_base)
    leftdraw = cv.cvCreateImage(size, 8, 3)
    rightdraw = cv.cvCreateImage(size, 8, 3)
    while 1:
        depth = depthmatch(xmatch, ymatch, left, right, roi=variable_roi, buf=variable_buf,baseline=variable_base, focal_length=variable_focal)
        cv.cvCopy(left, leftdraw)
        cv.cvCopy(right, rightdraw)
        cv.cvLine(leftdraw, depth[1], depth[2], (0,255,0), 2)
        cv.cvPutText(leftdraw, "%2f(m) at (%2f,%2f)" % (depth[0][2],depth[0][0],depth[0][1]), (xmatch,ymatch), font, (0,0,255))
        cv.cvLine(rightdraw, depth[2], depth[2], (0,0,255), 5)
        highgui.cvShowImage("depthmatch - left", leftdraw)
        highgui.cvShowImage("depthmatch - right", rightdraw)
        print depth
        highgui.cvWaitKey(10)
        
        
if __name__ == "__main__" and test_number == 2:
    left = highgui.cvLoadImage(str(sys.argv[1]))
    right = highgui.cvLoadImage(str(sys.argv[2]))
    highgui.cvNamedWindow("Depth")
    depth = depthmatrix(left, right, 4)
    depth_full = cv.cvCreateImage(cv.cvGetSize(left), 8, 1)
    cv.cvResize(depth, depth_full)
    highgui.cvShowImage("Depth", depth_full)
コード例 #11
0
ファイル: 3d.py プロジェクト: jlefley/igvrt-uiuc
def depthmatch(x,y,leftimage,rightimage,roi=20,buf=10,debug=False):
    __doc__ = """depthmatch function
    x,y : (int) pixel position of target in left image
    leftimage, rightimage : (IplImage) stereo images
    roi: (int) region of interest around x,y to use in matching
    buf: (int) buffer outside of a straight horizontal search for a match
    """
    info = cv.cvGetSize(leftimage)
    width = info.width
    height = info.height

    (y1,x1,y2,x2) = (y-roi,x-roi,y+roi,x+roi)
    #template = cv.cvCreateImage((roi*2,roi*2), 8, 3)
    if y1<0: y1 = 0
    if x1<0: x1 = 0
    if y2>height: y2 = height
    if x2>width: x2 = width
    #cv.cvSetZero(template)
    # copy subregion roi x roi

    template_rect = cv.cvRect(x1,y1,(x2-x1),(y2-y1))
    template = cv.cvGetSubRect(leftimage, template_rect)
    (y3,x3,y4,x4) = (y-roi-buf,x-roi-buf,y+roi+buf,width) # +/- 20 pixels in vertical direction, -20 to the right edge
    if x3<0: x3 = 0
    if y3<0: y3 = 0
    if x4>=width: x4 = width-1
    if y4>height: y4 = height
    #cv.cvSetImageROI(rightimage, (y3,x3,y4,x4))

    rightsub_rect = cv.cvRect(x3,y3,(x4-x3),(y4-y3))
    rightsub = cv.cvGetSubRect(rightimage, rightsub_rect)
    # result matrix should be (W - w + 1) x (H - h + 1) where WxH are template dimensions, wxh are rightsub dimensions
    W = x4-x3
    H = y4-y3
    w = x2-x1
    h = y2-y1

    resy = (y4-y3)-(y2-y1)+1
    resx = (x4-x3)-(x2-x1)+1

    resultmat = cv.cvCreateImage((resx, resy), 32, 1)
    cv.cvZero(resultmat)
    # match template image in a subportion of rightimage
    cv.cvMatchTemplate(rightsub, template, resultmat, cv.CV_TM_SQDIFF)
    min_val, max_val, min_point, max_point = cv.cvMinMaxLoc(resultmat)
    cv.cvNormalize(resultmat, resultmat, 1, 0, cv.CV_MINMAX)
    depth = stereo.depth(x, x3+min_point.x, max_pixels=width/2)
    
    if debug:
        print "Input image: %ix%i, target: (%i,%i)" % (width,height,x,y)
        print "Template box: (%i,%i) to (%i,%i)" % (x1, y1, x2, y2)
        print "Search area: (%i,%i) to (%i,%i)" % (x3, y3, x4, y4)
        print "%ix%i, %ix%i" % (W,H,w,h)
        print "Result matrix %ix%i" % (resx, resy)
        print "stereo.depth(%i,%i,max_pixels=%i)" % (x, min_point.x+x3,width/2)
        if depth[0]:
            print "Depth: ", depth[0], "(cm)"
        #cv.cvRectangle(rightimage, cv.cvPoint(x1,y1), cv.cvPoint(x2,y2), (255,0,0))
        cv.cvRectangle(rightimage, cv.cvPoint(min_point.x+x3,min_point.y+y3), cv.cvPoint(min_point.x+x3+roi*2,min_point.y+y3+roi*2), (0,255,0))
        cv.cvRectangle(rightimage, cv.cvPoint(x3,y3), cv.cvPoint(x4,y4), (0,0,255))
        cv.cvRectangle(leftimage, cv.cvPoint(x1,y1), cv.cvPoint(x2,y2), (255,0,0))
        #cv.cvRectangle(leftimage, cv.cvPoint(min_point.x+x3,min_point.y+y3), cv.cvPoint(min_point.x+x3+roi*2,min_point.y+y3+roi*2), (0,255,0))
        cv.cvRectangle(leftimage, cv.cvPoint(x3,y3), cv.cvPoint(x4,y4), (0,0,255))
        if depth[0]:
            cv.cvPutText(leftimage, "%5f(cm)" % depth[0], (x1,y1), font, (255,255,255))
        highgui.cvShowImage("depthmatch - template", template)
        highgui.cvShowImage("depthmatch - match", resultmat)
        highgui.cvShowImage("depthmatch - right", rightimage)
        highgui.cvShowImage("depthmatch - left", leftimage)
コード例 #12
0
ファイル: drawing.py プロジェクト: knewter/CoinVision
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # draw some text
    for i in range (number):
        pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
                          random.randrange (-height, 2 * height))
        font = cv.cvInitFont (random.randrange (0, 8),
                              random.randrange (0, 100) * 0.05 + 0.01,
                              random.randrange (0, 100) * 0.05 + 0.01,
                              random.randrange (0, 5) * 0.1,
                              random.randrange (0, 10),
                              line_type)

        cv.cvPutText (image, "Testing text rendering!",
                      pt1, font,
                      random_color (random))
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # prepare a text, and get it's properties
    font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX,
                          3, 3, 0.0, 5, line_type)
    text_size, ymin = cv.cvGetTextSize ("OpenCV forever!", font)
    pt1.x = (width - text_size.width) / 2
    pt1.y = (height + text_size.height) / 2
    image2 = cv.cvCloneImage(image)

    # now, draw some OpenCV pub ;-)
    for i in range (255):
コード例 #13
0
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)
コード例 #14
0
            # utilsation de ControlPeriph
            MouseControl.mouse_warp(souris, centrePointeur[0].x,
                                    centrePointeur[0].y, 0, 0)

            # envoie des coordonnees de pointeur via  protocole Tuio
            ##if first2==0:
            ##    sendTuioMess()

        first = 0
        if GUI == 1:
            #on trace un cercle sur les pointeurs
            for i in range(0, len(centrePointeur)):
                cv.cvCircle(frame, centrePointeur[i], 5, color, 2, 6, 0)
                #if first2==0:
                #    cv.cvPutText(frame, str(id_Pointeur[i]), centrePointeur[i], font, color2)
            cv.cvPutText(frame, str(len(centrePointeur)), cv.cvPoint(20, 30),
                         font, color)  # affiche le nombre de pointeur

            # message "config saved" temporaire
            if mess_saved < 20 and mess_saved != 0:
                cv.cvPutText(frame, "config saved", cv.cvPoint(20, 100), font,
                             color)
                mess_saved = mess_saved + 1
                if mess_saved == 19:
                    mess_saved = 0

            # we can now display the images
            highgui.cvShowImage('Camera', frame)
            highgui.cvShowImage('Binarisation', frameBin)
            highgui.cvShowImage('1-without background', framewithoutbg)
            highgui.cvShowImage('2-amplifie', framemul)
            highgui.cvShowImage('3-lisser-Smooth', framelisser1)
コード例 #15
0
ファイル: SW_Img.py プロジェクト: kingang1986/shapematching
def main():

    ct1 = CntPoint()
    ct2 = CntPoint()
    agl = CntAngle()
    das = CntDAS()
    das.bDraw = 0

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

    for o, a in opts:
        if o == "-v":
            ct.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 ("-n", "--num"):
            npoint = string.atoi(a)
        if o in ("-e", "--even"):
            ct.bEven = 1
    if (len(args)) != 2:
        usage()
        sys.exit(2)

    ct1.GetContour(args[0], npoint)

    agl.ExtractFeature(ct1.GetKeyPoints(), ct1.drawimg)
    das.ExtractFeature(ct1.GetKeyPoints(), ct1.drawimg)

    ct2.GetContour(args[1], npoint)
    agl.ExtractFeature(ct2.GetKeyPoints(), ct2.drawimg)
    das.ExtractFeature(ct2.GetKeyPoints(), ct2.drawimg)

    seq1 = getdata(ct1.GetKeyPoints())
    seq2 = getdata(ct2.GetKeyPoints())
    matcher = SmithWaterman()
    cost, align, X, Y = matcher.Align(seq1, seq2)
    myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
    if (bDraw):
        ct1.DrawKeyPoints()
        kpoints1 = ct1.GetKeyPoints()
        ct2.DrawKeyPoints()
        kpoints2 = ct2.GetKeyPoints()
        ptcount = 0
        for i in range(len(X)):
            xi = X[i]
            yi = Y[i]
            if (xi == -1):
                cv.cvPutText(
                    ct2.drawimg, 'O',
                    cv.cvPoint(int(kpoints2[yi].x), int(kpoints2[yi].y)),
                    myfont, cv.cvScalar(255, 0, 0, 0))
            if (yi == -1):
                cv.cvPutText(
                    ct1.drawimg, 'O',
                    cv.cvPoint(int(kpoints1[xi].x), int(kpoints1[xi].y)),
                    myfont, cv.cvScalar(255, 0, 0, 0))
            if (xi != -1 and yi != -1):
                ptcount += 1
                cv.cvPutText(
                    ct1.drawimg, str(ptcount),
                    cv.cvPoint(int(kpoints1[xi].x), int(kpoints1[xi].y)),
                    myfont, cv.cvScalar(255, 255, 0, 0))
                cv.cvPutText(
                    ct2.drawimg, str(ptcount),
                    cv.cvPoint(int(kpoints2[yi].x), int(kpoints2[yi].y)),
                    myfont, cv.cvScalar(255, 255, 0, 0))

        highgui.cvNamedWindow("contour1", 1)
        highgui.cvNamedWindow("contour2", 1)
        highgui.cvShowImage("contour1", ct1.drawimg)
        highgui.cvShowImage("contour2", ct2.drawimg)
        highgui.cvWaitKey(0)
コード例 #16
0
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # draw some text
    for i in range (number):
        pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
                          random.randrange (-height, 2 * height))
        font = cv.cvInitFont (random.randrange (0, 8),
                              random.randrange (0, 100) * 0.05 + 0.01,
                              random.randrange (0, 100) * 0.05 + 0.01,
                              random.randrange (0, 5) * 0.1,
                              random.randrange (0, 10),
                              line_type)

        cv.cvPutText (image, "Testing text rendering!",
                      pt1, font,
                      random_color (random))
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # prepare a text, and get it's properties
    font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX,
                          3, 3, 0.0, 5, line_type)
    text_size, ymin = cv.cvGetTextSize ("OpenCV forever!", font)
    pt1.x = (width - text_size.width) / 2
    pt1.y = (height + text_size.height) / 2
    image2 = cv.cvCloneImage(image)

    # now, draw some OpenCV pub ;-)
    for i in range (255):
コード例 #17
0
ファイル: SW_Img.py プロジェクト: kingang1986/shapematching
def main():

    ct1 = CntPoint()
    ct2 = CntPoint()
    agl = CntAngle()
    das = CntDAS()
    das.bDraw = 0


    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:dn:e", ["help", "output=", "draw", "num=", "even"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    output = None
    bDraw = 0
    npoint = 100
     
    for o, a in opts:
        if o == "-v":
            ct.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 ("-n", "--num"):
            npoint = string.atoi(a)
        if o in ("-e", "--even"):
            ct.bEven = 1
    if (len(args)) != 2:
        usage()
        sys.exit(2)
    
    ct1.GetContour(args[0], npoint)
    
    agl.ExtractFeature(ct1.GetKeyPoints(), ct1.drawimg)
    das.ExtractFeature(ct1.GetKeyPoints(), ct1.drawimg)
    
    ct2.GetContour(args[1], npoint)
    agl.ExtractFeature(ct2.GetKeyPoints(), ct2.drawimg)
    das.ExtractFeature(ct2.GetKeyPoints(), ct2.drawimg)

    
    seq1 = getdata(ct1.GetKeyPoints())
    seq2 = getdata(ct2.GetKeyPoints())
    matcher = SmithWaterman()
    cost,align,X,Y = matcher.Align(seq1, seq2)
    myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
    if (bDraw):
        ct1.DrawKeyPoints()
        kpoints1 = ct1.GetKeyPoints()
        ct2.DrawKeyPoints()
        kpoints2 = ct2.GetKeyPoints()
        ptcount = 0
        for i in range(len(X)):
            xi = X[i]
            yi = Y[i]
            if (xi == -1):
                cv.cvPutText(ct2.drawimg, 'O', cv.cvPoint(int(kpoints2[yi].x), int(kpoints2[yi].y)), myfont, cv.cvScalar(255, 0, 0,0))
            if (yi == -1):
                cv.cvPutText(ct1.drawimg, 'O', cv.cvPoint(int(kpoints1[xi].x), int(kpoints1[xi].y)), myfont, cv.cvScalar(255, 0, 0,0))
            if (xi != -1 and yi != -1):
                ptcount  += 1
                cv.cvPutText(ct1.drawimg, str(ptcount), cv.cvPoint(int(kpoints1[xi].x), int(kpoints1[xi].y)), myfont, cv.cvScalar(255, 255, 0,0))
                cv.cvPutText(ct2.drawimg, str(ptcount), cv.cvPoint(int(kpoints2[yi].x), int(kpoints2[yi].y)), myfont, cv.cvScalar(255, 255, 0,0))
            
        highgui.cvNamedWindow ("contour1", 1)
        highgui.cvNamedWindow ("contour2", 1)
        highgui.cvShowImage ("contour1", ct1.drawimg)
        highgui.cvShowImage ("contour2", ct2.drawimg)
        highgui.cvWaitKey (0)