示例#1
0
def visualize_consumer(to):
    """A consumer that visualizes the data on an image

    :param TrackerOut to: A TrackerOut objects that receives data
    """
    img = Image((600, 600))
    while True:
        to.flush()
        img.clearLayers()
        for pos, timestamp in to:
            for finger in pos:
                if finger is not None:
                    img.dl().rectangle2pts((finger[0]-4, finger[1]-4),
                                           (finger[0]+4, finger[1]+4),
                                           color=Color.RED,
                                           filled=True)
            print "{}: {}".format(int(timestamp), pos)
            img.show()
        to.clear()
    del img
示例#2
0
class Window:
    world_size = 100
    img_size = (world_size, world_size)
    generation = 0

    def __init__(self):
        self.display = Display(self.img_size)
        self.img = Image(self.img_size)
        self.img.save(self.display)

    def dot(self, x, y, size=0, color=Color.WHITE):
        x = int(round(x))
        y = int(round(y))
        #print "Drawing robot particle at {}, {}".format(x, y)
        self.img.dl().circle((x, y), size, color, filled=True)

    def dot_red(self, x, y):
        self.dot(x, y, 2, Color.RED)

    def dots(self, coords, size=0, color=Color.WHITE):
        for (x, y) in coords:
            self.dot(x, y, size, color)

    def clear(self):
        self.img = Image(self.img_size)
        #self.display.clear()
        self.img.save(self.display)

    def show(self):
        self.img.save(self.display)
        self.generation += 1
        print "Generation = {}".format(self.generation)
        self.wait_for_mouse()

    def wait_for_mouse(self):
        while True:
            for event in pg.event.get():
                if event.type == pg.MOUSEBUTTONDOWN:
                    print event
                    self.clear()
                    return
示例#3
0
from SimpleCV import Display, Image, Color

winsize = (640, 480)
display = Display(winsize)

img = Image(winsize)
img.save(display)

while not display.isDone():
    if display.mouseLeft:
	img.dl().circle((display.mouseX, display.mouseY), 5,
	    Color.RED, filled=True)
	img.save(display)
	img.save("art.png")

# -*- coding: utf-8 -*-

from SimpleCV import Display, Image, Color

winsize = (640, 480)
display = Display(winsize)
img = Image(winsize)
img.save(display)

while not display.isDone():
    if display.mouseLeft:
        img.dl().circle((display.mouseX, display.mouseY),
                        4,
                        Color.WHITE,
                        filled=True)
        img.save(display)
        img.save("ex7.png")
# -*- coding: utf-8 -*-

from SimpleCV import Display, Image, Color

winsize = (640,480)
display = Display(winsize)
img = Image(winsize)
img.save(display)

while not display.isDone():
    if display.mouseLeft:
        img.dl().circle((display.mouseX, display.mouseY), 4,
        Color.WHITE, filled=True)
        img.save(display)
        img.save("ex7.png")
示例#6
0
__author__ = "becks"

import time
from SimpleCV import Camera, Image, Color, Display

img = Image((300, 300))

img.dl().circle((150, 75), 50, Color.RED, filled=True)

img.dl().line((150, 125), (150, 275), Color.WHITE, width=5)

img.show()

time.sleep(5)

cam = Camera()

size = cam.getImage().size()

disp = Display(size)

center = (size[0] / 2, size[1] / 2)

while disp.isNotDone():
    img = cam.getImage()

    img.dl().circle(center, 50, Color.BLACK, width=3)

    img.dl().circle(center, 200, Color.BLACK, width=6)

    img.dl().line((center[0], center[1] - 50), (center[0], 0), Color.BLACK, width=2)
