Exemplo n.º 1
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.º 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 == 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():
    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.º 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