Esempio n. 1
0
def main():

    binary_outputs = []
    thresholded_wrapeds = []
    results = []
    checker_path = 'camera_cal'
    imgs_path = 'test_images'
    checker_imgs = utils.get_images_by_dir(checker_path)
    lane_imgs = utils.get_images_by_dir(imgs_path)
    # 相机校正
    imgs, undistorts = cam.cam_calibration(checker_imgs, lane_imgs)
    #阈值过滤
    for undistort in undistorts:
        binary_output = threshold.thresholding(undistort)
        binary_outputs.append(binary_output)
    #透视变换
        M, Minv = perspective_transform.get_M_Minv()

        thresholded_wraped = cv2.warpPerspective(binary_output, M, undistort.shape[1::-1], flags=cv2.INTER_LINEAR)

    #检测车道边界、滑动窗口拟合
        left_fit, right_fit, left_lane_inds, right_lane_inds = find_line1.find_line(thresholded_wraped)
    #计算车道曲率、及车辆相对车道中心位置、显示信息
        curvature, distance_from_center = final_process.calculate_curv_and_pos(thresholded_wraped, left_fit, right_fit)
        result = final_process.draw_area(undistort, thresholded_wraped, Minv, left_fit, right_fit)
        final_process.draw_values(result, curvature, distance_from_center)
        results.append(result)



    for i in range(len(undistorts)):
        cv2.imshow('in_image', undistorts[i])
        cv2.imshow('result', results[i])
        cv2.waitKey(0)
def calculate_abs_prob():
    threshold_dic = {}  # to fill with thresholoded values

    # create an empty dictioraty to fill with all absolute probability for each device and for each hour
    abs_prob = {}
    i = 0

    for i in range(len(folder_list)):
        # thresholing to binarize the wattage in each time slot
        threshold_dic[folder_list[i]] = thresholding(output_folder,
                                                     folder_list[i],
                                                     threshold_list[i])

        # calculate the absolute probability for each hour (prob is passed-by-reference)
        absolute_prob(threshold_dic[folder_list[i]], abs_prob, folder_list[i])

    return threshold_dic, abs_prob
Esempio n. 3
0
    def run(self):
        global done, o_sides, o_color, o_thr, frame_count
        while not self.terminated:
            if self.event.wait(1) and not done:
                try:
                    self.stream.seek(0)
                    if display:
                        for event in pygame.event.get():
                            if event.type == QUIT:
                                pygame.quit()
                                done = True

                    image = self.stream.array
                    result = np.zeros((size[1], size[0], 3), np.uint8)

                    if o_thr:
                        # thresholding
                        thr_m = threshold.thresholding(image)
                        # morphology
                        mask = morphology.opening(thr_m)
                        # find object
                        mask, points, o_sides = find_any_moving_object(mask)
                    else:
                        # color
                        color_m = color.find_color(image, o_color)
                        # morphology
                        mask = morphology.closing(color_m)
                        # find object
                        mask, points = find_object(mask, o_sides)
                    #print points
                    center = aim.find_center(size, points, o_sides)
                    if center_display:
                        print center
                    degrees = aim.get_degrees(size, center)
                    if degree_display:
                        print degrees
                    hardware.move_by_degrees(degrees)
                    if np.sum(points) > 0:
                        target_found = True
                        frame_count += 1
                        if frame_count > 8:
                            hardware.fire()
                            if not display:
                                print "Weapon fired!"
                                print "The 'Destroyer' will now be deactivated"
                                done = True
                    else:
                        target_found = False
                        frame_count = 0

                    # update the screen to show the latest screen image
                    if display:
                        if display_option == 1:
                            result = image
                        elif display_option == 2:
                            if o_thr:
                                mask = thr_m
                            else:
                                mask = color_m
                        if display_option > 1:
                            result[mask] = [255, 255, 255]
                        if o_sides > 3:
                            min_r = max(0, center[0] - 5)
                            max_r = min(size[1], center[0] + 6)
                            min_c = max(0, center[1] - 5)
                            max_c = min(size[0], center[1] + 6)
                            for i in xrange(min_r, max_r):
                                result[i, center[1]] = [17, 15, 100]
                            for j in range(min_c, max_c):
                                result[center[0], j] = [17, 15, 100]
                            #result[center[0],center[1]] = [17, 15, 100]

                        mapped = surfarray.map_array(screen,
                                                     result).transpose()
                        surfarray.blit_array(screen, mapped)
                        pygame.display.update()
                except:
                    #do nothing
                    print "A thread encountered an error"
                finally:
                    self.stream.seek(0)
                    self.stream.truncate()
                    self.event.clear()
                    with lock:
                        pool.append(self)
Esempio n. 4
0
import numpy as np
import cv2
import utils
import threshold
import matplotlib.pyplot as plt

def get_M_Minv():
    src = np.float32([[(203, 720), (585, 460), (695, 460), (1127, 720)]])
    dst = np.float32([[(320, 720), (320, 0), (960, 0), (960, 720)]])
    M = cv2.getPerspectiveTransform(src, dst)
    Minv = cv2.getPerspectiveTransform(dst,src)
    return M,Minv


if __name__ == '__main__':
    file = 'E:\Code\lane_detect\\test_images\\test2.jpg'
    test1 = cv2.imread(file)
    thresholded = threshold.thresholding(test1)
    M, Minv = get_M_Minv()
    thresholded_wraped = cv2.warpPerspective(thresholded, M, test1.shape[1::-1], flags=cv2.INTER_LINEAR)
    plt.figure(figsize=(10,10))
    plt.subplot(2, 2, 1), plt.imshow(test1)
    plt.subplot(2, 2, 2), plt.imshow(thresholded, cmap='gray')
    plt.subplot(2,2,3),plt.imshow(thresholded_wraped, cmap='gray')
    plt.show()
Esempio n. 5
0
# start the camera
cam.start()

while 1:

    # sleep between every frame
    time.sleep( 0.04 )
    # fetch the camera image
    image = cam.get_image()
    data = surfarray.array3d(image)
    result = np.zeros(data.shape[:3],dtype=np.uint8)
    
    global done, o_sides, o_color, o_thr, frame_count
    if o_thr:
        # thresholding
        thr_m = threshold.thresholding(data)
        # morphology
        mask = morphology.opening(thr_m)
        # find object
        mask,points,o_sides = find_any_moving_object(mask)
    else:
        # color
        color_m = color.find_color(data,o_color)
        # morphology
        color_m = morphology.closing(color_m)
        # find object
        mask,points = find_object(color_m,o_sides)
        print points
    #print points
    # center = aim.find_center(screen_size,points,o_sides)
    # if center_display: