Example #1
0
class Test_Shapes(unittest.TestCase):
    """docstring for Test_Roadgen"""

    #Setup the test instance of the class
    def setUp(self):
        self.test0 = Shapes()

    def tearDown(self):
        pass

    def test_unit_vector(self):
        npt.assert_almost_equal(self.test0.unit_vector([345.345, 0]),
                                np.array([1., 0.]),
                                decimal=7)
        npt.assert_almost_equal(self.test0.unit_vector([0, 345.345]),
                                np.array([0., 1.]),
                                decimal=7)
        npt.assert_almost_equal(self.test0.unit_vector([-345.345, 0]),
                                np.array([-1., 0.]),
                                decimal=7)
        npt.assert_almost_equal(self.test0.unit_vector([0, -345.345]),
                                np.array([0., -1.]),
                                decimal=7)
        npt.assert_almost_equal(self.test0.unit_vector([-3, -4]),
                                np.array([-.6, -.8]),
                                decimal=7)
Example #2
0
    def draw_pair(coords, cols):
        # Draw under-layer
        (q, r, k) = coords
        (c1, c2) = cols
        Board.draw_empty_tile(q, r, k)

        # Draw coloured shapes
        primary_points = Shapes.plot_primary(Board.board_size, Board.size, q, r, c1)
        Board.draw_shape(c1, primary_points)
        (nq, nr) = Hex.hex_neighbor((q, r), k)
        secondary_points = Shapes.plot_primary(Board.board_size, Board.size, nq, nr, c2)
        Board.draw_shape(c2, secondary_points)
Example #3
0
    def __init__(self):
        gtk.Window.__init__(self, title='Chem')

        #adding a box
        box = gtk.Box()
        self.add(box)

        #packing drawing area to the box
        darea = Shapes()
        box.pack_start(darea, True, True, 0)

        #packing grid to the box
        grid = gtk.Grid()
        box.pack_end(grid, True, True, 0)

        #attaching buttons to grid
        buttons = Buttons()

        buttons._attach_carbon_buttons(grid)
        buttons._attach_connections_buttons(grid)
        buttons._attach_organic_functions_buttons(grid)
        buttons._attach_search_button(grid)

        #adding event
        buttons._connect_search_button()
        buttons._connect_connections_buttons(darea.draw)
Example #4
0
def directConnect(factor):
    for ctl, chan, drv, tgt, alias, val in iterConns("MEm.shapes.connsFlower"):
        oCtl = pym.PyNode(ctl)
        oShape = Shapes(tgt)
        tgtAttr = oShape[alias]
        factorName = ctl + "_factorNode"
        factorNode = [
            node for node in oCtl.translateX.listConnections()
            if node.name() == factorName
        ]
        print "s:", factorNode
        if not factorNode:
            try:
                factorNode = pym.PyNode(factorName)
            except pym.MayaNodeError:
                factorNode = pym.createNode("multiplyDivide", n=factorName)
                factorNode = pym.PyNode(factorNode)
            print "c:", factorNode
            oCtl.translateX.connect(factorNode.input1X)
        else:
            factorNode = factorNode[0]

        print "o:", factorNode
        factorNode.input2X.set(factor)

        tgtNode = [
            attr for attr in factorNode.outputX.listConnections(p=True)
            if attr == tgtAttr
        ]
        print "factor2Tgt", tgtNode
        if not tgtNode:
            factorNode.outputX.connect(tgtAttr)
Example #5
0
 def draw_shape(shape_color, ppts):
     color1 = Shapes.get_sprite_color(shape_color)
     if shape_color in [0, 2, 4]:
         pg.draw.polygon(Board.screen, color1, ppts)
     elif shape_color == 1:
         Board.draw_hexagon(*ppts, color1)
     elif shape_color == 3:
         pg.draw.circle(Board.screen, color1, *ppts)
     elif shape_color == 5:
         pg.draw.circle(Board.screen, color1, *ppts)
Example #6
0
    def road_generator(self,
                       y_train,
                       line_width,
                       rand_gen=1,
                       seg_noise=0,
                       poly_noise=0):
        road_frame = np.ones(
            (self.view_res[1], self.view_res[0], self.n_channels),
            dtype=np.uint8)

        #set max intensity:
        max_intensity = 256

        if rand_gen:
            #Initialize a single tone background:
            if np.random.rand() < 0.5:
                road_frame[:, :, 0] *= rng.randint(0, .7 * max_intensity)
                road_frame[:, :, 1] *= rng.randint(0, .7 * max_intensity)
                road_frame[:, :, 2] *= rng.randint(0, .7 * max_intensity)
            else:
                road_frame[:, :, :] *= rng.randint(0, .7 * max_intensity)

        if seg_noise:
            #line width randomizer:
            line_width += rand_gen * max(line_width / 3 * np.random.randn(),
                                         -line_width * 3 / 4)

        while poly_noise:
            rr, cc = Shapes.poly_noise(self.view_res, [
                np.random.randint(0, self.gen_res[0]),
                np.random.randint(0, self.gen_res[1])
            ])
            road_frame[rr, cc, :] = (road_frame[rr, cc, :] + rng.randint(
                0, .5 * max_intensity, self.n_channels)) / 2
            poly_noise -= 1

        rr, cc = self.poly_line(self.view_res, y_train[0], line_width,
                                seg_noise)
        road_frame[rr, cc, :] = rng.randint(.8 * max_intensity, max_intensity,
                                            self.n_channels)

        rr, cc = self.dashed_line(self.view_res, y_train[1],
                                  self.view_res[1] / 4, line_width * 2)
        road_frame[rr, cc, 1:] = rng.randint(.7 * max_intensity, max_intensity)
        road_frame[rr, cc, 0] = rng.randint(0, .3 * max_intensity)

        rr, cc = self.poly_line(self.view_res, y_train[2], line_width,
                                seg_noise)
        road_frame[rr, cc, :] = rng.randint(.8 * max_intensity, max_intensity,
                                            self.n_channels)

        return road_frame
