Example #1
0
def run():
    IMU = arduino.IMU()

    start = (0, 0)
    end = (200, 200)
    grid, start, end = mapmaker.read()

    mToI = 1

    posX = buggyinfo.Position(start[0], metersToIndex=mToI)
    posY = buggyinfo.Position(start[1], metersToIndex=mToI)
    posZ = buggyinfo.Position(0, initialV=1, metersToIndex=mToI)

    drawer = draw.Drawer(300, 300, 700, 700, start, end)

    while drawer.done is False:
        accel, gyro, dt = IMU.getIMU()

        accel.x = 0.01
        accel.y = 0.01
        dt = 1

        posX.update(accel.x, dt)
        posY.update(accel.y, dt)
        posZ.update(accel.z, dt)

        drawer.updateNode(posX.convert(), posY.convert(), posZ.convert(),
                          False)

        drawer.loop()
        drawer.drawParticle(int(posX), int(posY))
        drawer.update()
Example #2
0
def run(rows=40,
        cols=40,
        cell_size=10,
        initial_x=0,
        initial_y=0,
        final_x=20,
        final_y=39):
    drawer = draw.Drawer('temp.svg')
    m = maze.Maze(rows, cols, cell_size, drawer)
    m.generate(initial_x, initial_y, final_x, final_y)
    out = m.draw()
    return out
Example #3
0
def main():
    grid = board.Grid()
    fileExt = "DotBoi.eps"
    bprocessor = boardProcessor.Process(tileSize, thresholding, threshNum, smallestSquareSize)
    iprocessor = imgProcessor.Process(tileSize)
    drawer = draw.Drawer(tileSize, setShapeColors, setLines, lineWidth, setDotColors, setDots, \
                         dotRadius, setLineColors, setShapes, fancyColor, greyShades, diagRestrict)

    grid.photo = iprocessor.makeImage(photoName + ".jpg", tileSize)
    bprocessor.makeSquares(grid) #Makes all squares
    bprocessor.makeNeighbors(grid) #Sets neighbors of all squares and creates coords!
    PSFile = open(photoName + fileExt, "w+")
    drawer.drawPS(grid, PSFile)
Example #4
0
    def __init__(self, **kwargs):
        """
        Constructor.

        Arguments:
            kwargs -- Arguments.
        """

        super(GUI, self).__init__(**kwargs)

        # Initialize drawer.
        # We draw in (0, 100) * (0, 100) area in physical world.
        # It is impossible to set painting area yet, because window is not created.
        phys_area = draw.Area((0.0, 100.0), (0.0, 100.0))
        self.Drawer = draw.Drawer(phys_area, self, None)
Example #5
0
def run():
    motorSpeed = 40
    motorForward = False

    #    motor = arduino.DCMotor(1)
    #    IMU = arduino.IMU()
    # button1 = Arduino.Button(0)

    posX = buggyinfo.position(0)
    posY = buggyinfo.position(0)
    posZ = buggyinfo.position(0)

    drawer = draw.Drawer(200, 200, 700, 700, (20, 20), (70, 80))

    while drawer.done is False:
        #        if motorForward == True:
        #            motor.driveForward(motorSpeed)
        #        else:
        #            motor.driveBackward(motorSpeed)

        #        motorSpeed += 5
        #        if motorSpeed > 255:
        #            motorSpeed = 40
        #            motorForward = not motorForward
        #        data = IMU.getIMU()
        data = drawer.getAccel()
        accel = accel = kalman.smooth(data[0:3])
        yaw, pitch, roll = data[3:6]
        dt = data[6]

        posX.update(accel[0], dt)
        posY.update(accel[1], dt)
        posZ.update(accel[2], dt)

        print(posX, posY, posZ), (yaw, pitch, roll), accel

        drawer.loop()
        drawer.drawParticle(int(posX), int(posY))
        drawer.update()

    drawer.deinit()
    arduino.arduino.stop()