示例#7
0
    def __call__(self, image):
        params = util.utf8convert(self.inspection.parameters)
        retVal = []
        mask = Image((image.width,image.height))
        if( params.has_key('w') and  params.has_key('h') and params.has_key('x') and params.has_key('y') ): #rectangle
            if( params['x'] + params['w'] < image.width and
                params['y'] + params['h'] < image.height and
                params['y'] >= 0 and 
                params['x'] >= 0 ):
                mask.drawRectangle(params['x'],params['y'],params['w'],params['h'],width=-1,color=Color.WHITE)
                mask = mask.applyLayers()
                fs = image.findBlobsFromMask(mask)
                ff = M.FrameFeature()
                if( fs is not None and len(fs) > 0 ):                    
                    #fs[-1].draw()
                    b = fs[-1]
                    b.__class__ = BlobRegion                   
                    c = b.meanColor()
                    b.mColor = (int(c[0]),int(c[1]),int(c[2]))
                    ff.setFeature(b) # a little hacky but I am sure that it works
                    retVal = [ff]
  
        elif( params.has_key('x') and  params.has_key('y') and params.has_key('r') ): # circle
            if( params['x'] + params['r'] < image.width and
                params['y'] + params['r'] < image.height and 
                params['x'] - params['r'] >= 0 and 
                params['y'] - params['r'] >= 0 ):

                r = params['r']
                x = params['x']
                y = params['y']

                mask.drawCircle((x,y),r,thickness=-1,color=Color.WHITE)
                mask = mask.applyLayers()
                fs = image.findBlobsFromMask(mask)
                ff = M.FrameFeature()
                if( fs is not None and len(fs) > 0 ):                    
                    #fs[-1].draw()
                    b = fs[-1]
                    b.__class__ = BlobRegion                  
                    c = b.meanColor()
                    b.mColor = (int(c[0]),int(c[1]),int(c[2]))
                    ff.setFeature(b)
                    retVal = [ff]

        elif( params.has_key('contour') ):
            contour = params['contour'] # this may bail out
            if( len(contour) >=  3 ):
                mask.dl().polygon(contour,filled=True,color=Color.WHITE)
                mask = mask.applyLayers()
                fs = image.findBlobsFromMask(mask)
                ff = M.FrameFeature()
                if( fs is not None and len(fs) > 0 ):                    
                    #fs[-1].draw()
                    b = fs[-1]
                    b.__class__ = BlobRegion                   
                    c = b.meanColor()
                    b.mColor = (int(c[0]),int(c[1]),int(c[2])) 
                    ff.setFeature(b)
                    retVal = [ff]
            
        if( params.has_key("saveFile") ):
            image.save(params["saveFile"])

        return retVal
示例#8
0
from SimpleCV import Display, Image, Color

winsize = (640, 480)
display = Display(winsize)

img = Image(winsize)
img.save(display)

while not display.isDone():
    if display.mouseLeft:
        img.dl().circle((display.mouseX, display.mouseY),
                        5,
                        Color.RED,
                        filled=True)
        img.save(display)
        img.save("art.png")
示例#9
0
class Window2:
    generation = 0

    def __init__(self, filename, scale=1):
        filename = os.path.expanduser(filename)
        self.img = Image(filename)
        self.max_x, self.max_y = self.img.width, self.img.height
        self.scale = scale

        self.array_map = np.array([[0 for y in range(self.max_y)] for x in range(self.max_x)])
        for x in range(self.max_x):
            for y in range(self.max_y):
                pixel = self.img.getPixel(x, y)
                self.array_map[x][y] = (pixel == (255, 255, 255))

        # scale image
        self.img = self.img.resize(self.img.width*scale, self.img.height*scale)
        self.img_size = self.img.width, self.img.height

        self.display = Display(self.img_size)
        self.img.save(self.display)

    def dot(self, p, color=Color.WHITE, size=0):
        x, y = p[0], p[1]
        #print "Drawing robot particle at {}, {}".format(x, y)
        if x < 0 or x >= self.max_x:
            print "Oh my god! x=", x
            raise RuntimeError
        if y < 0 or y >= self.max_y:
            print "Oh shit! y=", y
            raise RuntimeError
        else:
            self.img.dl().circle(center=(x*self.scale, y*self.scale), radius=size, color=color, width=1, filled=True)

    def dot_red(self, p, color=Color.RED):
        self.dot(p, color, 2)

    def dots(self, coords, color=Color.WHITE, size=0):
        for (x, y) in coords:
            self.dot((x, y), color, size)

    def clear(self):
        self.img = Image(self.img_size)
        #self.display.clear()
        self.img.save(self.display)

    def clear_dl(self):
        self.img.clearLayers()
        self.img.save(self.display)

    def show(self):
        self.img.save(self.display)
        self.generation += 1
        print "Generation = {}".format(self.generation)
        self.wait_for_mouse()
        print "Mouse pressed!"

    def draw_robot(self, position, orientation):
        color = Color.RED
        #self.img.drawRectangle(p[0], p[1], 20, 40, color, 1)
        self.dot(position, color, 2)

        length = 20
        bx = int(round(position[0] + cos(orientation) * length))
        by = int(round(position[1] + sin(orientation) * length))

        self.vector(position, orientation, length, detect_collision=False, color=color)
        self.vector((bx, by), orientation - 3*pi/4, length=8, detect_collision=False, color=color)
        self.vector((bx, by), orientation + 3*pi/4, length=8, detect_collision=False, color=color)

    def vector(self, x, orientation, length, detect_collision=True, color=Color.FORESTGREEN):
        bx = int(round(x[0] + cos(orientation) * length))
        by = int(round(x[1] + sin(orientation) * length))
        #self.dot_red((bx, by))
        return self.line(x, (bx, by), detect_collision=detect_collision, color=color)
        #return bx, by

    # a = startpunkt, b = endpunkt
    #@profile
    def line(self, a, b, detect_collision=True, color=Color.BLUE):
        """http://en.wikipedia.org/wiki/Bresenham's_line_algorithm"""

        # performance => use local vars
        max_x = self.max_x
        max_y = self.max_y
        array_map = self.array_map

        x0, y0 = a
        x1, y1 = b
        dx = abs(x1-x0)
        dy = -abs(y1-y0)
        if x0 < x1:
            sx = 1
        else:
            sx = -1

        if y0 < y1:
            sy = 1
        else:
            sy = -1
        err = dx+dy

        while True:
            if x0 <= 0 or x0 >= max_x or y0 <= 0 or y0 >= max_y:
                break
            if color:
                self.dot((x0, y0), color, 0)
            #if detect_collision and self.img.getPixel(x0, y0) == (255, 255, 255):
            if detect_collision and array_map[x0][y0]:
                break
            if x0 == x1 and y0 == y1:
                break
            e2 = 2*err

            if e2 > dy:
                err += dy
                x0 += sx

            if x0 == x1 and y0 == y1:
                #if color:
                #    self.dot((x0, y0), color, 0)
                break

            if e2 < dx:
                err = err + dx
                y0 += sy
        return x0, y0

    def wait_for_mouse(self):
        while True:
            for event in pg.event.get():
                if event.type == pg.MOUSEBUTTONDOWN:
                    print event
                    #self.clear()
                    return