Example #7
0
    def middle_points(self, y_train, y_noise, orientation=1):
        #Assign the central control point:
        y_train[1, 0,
                1] = np.random.randint(0, self.view_res[0]) + self.cropsize[0]
        y_train[1, 1,
                1] = np.random.randint(0, self.view_res[1]) + self.cropsize[1]
        '''Calculate the control point axis:
        control point axis is defined by a unit vector parallel to a line
        originating at the midpoint of the line's start and end and 
        terminating at the curves second control point'''
        u_delta = Shapes.unit_vector(y_train[1, :, 1] - (
            y_train[1, :, 0] + (y_train[1, :, 2] - y_train[1, :, 0]) / 2))

        #print(u_delta)
        #scales the sideways road outputs to account for pitch
        vertical_excursion = np.absolute(u_delta[1]) * self.max_road_width

        #rotational correction:
        u_rot = Shapes.rot_by_vector(y_train[1, :, 2] - y_train[1, :, 0],
                                     u_delta)
        #Checks to see which side of the line between start and end the midpoint falls on
        if u_rot[1] > 0:
            #If u_delta has a negative y component then it falls south of the line and need to be inverted
            u_delta *= -1

        #Set the left side no.1 control point
        y_train[0, :, 1] = (y_train[1, :, 1] + u_delta * np.multiply(
            (self.max_road_width - y_noise[0, 1]),
            (1 - self.lane_convergence + self.lane_convergence * np.maximum(
                .2,
                (y_train[1, 1, 1] + vertical_excursion)) / self.gen_res[1])))
        #Set the right side no.1 control point
        y_train[2, :, 1] = (y_train[1, :, 1] - u_delta * np.multiply(
            (self.max_road_width - y_noise[1, 1]),
            (1 - self.lane_convergence + self.lane_convergence * np.maximum(
                .2,
                (y_train[1, 1, 1] - vertical_excursion)) / self.gen_res[1])))

        return y_train
Example #8
0
    def train_dataloader(self):
        transform = self.data_transforms()

        if self.params['dataset'] == 'celeba':
            dataset = CelebA(root=self.params['data_path'],
                             split="train",
                             transform=transform,
                             download=False)
        elif self.params['dataset'] == 'shapes':
            dataset = Shapes(root=self.params['data_path'],
                             split="train",
                             transform=transform)
        else:
            raise ValueError('Undefined dataset type')

        self.num_train_imgs = len(dataset)
        return DataLoader(dataset,
                          batch_size=self.params['batch_size'],
                          shuffle=True,
                          drop_last=True)
Example #9
0
    def val_dataloader(self):
        transform = self.data_transforms()

        if self.params['dataset'] == 'celeba':
            self.sample_dataloader = DataLoader(CelebA(root=self.params['data_path'],
                                                       split="test",
                                                       transform=transform,
                                                       download=False),
                                                batch_size=144,
                                                shuffle=True,
                                                drop_last=True)
            self.num_val_imgs = len(self.sample_dataloader)
        elif self.params['dataset'] == 'shapes':
            self.sample_dataloader = DataLoader(Shapes(root=self.params['data_path'],
                                                       split="test",
                                                       transform=transform),
                                                batch_size=144,
                                                shuffle=True,
                                                drop_last=True)
            self.num_val_imgs = len(self.sample_dataloader)
        else:
            raise ValueError('Undefined dataset type')

        return self.sample_dataloader
Example #10
0
import cv2

from drawwindow import DrawWindow
from shapes import Shapes, PolyLine, PolyPoints, PixelRegion, RectangleShape, EllipseShape
import random
#
#debug=0
##cv2.RNG random(12345)
#
#
## add some lines
w=400
h=500
##PolyLine *PL
S = Shapes()

for i in range(5):
    PL = PolyLine()
    PL.setPenColor(random.randint(50,250),random.randint(50,250),random.randint(50,250))
    for i in range(10):
        PL.addPoint((random.randint(100,w-100),random.randint(100,h-100)))
    S.addShape(PL)
    

# add a poly poregion
PP = PolyPoints()

ww=100
delx=20
dely=200
Example #11
0
 def setUp(self):
     self.test0 = Shapes()