Example #6
0
    def Draw(self,
             fun,
             is_draw_color_field=True,
             is_draw_cells=True,
             is_draw_patterns=True,
             is_draw_velocity_field=True):
        d = draw.Drawer(draw_area=(0.0, 0.0, self.SizeX, self.SizeY),
                        pic_size=(800, 800))
        """
        Draw picture.

        Arguments:
            d -- drawer,
            pic_size -- picture size.
        """

        (mn, mx) = self.FunInterval(fun)

        if is_draw_color_field:

            # Coloring.
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    factor = 255 - int((fun(c) - mn) / (mx - mn) * 255)
                    color = (factor, factor, factor)
                    d.Rect(c.LoCorner.Tuple(2), c.HiCorner.Tuple(2),
                           aggdraw.Pen(color, 1.0), aggdraw.Brush(color))

        d.Rect((0.0, 0.0), (self.SizeX, self.SizeY), aggdraw.Pen('blue', 1.0))

        # Draw ellipse.
        d.Ellipse(Sph.LoPoint().Tuple(2),
                  Sph.HiPoint().Tuple(2),
                  pen=aggdraw.Pen('black', 2.0))

        if is_draw_cells:

            # Inner.
            pen = aggdraw.Pen('orange', 2.0)
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    if c.Type == TypeInner:
                        d.Rect(c.LoCorner.Tuple(2), c.HiCorner.Tuple(2), pen)

            # Ghost.
            pen = aggdraw.Pen('red', 2.0)
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    if c.Type == TypeGhost:
                        d.RectWithCenterPoint(c.LoCorner.Tuple(2),
                                              c.HiCorner.Tuple(2), 1, pen)

            # Border.
            pen = aggdraw.Pen('green', 2.0)
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    if c.Type == TypeBorder:
                        d.RectWithCenterPoint(c.LoCorner.Tuple(2),
                                              c.HiCorner.Tuple(2), 1, pen)

        if is_draw_patterns:

            # Draw shpere nearest points.
            pen = aggdraw.Pen('black', 2.0)
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    if c.BorderPoint != None:
                        d.Point(c.BorderPoint.Tuple(2), 1.0, pen)
                        d.Line(c.BorderPoint.Tuple(2),
                               (c.BorderPoint +
                                0.05 * c.BorderNormal).Tuple(2), pen)

            # Draw approximate patterns.
            pen = aggdraw.Pen('pink', 2.0)
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    if (c.App1 != None) and (c.App2 != None):
                        d.FullGraph([
                            c.BorderPoint.Tuple(2),
                            c.App1.Tuple(2),
                            c.App2.Tuple(2)
                        ], pen)

        if is_draw_velocity_field:

            # Draw velocity speed.
            pen = aggdraw.Pen('steelblue', 1.0)
            for i in range(self.CellsX):
                for j in range(self.CellsY):
                    c = self.Cells[i][j][0]
                    if (c.Type == TypeCommon) or (c.Type == TypeBorder) or (
                            c.Type == TypeGhost):
                        v = geom.Vector(c.D.u, c.D.v, 0.0)
                        if v.Mod() < 0.001:
                            d.Point(c.Center.Tuple(2), 1, pen)
                        else:
                            v.Normalize()
                            v.Scale(0.4 * self.dx)
                            d.Line((c.Center - v).Tuple(2),
                                   (c.Center + v).Tuple(2), pen)

        d.FSS()
Example #7
0
import cv2 as cv
import draw as drw
import pipeline as p
import image2world as i2w
jetson_UART = "/dev/ttyTHS1"
drawer = drw.Drawer(jetson_UART)

start_offset = 13
try:
    cam = cv.VideoCapture(0, cv.CAP_V4L2)
    cam.set(3, 1280)  # height
    cam.set(4, 720)  # width

    objPoints = [[[25.1], [3.1], [0]], [[25.8], [19], [0]], [[4.3], [18.1],
                                                             [0]],
                 [[4], [3.5], [0]]]
    #objPoints = [[[26.65],[1], [0]], [[26.05],[22.2], [0]], [ [0],[23], [0]], [[0], [0], [0]] ]
    params = p.chessboard_calibrate('calibration', 6, 8, debug=False)
    ret, mtx, dist, rvecs, tvecs = params

    img = p.capture_image(cam)  # calibration first
    xyz = i2w.ImageToWorld(mtx, dist, objPoints)
    xyz.locate_keypoints(img)

    xyz.find_inverse_params()
    img = p.capture_image(cam)  # puzzle

    drawPoints, src = xyz.convert_to_xy(
        getattr(xyz, 'imagePoints').tolist(), img)

    p.display(src)
