示例#1
0
class Fish():
    def __init__(self, image_url, mask_url):
        self.position = (10, 10)
        self.last_position = (0, 0)
        self.draw_position = (0, 0)
        self.direction = "left"
        self.orig_image = Image(image_url)
        self.orig_mask = Image(mask_url).invert()
        self.draw_image = self.orig_image.copy()
        self.draw_mask = self.orig_mask.copy()

    def update(self, x, y, w, h):
        self.update_dir()

        self.position = (x, y)

        self.draw_image = self.orig_image.resize(w=w, h=h)
        self.draw_mask = self.orig_mask.resize(w=w, h=h)
 
        if self.direction == "left":
            self.draw_position = self.position
        
        elif self.direction == "right":
            # TODO: setup offsets here for image when facing another direction
            self.draw_position = (self.position[0] + 0, self.position[1] + 0)
            pass

    def update_dir(self):
        hor_change = self.position[0] - self.last_position[0]
        # if the difference is more than 10 pixels
        if abs(hor_change) > 5:
            # TODO: can optimise this slightly by checking if == left && horchange is positive
            # (so doesnt flip it every time over 10 pixels in the same direction)
            if self.direction == "left":
                self.direction = "right"
                self.draw_image = self.orig_image.flipHorizontal().copy()
                self.draw_mask = self.orig_mask.flipHorizontal().copy()
            elif self.direction == "right":
                self.direction = "left"
                self.draw_image = self.orig_image.copy()
                self.draw_mask = self.orig_mask.copy()
            self.last_position = self.position

    def draw(self, parent):
        #self.draw_image.save(canvas)
        print self.draw_image
        print self.draw_position
        parent.canvas = parent.canvas.blit(self.draw_image, pos=self.draw_position, alphaMask=self.draw_mask)
示例#2
0
from SimpleCV import Image
import time
img = Image('ladies.jpg')
# Flip the image along the horizontal axis, and then display the results
flip = img.flipHorizontal()
flip.show()
time.sleep(10)