Example #12
0
    def __init__(self, config_provider):

        text_to_speech = None
        if (
            config_provider.acting
            or config_provider.audio_classifier
            or config_provider.browser
            or config_provider.calculator
            or config_provider.fruit_machine
            or config_provider.hand_gesture
            or config_provider.happy_colour
            or config_provider.iris_classifier
            or config_provider.mixing_desk
            or config_provider.optical_character_recognition
            or config_provider.play_your_cards_right
            or config_provider.shapes
            or config_provider.slideshow
            or config_provider.weather
        ):
            from texttospeech import TextToSpeech

            text_to_speech = TextToSpeech()

        speech_to_text = None
        if (
            config_provider.acting
            or config_provider.browser
            or config_provider.calculator
            or config_provider.fruit_machine
            or config_provider.iris_classifier
            or config_provider.mixing_desk
            or config_provider.phrase_translation
            or config_provider.play_your_cards_right
            or config_provider.weather
        ):
            from speechtotext import SpeechToText

            speech_to_text = SpeechToText()

        self.acting = None
        if config_provider.acting:
            from acting import Acting

            self.acting = Acting(text_to_speech, speech_to_text)

        self.audio_classifier = None
        if config_provider.audio_classifier:
            from audioclassifier import AudioClassifier

            self.audio_classifier = AudioClassifier(text_to_speech)

        self.browser = None
        if config_provider.browser:
            from browser import Browser

            self.browser = Browser(text_to_speech, speech_to_text)

        self.calculator = None
        if config_provider.calculator:
            from calculator import Calculator

            self.calculator = Calculator(text_to_speech, speech_to_text)

        self.fruit_machine = None
        if config_provider.fruit_machine:
            from fruitmachine import FruitMachine

            self.fruit_machine = FruitMachine(text_to_speech, speech_to_text)

        self.hand_gesture = None
        if config_provider.hand_gesture:
            from handgesture import HandGesture

            self.hand_gesture = HandGesture(text_to_speech)

        self.happy_colour = None
        if config_provider.happy_colour:
            from happycolour import HappyColour

            self.happy_colour = HappyColour(text_to_speech)

        self.iris_classifier = None
        if config_provider.iris_classifier:
            from irisclassifier import IrisClassifier

            self.iris_classifier = IrisClassifier(text_to_speech, speech_to_text)

        self.mixing_desk = None
        if config_provider.mixing_desk:
            from mixingdesk import MixingDesk

            self.mixing_desk = MixingDesk(text_to_speech, speech_to_text)

        self.optical_character_recognition = None
        if config_provider.optical_character_recognition:
            from opticalcharacterrecognition import OpticalCharacterRecognition

            self.optical_character_recognition = OpticalCharacterRecognition(text_to_speech)

        self.phrase_translation = None
        if config_provider.phrase_translation:
            from phrasetranslation import PhraseTranslation

            self.phrase_translation = PhraseTranslation(speech_to_text)

        self.play_your_cards_right = None
        if config_provider.play_your_cards_right:
            from playyourcardsright import PlayYourCardsRight

            self.play_your_cards_right = PlayYourCardsRight(text_to_speech, speech_to_text)

        self.shapes = None
        if config_provider.shapes:
            from shapes import Shapes

            self.shapes = Shapes(text_to_speech)

        self.slideshow = None
        if config_provider.slideshow:
            from slideshow import Slideshow

            self.slideshow = Slideshow(text_to_speech)

        self.television = None
        if config_provider.television:
            from television import Television

            self.television = Television()

        self.weather = None
        if config_provider.weather:
            from weather import Weather

            self.weather = Weather(text_to_speech, speech_to_text)
Example #13
0
	def __init__(self, position, radius, color, rotation):
		self.radius = radius
		Shapes.__init__(self, position, rotation, color)
    def __init__(self, config_provider):

        text_to_speech = None
        if (config_provider.acting or config_provider.audio_classifier
                or config_provider.browser or config_provider.calculator
                or config_provider.fruit_machine
                or config_provider.hand_gesture or config_provider.happy_colour
                or config_provider.iris_classifier
                or config_provider.mixing_desk
                or config_provider.optical_character_recognition
                or config_provider.play_your_cards_right
                or config_provider.shapes or config_provider.slideshow
                or config_provider.weather):
            from texttospeech import TextToSpeech
            text_to_speech = TextToSpeech()

        speech_to_text = None
        if (config_provider.acting or config_provider.browser
                or config_provider.calculator or config_provider.fruit_machine
                or config_provider.iris_classifier
                or config_provider.mixing_desk
                or config_provider.phrase_translation
                or config_provider.play_your_cards_right
                or config_provider.weather):
            from speechtotext import SpeechToText
            speech_to_text = SpeechToText()

        self.acting = None
        if config_provider.acting:
            from acting import Acting
            self.acting = Acting(text_to_speech, speech_to_text)

        self.audio_classifier = None
        if config_provider.audio_classifier:
            from audioclassifier import AudioClassifier
            self.audio_classifier = AudioClassifier(text_to_speech)

        self.browser = None
        if config_provider.browser:
            from browser import Browser
            self.browser = Browser(text_to_speech, speech_to_text)

        self.calculator = None
        if config_provider.calculator:
            from calculator import Calculator
            self.calculator = Calculator(text_to_speech, speech_to_text)

        self.fruit_machine = None
        if config_provider.fruit_machine:
            from fruitmachine import FruitMachine
            self.fruit_machine = FruitMachine(text_to_speech, speech_to_text)

        self.hand_gesture = None
        if config_provider.hand_gesture:
            from handgesture import HandGesture
            self.hand_gesture = HandGesture(text_to_speech)

        self.happy_colour = None
        if config_provider.happy_colour:
            from happycolour import HappyColour
            self.happy_colour = HappyColour(text_to_speech)

        self.iris_classifier = None
        if config_provider.iris_classifier:
            from irisclassifier import IrisClassifier
            self.iris_classifier = IrisClassifier(text_to_speech,
                                                  speech_to_text)

        self.mixing_desk = None
        if config_provider.mixing_desk:
            from mixingdesk import MixingDesk
            self.mixing_desk = MixingDesk(text_to_speech, speech_to_text)

        self.optical_character_recognition = None
        if config_provider.optical_character_recognition:
            from opticalcharacterrecognition import OpticalCharacterRecognition
            self.optical_character_recognition = OpticalCharacterRecognition(
                text_to_speech)

        self.phrase_translation = None
        if config_provider.phrase_translation:
            from phrasetranslation import PhraseTranslation
            self.phrase_translation = PhraseTranslation(speech_to_text)

        self.play_your_cards_right = None
        if config_provider.play_your_cards_right:
            from playyourcardsright import PlayYourCardsRight
            self.play_your_cards_right = PlayYourCardsRight(
                text_to_speech, speech_to_text)

        self.shapes = None
        if config_provider.shapes:
            from shapes import Shapes
            self.shapes = Shapes(text_to_speech)

        self.slideshow = None
        if config_provider.slideshow:
            from slideshow import Slideshow
            self.slideshow = Slideshow(text_to_speech)

        self.television = None
        if config_provider.television:
            from television import Television
            self.television = Television()

        self.weather = None
        if config_provider.weather:
            from weather import Weather
            self.weather = Weather(text_to_speech, speech_to_text)