Example #8
0
def main():
    args = parse_args()

    if int(str(pytesseract.get_tesseract_version())[0]) < 4:
        sys.exit('Tesseract 4.0.0 or greater required!')

    if args.everything:
        jetson_UART = "/dev/ttyTHS1"
        drawer = drw.Drawer(jetson_UART)

    cam = cv.VideoCapture(0, cv.CAP_V4L2)
    cam.set(3, 1280)  # height
    cam.set(4, 720)  # width

    xyz = capture_image(cam)
    xyz_params = chessboard_calibrate('calibration_dummy', 6, 8, debug=False)
    ret, mtx, dist, rvecs, tvecs = xyz_params
    h, w = xyz.shape[:2]
    newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w, h), 1,
                                                     (w, h))
    xyz = cv.undistort(xyz, mtx, dist, None, newcameramtx)
    x, y, w, h = roi
    xyz = xyz[y:y + h, x:x + w]
    xy_check = i2wt.uv_to_xy(xyz, xyz_params, [], True)
    display(xy_check[0])
    print(xy_check[1])

    while True:
        try:
            if args.image:
                img = cv.imread(args.image)
            else:
                img = capture_image(cam)

            # Camera Calibration
            # param order ret, mtx, dist, rvecs, tvecs
            if not args.image:
                params = chessboard_calibrate('calibration', 6, 8, debug=False)
                ret, mtx, dist, rvecs, tvecs = params
                h, w = img.shape[:2]
                newcameramtx, roi = cv.getOptimalNewCameraMatrix(
                    mtx, dist, (w, h), 1, (w, h))
                img = cv.undistort(img, mtx, dist, None, newcameramtx)
                x, y, w, h = roi
                img = img[y:y + h, x:x + w]

                #display(img, 'Calibration Output')

            img = remove_shadow(img)
            puzzle, bank, x_offset, y_offset = segment(img, True)

            detected_puzzle, detected_bank, char_coords = tesseract(puzzle,
                                                                    bank,
                                                                    x_offset,
                                                                    y_offset,
                                                                    debug=True,
                                                                    img=img)
            solved_word_points = permutative_solve(detected_bank,
                                                   detected_puzzle)
            print(solved_word_points)
            solved_uv_points = i2wt.wordsearch_to_uv(char_coords,
                                                     solved_word_points)

            print(
                solved_uv_points
            )  #char_coords[solved_uv_points[0][0][0]][solved_uv_points[0][0][1]][2])

            #solved_uv_points = [[[[468 ], [222]],[[470],[642]]], [[[764],[446]], [[1064],[220]]]]
            to_MSP_points = i2wt.uv_to_xy(xyz, xyz_params, solved_uv_points,
                                          False)
            display(to_MSP_points[0])
            if args.everything:
                scaling_factor_x = 0.22
                scaling_factor_y = 0.22
                start_offset_x = 3.75
                start_offset_y = 6.6
                drawer.read(1)
                for point_pair in to_MSP_points[1]:
                    x1 = int(
                        round((point_pair[0][0] + start_offset_x) /
                              scaling_factor_x))
                    y1 = int(
                        round((point_pair[0][1] + start_offset_y) /
                              scaling_factor_y))
                    x2 = int(
                        round((point_pair[1][0] + start_offset_x) /
                              scaling_factor_x))
                    y2 = int(
                        round((point_pair[1][1] + start_offset_y) /
                              scaling_factor_y))
                    to_draw = [(x1, y1), (x2, y2)]
                    drawer.draw(to_draw)
                    drawer.read(1)
                drawer.send(255)
                cv.destroyAllWindows()
        except Exception as e:
            print(e)
        except (KeyboardInterrupt):
            print('See ya later!')
            if args.everything:
                drawer.cleanup()
            break
Example #9
0
import draw

drawer = draw.Drawer(20, 20, 700, 700, (20, 20), (70, 80))

drawer.loop()
Example #10
0
    xvals = np.dot(xPoints, polynomial_array)
    yvals = np.dot(yPoints, polynomial_array)

    return xvals, yvals


if __name__ == "__main__":
    import astar
    import draw
    from matplotlib import pyplot as plt

    grid, start, end = mapmaker.make(30, 30), (0, 0), (5, 5)
    height, width = grid.shape[0:2]

    drawer = draw.Drawer(width, height, 700, 700, start, end, grid)

    while drawer.done == False:
        drawer.loop()
        drawer.update()
    drawer.deinit()
    path, pathInfo, plotTime = astar.search(grid, start, end)

    points = path[:5]

    xpoints = [p[0] for p in points]
    ypoints = [p[1] for p in points]

    xvals, yvals = bezier_curve(points, nTimes=1000)
    print(xvals, yvals)
