Esempio n. 1
0
			def makerectangle(i,j) :
				j = j - numperiods / 2
				aprime = (.9 + (.1 / 49) * j**2) if abs(j) < 7 else 1
				myrect=shapes.rectangle([hx * aprime, hy], color=color)
				myrect.space = [a * aprime, w]
				myrect.position = [.5 * (myrect.space[0] - myrect.size[0]), 0, 0]
				return myrect
Esempio n. 2
0
def draw_arm(settings, which_arm):
    """
    Draws an arm, starting with the upper arm, then the lower arm, and finally the hand
    """
    fillcolor(ARM_COLOR)
    with restore_state_when_finished():
        update_position(ARM_ORIGIN)
        right(90)
        shoulder_angle = settings[which_arm + '_arm_shoulder_angle']
        right(shoulder_angle)
        rectangle_from_side_edge(UPPER_ARM_WIDTH, UPPER_ARM_LENGTH)
        fly(UPPER_ARM_LENGTH)
        elbow_angle = settings[which_arm + '_arm_elbow_angle']
        right(elbow_angle)
        rectangle_from_side_edge(LOWER_ARM_WIDTH, LOWER_ARM_LENGTH)
        fly(LOWER_ARM_LENGTH)
        left(45)
        rectangle(HAND_WIDTH, HAND_LENGTH)
Esempio n. 3
0
import shapes as sh

print(sh.circle(4))
print(sh.rectangle(4, 5))
print(sh.triangle(4, 6))
Esempio n. 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2015-05-17 15:50:58
# @Author  : chenhao ([email protected])
# @Link    : http://www.xjchenhao.cn
# @Version : $Id$

import shapes

# print(dir(shapes))

shapes.rectangle(2, 3)
Esempio n. 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2015-05-17 15:50:58
# @Author  : chenhao ([email protected])
# @Link    : http://www.xjchenhao.cn
# @Version : $Id$

import shapes
# print(dir(shapes))

shapes.rectangle(2, 3)
Esempio n. 6
0
				myrect=shapes.rectangle([hx * aprime, hy], color=color)
				myrect.space = [a * aprime, w]
				myrect.position = [.5 * (myrect.space[0] - myrect.size[0]), 0, 0]
				return myrect

			#generate the lattice of rectangles for the ladder
			mypc=shapes.photonic_crystal_shape_spacing(makerectangle,[1,numperiods], position = [0, .3 * .5 * w])
			mypc.position = sumlist(mypc.position, startposition)
			mypc.write(mydcfile)


			#generate the top and bottom parts of the ladder
			bar_width = .100 # .1 * w
			gap_width = 1. * w
			#bottom gap, bottom bar
			myrect = shapes.rectangle([mypc.size[0], bar_width], position = [0, -1 * gap_width], color = color)
			myrect.position = sumlist(myrect.position, startposition)
			myrect.write(mydcfile)
			#bottom gap, middle bar - position is the average of top and bottom bar
			myrect = shapes.rectangle([mypc.size[0], bar_width], position = [0, -.5 * (gap_width + bar_width)], color = color)
			myrect.position = sumlist(myrect.position, startposition)
			myrect.write(mydcfile)
			#bottom gap, top bar
			myrect = shapes.rectangle([mypc.size[0], bar_width], position = [0, -1 * bar_width], color = color)
			myrect.position = sumlist(myrect.position, startposition)
			myrect.write(mydcfile)

			# generate the hatches in the top and bottom portions that will be cut away
			numbreaks = 4
			xwidth = bar_width
			spacing = ( mypc.size[0] - xwidth ) / numbreaks
Esempio n. 7
0
import shapes

room1 = shapes.square(4)
room2 = shapes.rectangle(4, 2)

Esempio n. 8
0
	#straight edges. We can use this to write arbtitrary polygons. In this example
	#we write a triangle. Note how we use the color argument to make it blue.
	mypolyline=shapes.polyline(color=[0, 0, 1])
	mypolyline.addline([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 0, 0])
	mypolyline.write(mydcfile)

	#Circles are even easier to write. All we need to do is specify the radius.
	#If we want to change the position, we have to set the position variable.
	mycircle=shapes.circle(2,position=[-5, 0, 0])
	mycircle.setcolor([0,1,0])
	mycircle.write(mydcfile)

	#We can also write a rectangle. This is a simpler form of a polyline.
	#Again, we use position to change its location. Offset must be an array of
	#length 2 or 3. Also, this time I set the color after defining the shape.
	myrect=shapes.rectangle([3,4],position=[-5,0,0])
	myrect.setcolor([0,0,1])
	myrect.write(mydcfile)

	#To write a lattice: we define a function that returns a shape. This 
	#function must accept two arguments, which represent the row number and the 
	#column number. So if we want to change the properties of one of the 
	#circles, we can add an if statement to change it. This will change the 
	#position and the radius of the circle.
	def fshape(i, j) : 
		a = shapes.circle(2)
		if i == 2 and j == 2 : 
			a.setradius(1)
			a.position = [2, 2]
		#else : 
			#a.position = [0, 0]
Esempio n. 9
0
 def test_rect(self):
     rect = shapes.rectangle()
     rect.setLength(5)
     rect.setWidth(7)
     self.assertEquals(rect.getPerimeter(), 24)
     self.assertEquals(rect.getArea(), 35)
def collisionCheck(player, enemy):
    if player.getX() + 50 >= enemy.getX():
        if player.getY() <= enemy.getY() + 50 and player.getY() + 50 >= enemy.getY():
            return True
    return False


root = Tk()
root.title("Game_Example")
root.geometry("1000x700")

canvas = Canvas(width=1000, height=700, bg="black")
canvas.grid()

guiRect = canvas.create_rectangle(0, 350, 50, 400, outline="black", fill="white")
playerRect = shapes.rectangle(400, 350)

enemyGuiRect = canvas.create_rectangle(0, 250, 150, 400, outline="black", fill="red")
enemyRect = shapes.rectangle(400, 250)

fartGuiCircle = canvas.create_oval(0, 600, 100, 500, outline="green", fill="yellow")
fartCircle = shapes.Circle(100, 100)


def timer():

    # playerRect.setX(10)
    # playerRect.setY(10)
    # canvas.move(guiRect,10,0)

    fartCircle.setX(50)
Esempio n. 11
0
import shapes as sh

print(sh.circle(10))
print(sh.rectangle(10, 5))
print(sh.triangle(10, 5))