class Features:

    # initialise features
    def __init__(self, config_provider):

        text_to_speech = None
        if (config_provider.acting or config_provider.audio_classifier
                or config_provider.browser or config_provider.calculator
                or config_provider.fruit_machine
                or config_provider.hand_gesture or config_provider.happy_colour
                or config_provider.iris_classifier
                or config_provider.mixing_desk
                or config_provider.optical_character_recognition
                or config_provider.play_your_cards_right
                or config_provider.shapes or config_provider.slideshow
                or config_provider.weather):
            from texttospeech import TextToSpeech
            text_to_speech = TextToSpeech()

        speech_to_text = None
        if (config_provider.acting or config_provider.browser
                or config_provider.calculator or config_provider.fruit_machine
                or config_provider.iris_classifier
                or config_provider.mixing_desk
                or config_provider.phrase_translation
                or config_provider.play_your_cards_right
                or config_provider.weather):
            from speechtotext import SpeechToText
            speech_to_text = SpeechToText()

        self.acting = None
        if config_provider.acting:
            from acting import Acting
            self.acting = Acting(text_to_speech, speech_to_text)

        self.audio_classifier = None
        if config_provider.audio_classifier:
            from audioclassifier import AudioClassifier
            self.audio_classifier = AudioClassifier(text_to_speech)

        self.browser = None
        if config_provider.browser:
            from browser import Browser
            self.browser = Browser(text_to_speech, speech_to_text)

        self.calculator = None
        if config_provider.calculator:
            from calculator import Calculator
            self.calculator = Calculator(text_to_speech, speech_to_text)

        self.fruit_machine = None
        if config_provider.fruit_machine:
            from fruitmachine import FruitMachine
            self.fruit_machine = FruitMachine(text_to_speech, speech_to_text)

        self.hand_gesture = None
        if config_provider.hand_gesture:
            from handgesture import HandGesture
            self.hand_gesture = HandGesture(text_to_speech)

        self.happy_colour = None
        if config_provider.happy_colour:
            from happycolour import HappyColour
            self.happy_colour = HappyColour(text_to_speech)

        self.iris_classifier = None
        if config_provider.iris_classifier:
            from irisclassifier import IrisClassifier
            self.iris_classifier = IrisClassifier(text_to_speech,
                                                  speech_to_text)

        self.mixing_desk = None
        if config_provider.mixing_desk:
            from mixingdesk import MixingDesk
            self.mixing_desk = MixingDesk(text_to_speech, speech_to_text)

        self.optical_character_recognition = None
        if config_provider.optical_character_recognition:
            from opticalcharacterrecognition import OpticalCharacterRecognition
            self.optical_character_recognition = OpticalCharacterRecognition(
                text_to_speech)

        self.phrase_translation = None
        if config_provider.phrase_translation:
            from phrasetranslation import PhraseTranslation
            self.phrase_translation = PhraseTranslation(speech_to_text)

        self.play_your_cards_right = None
        if config_provider.play_your_cards_right:
            from playyourcardsright import PlayYourCardsRight
            self.play_your_cards_right = PlayYourCardsRight(
                text_to_speech, speech_to_text)

        self.shapes = None
        if config_provider.shapes:
            from shapes import Shapes
            self.shapes = Shapes(text_to_speech)

        self.slideshow = None
        if config_provider.slideshow:
            from slideshow import Slideshow
            self.slideshow = Slideshow(text_to_speech)

        self.television = None
        if config_provider.television:
            from television import Television
            self.television = Television()

        self.weather = None
        if config_provider.weather:
            from weather import Weather
            self.weather = Weather(text_to_speech, speech_to_text)

    # indicate whether a feature is speaking
    def is_speaking(self):
        return ((self.acting and self.acting.is_speaking) or
                (self.audio_classifier and self.audio_classifier.is_speaking)
                or (self.browser and self.browser.is_speaking)
                or (self.calculator and self.calculator.is_speaking)
                or (self.fruit_machine and self.fruit_machine.is_speaking)
                or (self.hand_gesture and self.hand_gesture.is_speaking)
                or (self.happy_colour and self.happy_colour.is_speaking)
                or (self.iris_classifier and self.iris_classifier.is_speaking)
                or (self.mixing_desk and self.mixing_desk.is_speaking)
                or (self.optical_character_recognition
                    and self.optical_character_recognition.is_speaking)
                or (self.phrase_translation
                    and self.phrase_translation.is_speaking)
                or (self.play_your_cards_right
                    and self.play_your_cards_right.is_speaking)
                or (self.shapes and self.shapes.is_speaking)
                or (self.slideshow and self.slideshow.is_speaking)
                or (self.weather and self.weather.is_speaking))

    # provide emotion from a feature
    def get_emotion(self):
        if self.acting:
            return self.acting.emotion
        if self.fruit_machine:
            return self.fruit_machine.emotion
        if self.hand_gesture:
            return self.hand_gesture.emotion
        if self.happy_colour:
            return self.happy_colour.emotion

        return None

    # update background image from a feature
    def update_background_image(self, image):
        if self.fruit_machine and self.fruit_machine.background_image.size > 0:
            return self.fruit_machine.background_image
        if self.iris_classifier and self.iris_classifier.background_image.size > 0:
            return self.iris_classifier.background_image
        if self.shapes and self.shapes.background_image.size > 0:
            return self.shapes.background_image
        if self.slideshow and self.slideshow.background_image.size > 0:
            return self.slideshow.background_image
        if self.television and self.television.background_image.size > 0:
            return self.television.background_image

        return image

    # handle features
    def handle(self, rocky_robot, sporty_robot, image):
        self._handle_acting(rocky_robot, sporty_robot)
        self._handle_audio_classifier(rocky_robot, sporty_robot)
        self._handle_browser(rocky_robot, sporty_robot)
        self._handle_calculator(rocky_robot, sporty_robot)
        self._handle_fruit_machine(sporty_robot, image)
        self._handle_hand_gesture(rocky_robot, sporty_robot, image)
        self._handle_happy_colour(rocky_robot, image)
        self._handle_iris_classifier(rocky_robot, sporty_robot, image)
        self._handle_mixing_desk(rocky_robot)
        self._handle_optical_character_recognition(rocky_robot, sporty_robot,
                                                   image)
        self._handle_phrase_translation(sporty_robot)
        self._handle_play_your_cards_right(sporty_robot)
        self._handle_shapes(rocky_robot, sporty_robot, image)
        self._handle_slideshow(rocky_robot, sporty_robot, image)
        self._handle_television(rocky_robot, sporty_robot, image)
        self._handle_weather(rocky_robot, sporty_robot)

    # handle acting
    def _handle_acting(self, rocky_robot, sporty_robot):
        if not self.acting: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.acting.start()
        else:
            self.acting.stop()

    # handle audio classifier
    def _handle_audio_classifier(self, rocky_robot, sporty_robot):
        if not self.audio_classifier: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.audio_classifier.start()
        else:
            self.audio_classifier.stop()

    # handle browser
    def _handle_browser(self, rocky_robot, sporty_robot):
        if not self.browser: return

        if rocky_robot.is_facing:
            self.browser.start(ROCK)
        elif sporty_robot.is_facing:
            self.browser.start(SPORT)
        else:
            self.browser.stop()

    # handle calculator
    def _handle_calculator(self, rocky_robot, sporty_robot):
        if not self.calculator: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.calculator.start()
        else:
            self.calculator.stop()

    # handle fruit machine
    def _handle_fruit_machine(self, sporty_robot, image):
        if not self.fruit_machine: return

        if sporty_robot.is_facing:
            self.fruit_machine.start(image)
        else:
            self.fruit_machine.stop()

    # handle hand gesture
    def _handle_hand_gesture(self, rocky_robot, sporty_robot, image):
        if not self.hand_gesture: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.hand_gesture.start(image)
        else:
            self.hand_gesture.stop()

    # handle happy colour
    def _handle_happy_colour(self, rocky_robot, image):
        if not self.happy_colour: return

        if rocky_robot.is_facing:
            self.happy_colour.start(image)
        else:
            self.happy_colour.stop()

    # handle iris classifier
    def _handle_iris_classifier(self, rocky_robot, sporty_robot, image):
        if not self.iris_classifier: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.iris_classifier.start(image)
        else:
            self.iris_classifier.stop()

    # handle mixing desk
    def _handle_mixing_desk(self, rocky_robot):
        if not self.mixing_desk: return

        if rocky_robot.is_facing:
            self.mixing_desk.start()
        else:
            self.mixing_desk.stop()

    # handle optical character recognition
    def _handle_optical_character_recognition(self, rocky_robot, sporty_robot,
                                              image):
        if not self.optical_character_recognition: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.optical_character_recognition.start(image)
        else:
            self.optical_character_recognition.stop()

    # handle phrase translation
    def _handle_phrase_translation(self, sporty_robot):
        if not self.phrase_translation: return

        if sporty_robot.is_facing:
            self.phrase_translation.start()
        else:
            self.phrase_translation.stop()

    # handle play your cards right
    def _handle_play_your_cards_right(self, sporty_robot):
        if not self.play_your_cards_right: return

        if sporty_robot.is_facing:
            self.play_your_cards_right.start()
        else:
            self.play_your_cards_right.stop()

    # handle shapes
    def _handle_shapes(self, rocky_robot, sporty_robot, image):
        if not self.shapes: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.shapes.start(image)
        else:
            self.shapes.stop()

    # handle slideshow
    def _handle_slideshow(self, rocky_robot, sporty_robot, image):
        if not self.slideshow: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.slideshow.start(image)
        else:
            self.slideshow.stop()

    # handle television
    def _handle_television(self, rocky_robot, sporty_robot, image):
        if not self.television: return

        if rocky_robot.is_rendered or sporty_robot.is_rendered:
            self.television.start(image)
        else:
            self.television.stop()

    # handle weather
    def _handle_weather(self, rocky_robot, sporty_robot):
        if not self.weather: return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.weather.start()
        else:
            self.weather.stop()
Example #16
0
num_samples = 1000
iou_thresh = 0.3
max_num_shapes = 3
metrics = ['mean_squared_error']
# loss = JaccardLoss()
loss = [DiceLoss(), JaccardLoss(), FocalLoss()]
H, W = image_shape = input_shape[:2]
batch_size = 5
epochs = 10
freeze = True
stop_patience = 5
reduce_patience = 2
experiment_path = 'experiments/'

data_manager = Shapes(num_samples,
                      image_shape,
                      iou_thresh=iou_thresh,
                      max_num_shapes=max_num_shapes)
num_classes = data_manager.num_classes
data = data_manager.load_data()
processor = PreprocessSegmentation(image_shape, num_classes)

# setting additional callbacks
callbacks = []
log_filename = os.path.join(experiment_path, 'optimization.log')
log = CSVLogger(log_filename)
stop = EarlyStopping('loss', patience=stop_patience)
save_filename = os.path.join(experiment_path, 'model.hdf5')
save = ModelCheckpoint(save_filename, 'loss', save_best_only=True)
plateau = ReduceLROnPlateau('loss', patience=reduce_patience)
callbacks.extend([log, stop, save, plateau])
Example #17
0
import os
import string
import pygame as pg

from shapes import Shapes
from config import config
from score import Score
from color import colors, ColorEffect

score = Score()
shape = Shapes()
next_shape = Shapes()
color_effect = ColorEffect(length=15)


class Relationship():
    def Button(self):
        pass


class Button:
    def __init__(self, key, function, draw_on):

        self.key = key

        # Положення та розміри кнопки
        self.x = config.buttons_size[self.key]['x']
        self.y = config.buttons_size[self.key]['y']
        self.w = config.buttons_size[self.key]['w']
        self.h = config.buttons_size[self.key]['h']
Example #18
0
    def build(self):
        self._get_config_vals()
        self.cols = 3
        self.rows = 5
        self.spacing = 5
        # animate noise application
        visibility = 1 - self.final_noise_level
        self.noise_animation = Animation(shape_visibility=visibility,
                                         duration=self.shape_display_duration)

        def create_info_label():
            return Label(size_hint=self.INFO_LABEL_SIZE_HINT)

        position_info = create_info_label()
        shape_info = create_info_label()
        overall_info = create_info_label()

        def update_position_info(instance, value):
            position_info.text = "Incorrect positions: %s" % value

        self.bind(p_errors=update_position_info)

        def update_shape_info(instance, value):
            shape_info.text = "Incorrect shapes: %s" % value

        self.bind(s_errors=update_shape_info)

        def update_overall_info(instance, value):
            overall_info.text = "%s / %s" % (value, self.max_iter)

        self.bind(iter=update_overall_info)

        self.add_widget(position_info)
        self.add_widget(shape_info)
        self.add_widget(overall_info)

        self.cells = []
        cell_shape_cls = Shapes.get(self.shape_type)
        for _ in xrange(self.GRID_SIZE):
            label = cell_shape_cls(self.start_noise_level)
            self.cells.append(label)
            self.add_widget(label)

        self.p_btn = Button(text="A: Position match",
                            size_hint=self.BTN_SIZE_HINT,
                            on_release=self.position_callback)
        self.add_widget(self.p_btn)
        self.n_btn = Button(text="F: Shape match",
                            size_hint=self.BTN_SIZE_HINT,
                            on_release=self.shape_callback)

        self.add_widget(self.n_btn)

        level_info = Label(text="[color=000000]%s-back[/color]" % self.history,
                           font_size="25sp",
                           markup=True,
                           size_hint=self.INFO_LABEL_SIZE_HINT)
        self.add_widget(level_info)
        # disable buttons at the start
        self.p_btn.disabled = True
        self.n_btn.disabled = True
Example #19
0
import numpy as np

from config import fps, pointer_size, start, end
from cursor import Cursor
from download import fetch_file
from metadata import Metadata
from shapes import Shapes

metadata = Metadata(fetch_file("metadata.xml"))

print(f'found "{metadata.meetingName}"')
print(f"starting on {metadata.starttime}")

cursor = Cursor(fetch_file("cursor.xml"))

shapes = Shapes(fetch_file("shapes.svg"))
for slide in shapes.slides:
    a = slide.file  # pre-download slide images

audio = fetch_file("video/webcams.webm", show_progress=True)

print("start generating video")
if start is None:
    time = 0
else:
    time = start
if end is None:
    end = metadata.duration
    print(end)