Example #11
0
import data_generation as dg
import draw as d
from algorithm.km_smote import Over_Sample
from algorithm.under_sample import Under_Sample


if __name__ == "__main__":
    dg = dg.DataGenerator(1000, 0.9)
    data, label = dg.generate()
    di = {"n_clusters": 10}
    osampler = Over_Sample(data=data, label=label, n=3, categorical_features=[], **di)
    syth = osampler.do_synthetic()
    print("syth leng", len(syth))
    syth_label = [1.0] * len(syth)
    dr = d.Drawer(data, label)
    dr.plot_scatter()
    dr1 = d.Drawer(syth, syth_label)
    dr1.plot_scatter()
    under_sample = Under_Sample(major=data[0:900].tolist(), major_label=[0.]*900, synthetics=syth, synthetics_label=syth_label, categorical_features=[], rate=0.5, **di)
    under = under_sample.do_undersample()
    print("under length", len(under))
    under_label = [0.0] * len(under)
    x = under + syth
    y = under_label + syth_label
    dr2 = d.Drawer(x, y)
    dr2.plot_scatter()
Example #12
0
        import pygame, draw, human_pacman
        from pygame.locals import *

        # Create a clock object
        clock = pygame.time.Clock()

        # Initialize PyGame and the game window
        pygame.init()
        pygame.display.set_caption("Learning Pac-Man")
        window = pygame.display.set_mode((1, 1))

        # Extract the screen from the display
        screen = pygame.display.get_surface()

        # Create the drawing object, it takes a reference to the screen and the state
        drawer = draw.Drawer(screen, state)

        # Give the game engine a reference to the drawing object
        game.set_drawing_object(drawer)

        # Just for fun, display a window and tray icon
        pygame.display.set_icon(
            pygame.transform.scale(
                pygame.image.load("images/pacman-r3.gif").convert(), (32, 32)))

    elif not game.manager.config_options['ai_mode']:
        raise PacmanError(
            "Cannot run game with graphics OFF if not in training mode")

    # Load the first level
    game.updater.reset_game()
Example #13
0
def run():
    # Init arduino properties, drawer, and map
    # while exit is false:
    # get accel and gyro
    # smooth with kalman
    # get position
    # update map (any new blocked nodes? Use image processing, ultrasonic, and other sensors)
    # plot astar to end
    # plot smooth path through next four nodes, extract angles (bezier curve, if angle is greater than allowed turn radius, eliminate node from path, or if its another buggy, slow the hell down!!!)
    # command angles to arduino until next node appears

    dcmotor = arduino.DCMotor(1)
    IMU = arduino.IMU()
    button1 = arduino.Button(3)
    sonar1 = arduino.Sonar(1)

    # grid, start, end = mapmaker.read()
    grid, start, end = mapmaker.make(30, 30), (0, 0), (5, 5)
    height, width = grid.shape[0:2]

    posX = buggyinfo.Position(start[0])
    posY = buggyinfo.Position(start[1])
    posZ = buggyinfo.Position(0)

    drawer = draw.Drawer(width, height, 700, 700, start, end, grid)

    dcmotor.driveForward(100)

    while drawer.done is False:
        # time0 = time.time()
        accel, gyro, magnet, dt = IMU.getIMU()  # get accel and gyro

        # get position
        posX.update(accel.x, dt)
        posY.update(accel.y, dt)
        posZ.update(accel.z, dt)

        # magnet.roll, magnet.pitch, magnet.yaw = \
        #     buggyinfo.convertToHeading(magnet.x, magnet.y, magnet.z)

        # print "(%0.3f, %0.3f, %0.3f)\t(%0.3f, %0.3f, %0.3f)" % \
        #       (gyro.roll, gyro.pitch, gyro.yaw,
        #        magnet.roll, magnet.pitch, magnet.yaw)
        #        print "%s\t%s\t%s" % (accel.x, accel.y, accel.z)
        # print(sonar1.getDistance())

        #        if button1.wasPressed():
        #            dcmotor.reverse()

        # update map (any new blocked nodes? Use image processing, ultrasonic, and other sensors)
        # ignore until below routines are finished

        # plot astar to end
        # path, pathInfo, plotTime = astar.search(grid, (posX, posY), end)

        # plot smooth path through next four nodes, extract angles

        # command angles to arduino until next node appears
        drawer.loop()
        drawer.drawParticle(int(posX), int(posY))
        drawer.update()

        # print time.time() - time0

    drawer.deinit()
    arduino.arduino.stop()