示例#10
0
__author__ = 'becks'

import time
from SimpleCV import Camera, Image, Color, Display

img = Image((300, 300))

img.dl().circle((150, 75), 50, Color.RED, filled = True)

img.dl().line((150, 125), (150, 275), Color.WHITE, width = 5)

img.show()

time.sleep(5)

cam = Camera()

size = cam.getImage().size()

disp = Display(size)

center = (size[0] / 2, size[1] / 2)

while disp.isNotDone():
    img = cam.getImage()

    img.dl().circle(center, 50, Color.BLACK, width = 3)

    img.dl().circle(center, 200, Color.BLACK, width = 6)

    img.dl().line((center[0], center[1] - 50), (center[0], 0), Color.BLACK, width = 2)
示例#11
0
__author__ = 'becks'
import time
from SimpleCV import Image

head = Image('head.png')

amgothic = Image('amgothic.png')

scream = Image('scream.png')

amgothic.dl().blit(head, (175, 110))

amgothic.show()

time.sleep(2)

layer = amgothic.getDrawingLayer()

scream.addDrawingLayer(layer)

scream.show()
time.sleep(2)

print amgothic._mLayers
print scream._mLayers

layer.blit(head, (75, 220))

amgothic.show()
time.sleep(2)
scream.show()
    (pt1, pt2) = line1.end_points  #pega os pontos finais da linha

    if line1.angle() > 18 and line1.angle(
    ) < 28:  #varre linhas entre com angulo de 18 a 28(angulos para linhas da estrada à esquerda)
        imgBy.dl().line(pt1, pt2, Color.BLUE, width=3)  #desenha linha
        m = math.tan(math.radians(line1.angle(
        )))  #calcula coeficinte angular da reta, através do angulo da mesma
        x2_temp = calculaX(m, Y, pt1)  #calcula x na reta
        if x2 > x2_temp:  #verifica se é o maior x à esquerda
            x2 = x2_temp  #salva o maior x

    if line1.angle() > -28 and line1.angle(
    ) < -18:  #varre linhas entre com angulo de 18 a 28(angulos para linhas da estrada à direita)
        imgBy.dl().line(pt1, pt2, Color.BLUE, width=3)  #desenha linha
        m = math.tan(math.radians(line1.angle(
        )))  #calcula coeficinte angular da reta, através do angulo da mesma
        x1_temp = calculaX(m, Y, pt1)  #calcula x na reta
        if x1 < x1_temp:  #verifica se é o maior x à direita
            x1 = x1_temp  #salva o maior x

#desenha linha entre os pontos da estrada
img.dl().line((x1, Y), (x2, Y), Color.RED, width=3)
distancia = x2 - x1  #calcula distância
print "DISTANCIA: ", distancia  #imprime no console
text = "DISTANCIA: " + str(
    math.ceil(distancia))  #formata string par imprimir na imagem
img.drawText(text, 120, 220, color=(0, 0, 255), fontsize=32)
#imprime valor na imagem
img.show()  #Exibe imagem
示例#13
0
__author__ = 'becks'
import time
from SimpleCV import Image

head = Image('head.png')

amgothic = Image('amgothic.png')

scream = Image('scream.png')

amgothic.dl().blit(head,(175, 110))

amgothic.show()

time.sleep(2)

layer = amgothic.getDrawingLayer()

scream.addDrawingLayer(layer)

scream.show()
time.sleep(2)

print amgothic._mLayers
print scream._mLayers

layer.blit(head,(75,220))

amgothic.show()
time.sleep(2)
scream.show()
from SimpleCV import Display, Image, Color

winsize = (640,480)
display = Display(winsize)

img = Image(winsize)
img.save(display)

while not display.isDone():
    if display.mouseLeft:
        img.dl().circle((display.mouseX, display.mouseY), 4, Color.YELLOW, filled=True)
        img.save(display)
        img.save("painting.png")
exit()