frame_len = 1 / fps
slide_id = -1
Example #20
0
class Features:

    # initialise features
    def __init__(self, config_provider):

        text_to_speech = None
        if (
            config_provider.acting
            or config_provider.audio_classifier
            or config_provider.browser
            or config_provider.calculator
            or config_provider.fruit_machine
            or config_provider.hand_gesture
            or config_provider.happy_colour
            or config_provider.iris_classifier
            or config_provider.mixing_desk
            or config_provider.optical_character_recognition
            or config_provider.play_your_cards_right
            or config_provider.shapes
            or config_provider.slideshow
            or config_provider.weather
        ):
            from texttospeech import TextToSpeech

            text_to_speech = TextToSpeech()

        speech_to_text = None
        if (
            config_provider.acting
            or config_provider.browser
            or config_provider.calculator
            or config_provider.fruit_machine
            or config_provider.iris_classifier
            or config_provider.mixing_desk
            or config_provider.phrase_translation
            or config_provider.play_your_cards_right
            or config_provider.weather
        ):
            from speechtotext import SpeechToText

            speech_to_text = SpeechToText()

        self.acting = None
        if config_provider.acting:
            from acting import Acting

            self.acting = Acting(text_to_speech, speech_to_text)

        self.audio_classifier = None
        if config_provider.audio_classifier:
            from audioclassifier import AudioClassifier

            self.audio_classifier = AudioClassifier(text_to_speech)

        self.browser = None
        if config_provider.browser:
            from browser import Browser

            self.browser = Browser(text_to_speech, speech_to_text)

        self.calculator = None
        if config_provider.calculator:
            from calculator import Calculator

            self.calculator = Calculator(text_to_speech, speech_to_text)

        self.fruit_machine = None
        if config_provider.fruit_machine:
            from fruitmachine import FruitMachine

            self.fruit_machine = FruitMachine(text_to_speech, speech_to_text)

        self.hand_gesture = None
        if config_provider.hand_gesture:
            from handgesture import HandGesture

            self.hand_gesture = HandGesture(text_to_speech)

        self.happy_colour = None
        if config_provider.happy_colour:
            from happycolour import HappyColour

            self.happy_colour = HappyColour(text_to_speech)

        self.iris_classifier = None
        if config_provider.iris_classifier:
            from irisclassifier import IrisClassifier

            self.iris_classifier = IrisClassifier(text_to_speech, speech_to_text)

        self.mixing_desk = None
        if config_provider.mixing_desk:
            from mixingdesk import MixingDesk

            self.mixing_desk = MixingDesk(text_to_speech, speech_to_text)

        self.optical_character_recognition = None
        if config_provider.optical_character_recognition:
            from opticalcharacterrecognition import OpticalCharacterRecognition

            self.optical_character_recognition = OpticalCharacterRecognition(text_to_speech)

        self.phrase_translation = None
        if config_provider.phrase_translation:
            from phrasetranslation import PhraseTranslation

            self.phrase_translation = PhraseTranslation(speech_to_text)

        self.play_your_cards_right = None
        if config_provider.play_your_cards_right:
            from playyourcardsright import PlayYourCardsRight

            self.play_your_cards_right = PlayYourCardsRight(text_to_speech, speech_to_text)

        self.shapes = None
        if config_provider.shapes:
            from shapes import Shapes

            self.shapes = Shapes(text_to_speech)

        self.slideshow = None
        if config_provider.slideshow:
            from slideshow import Slideshow

            self.slideshow = Slideshow(text_to_speech)

        self.television = None
        if config_provider.television:
            from television import Television

            self.television = Television()

        self.weather = None
        if config_provider.weather:
            from weather import Weather

            self.weather = Weather(text_to_speech, speech_to_text)

    # indicate whether a feature is speaking
    def is_speaking(self):
        return (
            (self.acting and self.acting.is_speaking)
            or (self.audio_classifier and self.audio_classifier.is_speaking)
            or (self.browser and self.browser.is_speaking)
            or (self.calculator and self.calculator.is_speaking)
            or (self.fruit_machine and self.fruit_machine.is_speaking)
            or (self.hand_gesture and self.hand_gesture.is_speaking)
            or (self.happy_colour and self.happy_colour.is_speaking)
            or (self.iris_classifier and self.iris_classifier.is_speaking)
            or (self.mixing_desk and self.mixing_desk.is_speaking)
            or (self.optical_character_recognition and self.optical_character_recognition.is_speaking)
            or (self.phrase_translation and self.phrase_translation.is_speaking)
            or (self.play_your_cards_right and self.play_your_cards_right.is_speaking)
            or (self.shapes and self.shapes.is_speaking)
            or (self.slideshow and self.slideshow.is_speaking)
            or (self.weather and self.weather.is_speaking)
        )

    # provide emotion from a feature
    def get_emotion(self):
        if self.acting:
            return self.acting.emotion
        if self.fruit_machine:
            return self.fruit_machine.emotion
        if self.hand_gesture:
            return self.hand_gesture.emotion
        if self.happy_colour:
            return self.happy_colour.emotion

        return None

    # update background image from a feature
    def update_background_image(self, image):
        if self.fruit_machine and self.fruit_machine.background_image.size > 0:
            return self.fruit_machine.background_image
        if self.iris_classifier and self.iris_classifier.background_image.size > 0:
            return self.iris_classifier.background_image
        if self.shapes and self.shapes.background_image.size > 0:
            return self.shapes.background_image
        if self.slideshow and self.slideshow.background_image.size > 0:
            return self.slideshow.background_image
        if self.television and self.television.background_image.size > 0:
            return self.television.background_image

        return image

    # handle features
    def handle(self, rocky_robot, sporty_robot, image):
        self._handle_acting(rocky_robot, sporty_robot)
        self._handle_audio_classifier(rocky_robot, sporty_robot)
        self._handle_browser(rocky_robot, sporty_robot)
        self._handle_calculator(rocky_robot, sporty_robot)
        self._handle_fruit_machine(sporty_robot, image)
        self._handle_hand_gesture(rocky_robot, sporty_robot, image)
        self._handle_happy_colour(rocky_robot, image)
        self._handle_iris_classifier(rocky_robot, sporty_robot, image)
        self._handle_mixing_desk(rocky_robot)
        self._handle_optical_character_recognition(rocky_robot, sporty_robot, image)
        self._handle_phrase_translation(sporty_robot)
        self._handle_play_your_cards_right(sporty_robot)
        self._handle_shapes(rocky_robot, sporty_robot, image)
        self._handle_slideshow(rocky_robot, sporty_robot, image)
        self._handle_television(rocky_robot, sporty_robot, image)
        self._handle_weather(rocky_robot, sporty_robot)

    # handle acting
    def _handle_acting(self, rocky_robot, sporty_robot):
        if not self.acting:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.acting.start()
        else:
            self.acting.stop()

    # handle audio classifier
    def _handle_audio_classifier(self, rocky_robot, sporty_robot):
        if not self.audio_classifier:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.audio_classifier.start()
        else:
            self.audio_classifier.stop()

    # handle browser
    def _handle_browser(self, rocky_robot, sporty_robot):
        if not self.browser:
            return

        if rocky_robot.is_facing:
            self.browser.start(ROCK)
        elif sporty_robot.is_facing:
            self.browser.start(SPORT)
        else:
            self.browser.stop()

    # handle calculator
    def _handle_calculator(self, rocky_robot, sporty_robot):
        if not self.calculator:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.calculator.start()
        else:
            self.calculator.stop()

    # handle fruit machine
    def _handle_fruit_machine(self, sporty_robot, image):
        if not self.fruit_machine:
            return

        if sporty_robot.is_facing:
            self.fruit_machine.start(image)
        else:
            self.fruit_machine.stop()

    # handle hand gesture
    def _handle_hand_gesture(self, rocky_robot, sporty_robot, image):
        if not self.hand_gesture:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.hand_gesture.start(image)
        else:
            self.hand_gesture.stop()

    # handle happy colour
    def _handle_happy_colour(self, rocky_robot, image):
        if not self.happy_colour:
            return

        if rocky_robot.is_facing:
            self.happy_colour.start(image)
        else:
            self.happy_colour.stop()

    # handle iris classifier
    def _handle_iris_classifier(self, rocky_robot, sporty_robot, image):
        if not self.iris_classifier:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.iris_classifier.start(image)
        else:
            self.iris_classifier.stop()

    # handle mixing desk
    def _handle_mixing_desk(self, rocky_robot):
        if not self.mixing_desk:
            return

        if rocky_robot.is_facing:
            self.mixing_desk.start()
        else:
            self.mixing_desk.stop()

    # handle optical character recognition
    def _handle_optical_character_recognition(self, rocky_robot, sporty_robot, image):
        if not self.optical_character_recognition:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.optical_character_recognition.start(image)
        else:
            self.optical_character_recognition.stop()

    # handle phrase translation
    def _handle_phrase_translation(self, sporty_robot):
        if not self.phrase_translation:
            return

        if sporty_robot.is_facing:
            self.phrase_translation.start()
        else:
            self.phrase_translation.stop()

    # handle play your cards right
    def _handle_play_your_cards_right(self, sporty_robot):
        if not self.play_your_cards_right:
            return

        if sporty_robot.is_facing:
            self.play_your_cards_right.start()
        else:
            self.play_your_cards_right.stop()

    # handle shapes
    def _handle_shapes(self, rocky_robot, sporty_robot, image):
        if not self.shapes:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.shapes.start(image)
        else:
            self.shapes.stop()

    # handle slideshow
    def _handle_slideshow(self, rocky_robot, sporty_robot, image):
        if not self.slideshow:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.slideshow.start(image)
        else:
            self.slideshow.stop()

    # handle television
    def _handle_television(self, rocky_robot, sporty_robot, image):
        if not self.television:
            return

        if rocky_robot.is_rendered or sporty_robot.is_rendered:
            self.television.start(image)
        else:
            self.television.stop()

    # handle weather
    def _handle_weather(self, rocky_robot, sporty_robot):
        if not self.weather:
            return

        if rocky_robot.is_facing or sporty_robot.is_facing:
            self.weather.start()
        else:
            self.weather.stop()
