Exemplo n.º 1
0
 def test_decode(self):
     a= Square.SQ_SIZE
     b = a*(Square.GRID_SIZE+3)
     rect = [(a,a),(b,a),(b,b),(a,b)]
     m_d = SquareDetector(Square.generate(1),0)
     for i in range(32):
         img = Square.generate(i)
         sq = Square(i,m_d)
         m_d.gray_img=img
         a,b = sq._decode_rect(rect)
         self.assertTrue((sq.TOP_LEFT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
         cv.Transpose(img, img)
         cv.Flip(img)
         a,b = sq._decode_rect(rect)
         self.assertTrue((sq.BOT_LEFT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
         cv.Transpose(img, img)
         cv.Flip(img)
         a,b = sq._decode_rect(rect)
         self.assertTrue((sq.BOT_RIGHT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
         cv.Transpose(img, img)
         cv.Flip(img)
         a,b = sq._decode_rect(rect)
         self.assertTrue((sq.TOP_RIGHT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
     m_d.flip_H=True
     for i in range(32):
         img = Square.generate(i)
         sq = Square(i,m_d)
         m_d.gray_img=img
         cv.Flip(img,img,1)
         _,b = sq._decode_rect(rect)
         self.assertTrue(i==b,"Wrong Flip %d: (%d)"%(i,b))
Exemplo n.º 2
0
def main():
    if CAM == 0:
        provider = MovieImageProvider('../resources/Video5.avi', 0, 0)
    else:
        provider = CamImageProvider(0, '../resources/Video5.avi')
    db.start_at(provider, 110)
    img, imgtime = provider.update_image()
    print(img, imgtime, time.time())
    db.pr([img])
    sd = SquareDetector(img)  # ,imgtime,1, False )
    for i in [0, 30]:
        sd.add_marker(Square(i))

    # win='Result'
    # canny='Canny'
    # tmp='Temp'
    # cv.NamedWindow(win)
    # cv.NamedWindow(tmp)
    # cv.MoveWindow(win,0,0)
    # cv.MoveWindow(tmp,650,0)
    ti = 0.01
    while True:
        k = cv.WaitKey(1)
        if k == 27:
            break
        elif k == 2424832:
            step = -1
        elif k == 32:
            cv.WaitKey(delay=0)
            step = 1
        else:
            step = 1
        start = time.time()
        img, imgtime = provider.update_image()
        if img is None:
            break
        if provider.index == 112:
            pass
        sq = sd.find_markers(img, imgtime)
        sd.draw_markers(img)
        sd.putText("Frame: %d %.3f FPS" % (provider.index, (1 / ti)), (0, 15),
                   (0, 0, 0))
        cv.ShowImage('test', sd.draw_img)
        db.show([img, sd.draw_img, sd.bw_img], 'main', 0, 10)
        ti = time.time() - start
        cv.WaitKey(1)
Exemplo n.º 3
0
def main():
    if CAM == 0:
        provider = MovieImageProvider('../resources/Video5.avi', 0, 0)
    else:
        provider = CamImageProvider(0, '../resources/Video5.avi')
    db.start_at(provider, 110)
    img, imgtime = provider.update_image()
    print(img, imgtime, time.time())
    db.pr([img]);
    sd = SquareDetector(img)  # ,imgtime,1, False )
    for i in [0, 30]:
        sd.add_marker(Square(i))

    # win='Result'
    # canny='Canny'
    # tmp='Temp'
    # cv.NamedWindow(win)
    # cv.NamedWindow(tmp)
    # cv.MoveWindow(win,0,0)
    # cv.MoveWindow(tmp,650,0)
    ti = 0.01
    while True:
        k = cv.WaitKey(1)
        if k == 27:
            break
        elif k == 2424832:
            step = -1
        elif k == 32:
            cv.WaitKey(delay=0)
            step = 1
        else:
            step = 1;
        start = time.time()
        img, imgtime = provider.update_image()
        if img == None:
            break;
        if provider.index == 112:
            pass
        sq = sd.find_markers(img, imgtime)
        sd.draw_markers(img)
        sd.putText("Frame: %d %.3f FPS" % (provider.index, (1 / ti)), (0, 15), (0, 0, 0))
        cv.ShowImage('test', sd.draw_img)
        db.show([img, sd.draw_img, sd.bw_img], 'main', 0, 10)
        ti = time.time() - start
        cv.WaitKey(1)
Exemplo n.º 4
0
def main():
    ip= CamImageProvider(0, "../resources/testdata.avi")
    #ip = MovieImageProvider("../resources/testdata.avi",0,0)
    sq = Square(0)
    img,imgtime = ip.getImage(1)
    m_d = SquareDetector(img, imgtime, 2, 0)
    m_d.add_marker(sq)
    angle_min = math.pi
    angle_max = 0
    angle_diff_min = 100
    angle_diff_max = 0
    prop_min  = 40
    prop_max = 0
    rot_max = 0
    debug.start_at(ip, 0)
    while cv.WaitKey(1)<>27:
        img,imgtime = ip.getImage(1)
        if img is None:
            return
#        tmpimg = cv.CloneImage(draw_img)
#        tmpimg2 = cv.CloneImage(draw_img)
#        gray2 = cv.CloneImage(gray)
#        gray3 = cv.CloneImage(gray)
#        tmp = cv.CloneImage(gray)
#        mask = cv.CloneImage(gray)
#        mask2=cv.CloneImage(gray)
#        cv.Set(mask2,1)
#        cv.CvtColor(draw_img, gray, cv.CV_BGR2GRAY)
#        cv.CvtColor(draw_img, tmpimg, cv.CV_BGR2HSV)
#        cv.SetImageCOI(tmpimg, 1)
#        cv.Copy(tmpimg, gray)
#        print cv.MinMaxLoc(gray)
#        cv.ShowImage("gray", gray)
        if debug.is_time():
            pass
        m_d.find_markers(img,imgtime,True)
        mar = m_d.markers[0]
        points = mar.points
        m_d.draw_markers(m_d.draw_img)
        debug.show([m_d.draw_img],"main",1,1)
        #debug.show_images()
        if len(points)<>4 or cv.WaitKey(50)<>32: 
            continue
        a = length(vector(points[0],points[1]))
        b = length(vector(points[1],points[2]))
        c = length(vector(points[2],points[3]))
        d = length(vector(points[3],points[0]))
        if a>c:
            a,c = c,a
        if b>d:
            b,d = d,b
        if c == 0.0:
            print mar
        else:
            print "sides a/c:", a/c
            if a/c > prop_max: prop_max = a/c
            if a/c < prop_min: prop_min = a/c
        if d==0.0:
            print mar
        else:
            print "sides b/d", b/d
            if b/d > prop_max: prop_max = b/d
            if b/d < prop_min: prop_min = b/d
        for cor in mar.corners:
            if cor.angle < angle_min:angle_min = cor.angle
            if cor.angle > angle_max:angle_max = cor.angle
            if cor.rotation > rot_max: rot_max = cor.rotation
        a,b,c,d = [c.angle for c in mar.corners]
        if a>c:
            a,c=c,a
        if b>d:
            b,d=d,b
        if a/c > angle_diff_max: angle_diff_max=a/c
        if a/c< angle_diff_min: angle_diff_min = a/c
        print "angle diff a/c", a/c
        if b/d > angle_diff_max: angle_diff_max=b/d
        if b/d< angle_diff_min: angle_diff_min = b/d
        print "angle diff b/d", b/d
                
    print "angle_min", angle_min
    print "angle_max", angle_max
    print "prop_min", prop_min
    print "prop_max", prop_max
    print "rot_max",rot_max
    print "angle_diff_min", angle_diff_min
    print "angle_diff_max",angle_diff_max
Exemplo n.º 5
0
def main():
    ip = CamImageProvider(0, "../resources/testdata.avi")
    #ip = MovieImageProvider("../resources/testdata.avi",0,0)
    sq = Square(0)
    img, imgtime = ip.getImage(1)
    m_d = SquareDetector(img, imgtime, 2, 0)
    m_d.add_marker(sq)
    angle_min = math.pi
    angle_max = 0
    angle_diff_min = 100
    angle_diff_max = 0
    prop_min = 40
    prop_max = 0
    rot_max = 0
    debug.start_at(ip, 0)
    while cv.WaitKey(1) <> 27:
        img, imgtime = ip.getImage(1)
        if img is None:
            return


#        tmpimg = cv.CloneImage(draw_img)
#        tmpimg2 = cv.CloneImage(draw_img)
#        gray2 = cv.CloneImage(gray)
#        gray3 = cv.CloneImage(gray)
#        tmp = cv.CloneImage(gray)
#        mask = cv.CloneImage(gray)
#        mask2=cv.CloneImage(gray)
#        cv.Set(mask2,1)
#        cv.CvtColor(draw_img, gray, cv.CV_BGR2GRAY)
#        cv.CvtColor(draw_img, tmpimg, cv.CV_BGR2HSV)
#        cv.SetImageCOI(tmpimg, 1)
#        cv.Copy(tmpimg, gray)
#        print cv.MinMaxLoc(gray)
#        cv.ShowImage("gray", gray)
        if debug.is_time():
            pass
        m_d.find_markers(img, imgtime, True)
        mar = m_d.markers[0]
        points = mar.points
        m_d.draw_markers(m_d.draw_img)
        debug.show([m_d.draw_img], "main", 1, 1)
        #debug.show_images()
        if len(points) <> 4 or cv.WaitKey(50) <> 32:
            continue
        a = length(vector(points[0], points[1]))
        b = length(vector(points[1], points[2]))
        c = length(vector(points[2], points[3]))
        d = length(vector(points[3], points[0]))
        if a > c:
            a, c = c, a
        if b > d:
            b, d = d, b
        if c == 0.0:
            print mar
        else:
            print "sides a/c:", a / c
            if a / c > prop_max: prop_max = a / c
            if a / c < prop_min: prop_min = a / c
        if d == 0.0:
            print mar
        else:
            print "sides b/d", b / d
            if b / d > prop_max: prop_max = b / d
            if b / d < prop_min: prop_min = b / d
        for cor in mar.corners:
            if cor.angle < angle_min: angle_min = cor.angle
            if cor.angle > angle_max: angle_max = cor.angle
            if cor.rotation > rot_max: rot_max = cor.rotation
        a, b, c, d = [c.angle for c in mar.corners]
        if a > c:
            a, c = c, a
        if b > d:
            b, d = d, b
        if a / c > angle_diff_max: angle_diff_max = a / c
        if a / c < angle_diff_min: angle_diff_min = a / c
        print "angle diff a/c", a / c
        if b / d > angle_diff_max: angle_diff_max = b / d
        if b / d < angle_diff_min: angle_diff_min = b / d
        print "angle diff b/d", b / d

    print "angle_min", angle_min
    print "angle_max", angle_max
    print "prop_min", prop_min
    print "prop_max", prop_max
    print "rot_max", rot_max
    print "angle_diff_min", angle_diff_min
    print "angle_diff_max", angle_diff_max
Exemplo n.º 6
0
#        return self.FAILED,0
    def get_identifier(self):
        return "QR %s"%self.ident
        
    identifier = property(get_identifier, None, "QR identifier")
        
        
if __name__=='__main__':
    from image_providers import CamImageProvider,MovieImageProvider
    ip=CamImageProvider(0,"test_data.avi")
    #ip=MovieImageProvider("test_data.avi",start_from=80)
    db.DEBUG=True
    #size=(200,200)
    img=ip.next()
    #image=cv.CreateImage(size, 8, 3)
    sd=SquareDetector(image)
    qr=QRMarker("QR")
    sd.add_marker(qr)
    while cv.WaitKey(1)!=27:
        image,img_time=ip.getImage()
        if image is None:
            break
    #    cv.SetImageROI(img, (0,0,200,200))
    #    cv.Copy(img,image)
    #    cv.ResetImageROI(img)
        sd.find_markers(image,img_time)
        sd.draw_markers(image)
    #    gray = cv.CreateImage((640,480), 8, 1)
    #    bw=cv.CloneImage(gray)
    #    cv.CvtColor(img, gray, cv.CV_BGR2GRAY)
    #    cv.Threshold(gray, bw, 128, 255, cv.CV_THRESH_OTSU)