print('główny - wartość zmiennnej __name__:', __name__)
Esempio n. 12
0
def main():
    video_path = "../../../dataset/project_video.mp4"

    # open the video file for reading
    cap = cv2.VideoCapture(video_path)

    # if not success, exit program
    if cap.isOpened() == False:
        print("Cannot open the video file:", video_path)
        exit(-1)

    # Uncomment the following line if you want to start the video in the middle
    #cap.set(cv2.CAP_PROP_POS_MSEC, 300);

    # get the frames rate of the video
    fps = cap.get(cv2.CAP_PROP_FPS)
    print("Frames per seconds:", fps)

    # set the wait time between each frame
    wait_time = 1000 / fps

    # get height and width
    frame_h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    frame_w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)

    # create windows
    cv2.namedWindow("video_window", cv2.WINDOW_NORMAL)
    cv2.namedWindow("warp_window")

    # create source points for polygon and transform

    a = 140
    b = 800
    t_center = np.round(frame_w / 2)
    t_height = 205
    t_y = frame_h - t_height - 60

    pts_src = shapes.trapazoid(a, b, t_center, t_height, t_y)

    # destination points for transform
    warp_img_size = (600, 600)
    pts_dst = shapes.rectangle(warp_img_size[0], warp_img_size[1])

    # Calculate Homography
    h, status = cv2.findHomography(pts_src, pts_dst)

    h2, status = cv2.findHomography(pts_dst, pts_src)
    """
    # Output image
    im_out
    """

    # polygon figure
    mask = np.matrix(np.ones((int(frame_h), int(frame_w))), dtype=np.int8)
    shapes.draw_polygon(mask, pts_src)
    """
    # time calculation
    clock_t time_s;
    time_s = clock();
    """

    color_basis = 256
    color_basis = np.uint8(256 / color_basis)

    key = -1
    pause = False
    start_time = time.time() * 1000
    while True:

        # read a new frame from video
        ret, frame = cap.read()

        # breaking the while loop at the end of the video
        if ret == False:
            print("Found the end of the video")
            break

        # warp source image to destination based on homography
        im_out = cv2.warpPerspective(frame, h, warp_img_size)

        cv2.imshow("Warp unthresholded", im_out)

        im_out = np.round(im_out / color_basis).astype(np.uint8)
        im_out = im_out * color_basis

        im_out = lanefinder.threshold(im_out, np.array([0, 0, 180]),
                                      np.array([255, 255, 255]))

        # draw trapazoid on the frame
        shapes.draw_polygon(frame, pts_src, color=(0, 0, 0), thickness=6)

        # show the frame in the created window
        cv2.imshow("video_window", frame)

        grid = (6, 6)

        #------------------------------------------------------------------------------
        mat = np.zeros([600, 600], dtype=np.uint8)

        blank_img = np.zeros((im_out.shape[0], im_out.shape[1], 3), np.uint8)
        blank_img[im_out > 0] = (255, 255, 255)

        line_l, line_r = lanefinder.find_lane_points(im_out, grid)

        line_l = np.vstack([line_l[0], line_l, line_l[-1]])
        line_l[-1, 1] = mat.shape[0] + 50
        line_l[0, 1] = -50

        line_r = np.vstack([line_r[0], line_r, line_r[-1]])
        line_r[-1, 1] = mat.shape[0] + 50
        line_r[0, 1] = -50

        print(line_l)
        print(line_r)

        for p in line_r:
            cv2.line(blank_img, (p[0] - 4, p[1]), (p[0] + 4, p[1]),
                     (255, 0, 0), 6)
        for p in line_l:
            cv2.line(blank_img, (p[0] - 4, p[1]), (p[0] + 4, p[1]),
                     (0, 255, 0), 6)

        cv2.imshow("gogibogi", blank_img)

        poly_l = np.polyfit(line_l[:, 0] + 0.1,
                            line_l[:, 1] + 0.1,
                            deg=2,
                            rcond=None,
                            full=False,
                            w=None,
                            cov=False)
        poly_r = np.polyfit(line_r[:, 0] + 0.1,
                            line_r[:, 1] + 0.1,
                            deg=2,
                            rcond=None,
                            full=False,
                            w=None,
                            cov=False)

        l_array = []
        r_array = []

        for x in range(np.min(line_l[:, 0]), np.max(line_l[:, 0]) + 5):
            y = int(poly_l[0] * x**2 + poly_l[1] * x + poly_l[2])
            #y = int(poly_l[0]*x + poly_l[1])

            if 0 <= y < 600 and 100 < x < 500:
                mat[y, x] = 255
                l_array.append((x, y))
        #l_array.append((np.max(line_l[:,0]),599))

        for x in range(np.min(line_r[:, 0]), np.max(line_r[:, 0]) + 5):
            #y = int(poly_r[0]*x + poly_r[1])
            y = int(poly_r[0] * x**2 + poly_r[1] * x + poly_r[2])

            if 0 <= y < 600 and 100 < x < 500:
                mat[y, x] = 255
                r_array.append((x, y))
        #r_array.append((np.max(line_r[:,0]),599))

        #for x in range(np.min(line_r[:,0]), np.max(line_r[:,0])):
        #    print([int(poly_r[0]*np.power(x,2) + poly_r[1]*x + poly_r[2]), x])
        shapes.draw_polygon(mat,
                            r_array,
                            color=(255, 0, 0),
                            thickness=10,
                            t=8,
                            shift=0,
                            close=False)
        shapes.draw_polygon(mat,
                            l_array,
                            color=(255, 0, 0),
                            thickness=10,
                            t=8,
                            shift=0,
                            close=False)

        #trap = np.matrix(pts_src, dtype=np.int16)
        #print(trap)
        #trap_w = np.max(trap[:,0]) - np.min(trap[:,0])
        #trap_h = np.max(trap[:,1]) - np.min(trap[:,1])
        #print(trap_h, trap_w)

        im_out2 = cv2.warpPerspective(mat, h2, (int(frame_w), int(frame_h)))

        cv2.imshow("ASDASD", mat)

        cv2.imshow("noesdfdsd", im_out)

        frame[im_out2 > 0] = (0, 0, 255)
        cv2.imshow("sushi", frame)

        #print(poly_l)

        #-------------------------------------------------------------------------------

        # calculate time it takes to do h**o transform
        calc_time = (time.time() * 1000) - start_time
        wait = wait_time

        # calculate waiting time to maintain fps
        if int(wait) > calc_time:
            wait -= calc_time
            wait = int(wait)
            if wait == 0:
                wait = 1
        else:
            wait = 1

        # wait for frame
        key = -1
        if pause == True:
            key = cv2.waitKey(0)
        else:
            key = cv2.waitKey(wait)

        if key == 32:
            pause = not pause
        elif key == 13:
            pass
        elif key > -1:
            # destroy the created window
            cv2.destroyAllWindows()
            exit(0)

        # get start time for calculating wait_time next iteration
        start_time = time.time() * 1000
Esempio n. 13
0
def main():
    video_path = "../../../dataset/project_video.mp4"
    #video_path = "/home/forat/Desktop/fackfack.mp4"

    # open the video file for reading
    cap = cv2.VideoCapture(video_path)

    # if not success, exit program
    if cap.isOpened() == False:
        print("Cannot open the video file:", video_path)
        exit(-1)

    # Uncomment the following line if you want to start the video in the middle
    #cap.set(cv2.CAP_PROP_POS_MSEC, 300);

    # get the frames rate of the video
    fps = cap.get(cv2.CAP_PROP_FPS)
    print("Frames per seconds:", fps)

    # set the wait time between each frame
    wait_time = 1000 / fps

    # get height and width
    frame_h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) * SCALE
    frame_w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) * SCALE

    # create windows
    cv2.namedWindow("video_window")
    cv2.namedWindow("plot_window")
    cv2.setMouseCallback("plot_window",
                         lanefinder.threshold_plot_event_handler)

    # create source points for polygon and transform

    a = 100 * SCALE
    b = 550 * SCALE
    t_center = np.round(frame_w / 2) + 10 * SCALE
    t_height = 205 * SCALE
    t_y = (frame_h - t_height - 60 * SCALE)

    pts_src = shapes.trapazoid(a, b, t_center, t_height, t_y)

    # destination points for transform
    warp_img_size = (600, 600)
    pts_dst = shapes.rectangle(warp_img_size[0], warp_img_size[1])

    # polygon figure
    mask = np.matrix(np.zeros((int(frame_h), int(frame_w))), dtype=np.uint8)
    shapes.fill_polygon(mask, pts_src, (1, 1, 1))

    # calculate factor for making simpler color pallatte
    #color_basis = 64 # change this in case you want less than 256 colors
    color_basis = 256  # change this in case you want less than 256 colors
    color_basis = np.uint8(256 / color_basis)

    # variables for loop run
    key = -1
    pause = False
    start_time = time.time() * 1000

    # loop through video
    while True:

        # read a new frame from video
        ret, frame = cap.read()

        # breaking the while loop at the end of the video
        if ret == False:
            print("Found the end of the video")
            break

        # get frame
        frame = cv2.resize(frame,
                           None,
                           fx=SCALE,
                           fy=SCALE,
                           interpolation=cv2.INTER_CUBIC)  # resize
        #frame[mask == 0] *= 0

        # copy frame to mod it
        mframe = np.copy(frame)

        # simplify color basis
        mframe[mask == 0] *= 0
        mframe = np.round(mframe / color_basis).astype(np.uint8)
        mframe = mframe * color_basis

        # find the intencity histogram of the red layer
        red_histo = lanefinder.i_histo(mframe[:, :, 2], limit=255, mask=mask)

        if np.max(red_histo) > 0:
            red_histo = np.array(red_histo) / np.max(red_histo) * 100

        # calculate threshold and threshold x position on plot
        dth = 5
        th, h = lanefinder.dynamic_threshold(red_histo, dth, 245)
        th += 20
        h += dth

        # prep for histogram plot
        plot = np.zeros((240, 600, 3), dtype=np.float)
        shapes.plot(plot, red_histo, y_max=300, color=(0, 0, 255), thickness=2)
        shapes.plot(plot,
                    h,
                    y_max=dth * 2 + 2,
                    color=(255, 0, 255),
                    thickness=2)

        static_th_x = int(lanefinder.plot_threshold())
        static_th = 180  #int(static_th_x/plot.shape[1] * 256)

        # add plot histogram
        th_x = int(th / 256 * plot.shape[1])
        cv2.line(plot, (th_x, 0), (th_x, plot.shape[1]), (255, 0, 0), 4)
        cv2.line(plot, (static_th_x, 0), (static_th_x, plot.shape[1]),
                 (0, 255, 0), 4)
        cv2.imshow("plot_window", plot)

        try:
            mframe1 = lanefinder.threshold(mframe, np.array([0, 0, th]),
                                           np.array([255, 255,
                                                     255]))  #, mask=mask)
            mframe2 = lanefinder.threshold(mframe, np.array([0, 0, static_th]),
                                           np.array([255, 255,
                                                     255]))  #,mask=mask)
        except:
            print("Frame crash, internal opencv problem..")
            continue

        # show the frame in the created window
        cv2.imshow("video_window", mframe1)
        cv2.imshow("shit", mframe2)

        # calculate time it takes to do h**o transform
        calc_time = (time.time() * 1000) - start_time
        wait = wait_time

        # calculate waiting time to maintain fps
        if int(wait) > calc_time:
            wait -= calc_time
            wait = int(wait)
            if wait == 0:
                wait = 1
        else:
            wait = 1

        # wait for frame
        key = -1
        if pause == True:
            key = cv2.waitKey(0)
        else:
            key = cv2.waitKey(wait)

        if key == 32:
            pause = not pause
        elif key == 27:
            # destroy the created window
            cv2.destroyAllWindows()
            exit(0)

        # get start time for calculating wait_time next iteration
        start_time = time.time() * 1000

        # frame     rho  theta  threshold  line    srn    stn
        #hough_lines = cv2.HoughLinesP(mframe2, 1, np.pi, static_th, minLineLength = 25, maxLineGap = 250)

        edges = cv2.Canny(mframe2, 100, 200)
        cv2.imshow("sadsad", edges)
        #lines = cv2.HoughLinesP(edges, 1, np.pi/180, threshold, 0, minLineLength, 20);

        #cv2.cvtColor()
        minLineLengths = 60
        maxLineGaps = 30
        gray_image = cv2.cvtColor(mframe2, cv2.COLOR_GRAY2BGR)

        lines = cv2.HoughLinesP(edges,
                                1,
                                np.pi / 180,
                                1,
                                minLineLength=minLineLengths,
                                maxLineGap=maxLineGaps)
        #HoughLinesP(cframe, lines, 1, CV_PI/180, 25, 30, 250 );
        print(lines)
        try:
            for line in lines:

                print(line)
                try:
                    cv2.line(frame, (line[0, 0], line[0, 1]),
                             (line[0, 2], line[0, 3]), (255, 0, 0),
                             thickness=3,
                             lineType=8)

                except:
                    pass
        except:
            pass
        cv2.imshow('hough', frame)
Esempio n. 14
0
 def test_rect(self):
     rect = shapes.rectangle()
     rect.setLength(5)
     rect.setWidth(7)
     self.assertEquals(rect.getPerimeter(), 24)
     self.assertEquals(rect.getArea(), 35)