Example #21
0
        print("Mono: clean %dms (%dms ea), draw %dms (%dms ea), total %dms" %
              (tc, tc // (4 + 22 + 24), td, td // len(self._wave), tt))

        ip.clean(2, 2)
        ip.clean(3, 1)
        ip.power_off()

    # @micropython.viper
    def clear(self):
        self.fill(0)
        # fb = ptr8(self._framebuf)
        # for ix in range(D_ROWS * D_COLS // 8):
        #    fb[ix] = 0


Shapes.__mix_me_in(InkplateMono)


# Inkplate display with 2 bits of gray scale (4 levels)
class InkplateGS2(framebuf.FrameBuffer):
    _wave = None

    def __init__(self):
        self._framebuf = bytearray(D_ROWS * D_COLS // 4)
        super().__init__(self._framebuf, D_COLS, D_ROWS, framebuf.GS2_HMSB)
        if not InkplateGS2._wave:
            InkplateGS2._gen_wave()

    # _gen_wave generates the waveform table. The table consists of N phases or steps during
    # each of which the entire display gets written. The array in each phase gets indexed with
    # a nibble of data and contains the 32-bits that need to be pushed into the gpio port.
Example #22
0
             .expects("call6").with_args(arg1, arg2, kw1=kw1, kw2=kw2)
             )
         
         (Chain(proxy)
             .call1(arg1)
             .call2()
             .call3(kw1=kw1)
             .call4(arg2)
             .call5()
             .call6(arg1, arg2, kw1=kw1, kw2=kw2)
             )
 
 describe "Managing the proxy":
     it "is possible to add new proxies and go back to old ones":
         shapes = (
             Chain(Shapes())
             
                 .create('square')
                 .chain_promote_value()
                     .set_length(4)
                 .chain_demote_value()
                 
                 .create('rectangle')
                 .chain_promote_value()
                     .set_width(6)
                     .set_length(8)
                 .chain_demote_value()
                 
             .chain_exit()
             )