def store_data(shape):
    s_LTop2, s_RTop2 = [shape[0] / 2 - 24, 5], [shape[0] / 2 + 24, 5]
    s_LBot2, s_RBot2 = [110, shape[1]], [shape[0] - 110, shape[1]]

    src = np.float32([s_LBot2, s_LTop2, s_RTop2, s_RBot2])
    dst = np.float32([(170, 720), (170, 0), (550, 0), (550, 720)])

    mtx, dist = calibration.calib()

    f = open('temp.pkl', 'wb')
    pickle.dump(mtx, f)
    pickle.dump(dist, f)
    pickle.dump(src, f)
    pickle.dump(dst, f)

    f.close()

    return mtx, dist, src, dst
示例#2
0
import matplotlib.image as mpimg
from calibration import calib, undistort
from threshold import gradient_combine, hls_combine, comb_result
from finding_lines import Line, warp_image, find_LR_lines, draw_lane, print_road_status, print_road_map
from skimage import exposure
input_type = 'video' #'video' # 'image'
input_name = 'project_video.mp4' #'test_images/straight_lines1.jpg' # 'challenge_video.mp4'

left_line = Line()
right_line = Line()

th_sobelx, th_sobely, th_mag, th_dir = (35, 100), (30, 255), (30, 255), (0.7, 1.3)
th_h, th_l, th_s = (10, 100), (0, 60), (85, 255)

# camera matrix & distortion coefficient
mtx, dist = calib()

if __name__ == '__main__':

    if input_type == 'image':
        img = cv2.imread(input_name)
        undist_img = undistort(img, mtx, dist)
        undist_img = cv2.resize(undist_img, None, fx=1 / 2, fy=1 / 2, interpolation=cv2.INTER_AREA)
        rows, cols = undist_img.shape[:2]

        combined_gradient = gradient_combine(undist_img, th_sobelx, th_sobely, th_mag, th_dir)
        combined_hls = hls_combine(undist_img, th_h, th_l, th_s)
        combined_result = comb_result(combined_gradient, combined_hls)

        c_rows, c_cols = combined_result.shape[:2]
        s_LTop2, s_RTop2 = [c_cols / 2 - 24, 5], [c_cols / 2 + 24, 5]
    def __init__(self,
                 image,
                 thesh_sobelx_X=35,
                 thesh_sobelx_Y=100,
                 thesh_sobely_X=30,
                 thesh_sobely_Y=255,
                 thesh_mag_X=30,
                 thesh_mag_Y=255,
                 thesh_dir_X=0.7,
                 thesh_dir_Y=1.3,
                 th_h_X=10,
                 th_h_Y=100,
                 th_l_X=0,
                 th_l_Y=60,
                 th_s_X=85,
                 th_s_Y=255):

        self.left_line = Line()
        self.right_line = Line()

        self.mtx, self.dist = calib()

        self.image = image

        # HLS thresh
        self.thesh_h_X = th_h_X
        self.thesh_h_Y = th_h_Y
        self.thesh_l_X = th_l_X
        self.thesh_l_Y = th_l_Y
        self.thesh_s_X = th_s_X
        self.thesh_s_Y = th_s_Y

        # Sobel and mag, dir thresh
        self.thesh_sobelx_X = thesh_sobelx_X
        self.thesh_sobelx_Y = thesh_sobelx_Y
        self.thesh_sobely_X = thesh_sobely_X
        self.thesh_sobely_Y = thesh_sobely_Y
        self.thesh_mag_X = thesh_mag_X
        self.thesh_mag_Y = thesh_mag_Y
        self.thesh_dir_X = thesh_dir_X
        self.thesh_dir_Y = thesh_dir_Y

        def thesh_sobelx_X(self):
            return self.thesh_sobelx_X

        def thesh_sobelx_Y(self):
            return self.thesh_sobelx_Y

        def thesh_sobely_X(self):
            return self.thesh_sobely_X

        def thesh_sobely_Y(self):
            return self.thesh_sobely_Y

        def thesh_mag_X(self):
            return self.thesh_mag_X

        def onchangethesh_h_X(pos):
            self.thesh_h_X = pos
            self.renders()

        def onchangethesh_h_Y(pos):
            self.thesh_h_Y = pos
            self.renders()

        def onchangethesh_l_X(pos):
            self.thesh_l_X = pos
            self.renders()

        def onchangethesh_l_Y(pos):
            self.thesh_l_Y = pos
            self.renders()

        def onchangethesh_s_X(pos):
            self.thesh_s_X = pos
            self.renders()

        def onchangethesh_s_Y(pos):
            self.thesh_s_Y = pos
            self.renders()

        def onchangethesh_sobelx_X(pos):
            self.thesh_sobelx_X = pos
            self.renders()

        def onchangethesh_sobelx_Y(pos):
            self.thesh_sobelx_Y = pos
            self.renders()

        def onchangethesh_sobely_X(pos):
            self.thesh_sobely_X = pos
            self.renders()

        def onchangethesh_sobely_Y(pos):
            self.thesh_sobely_Y = pos
            self.renders()

        def onchangethesh_mag_X(pos):
            self.thesh_mag_X = pos
            self.renders()

        def onchangethesh_mag_Y(pos):
            self.thesh_mag_Y = pos
            self.renders()

        def onchangethesh_dir_X(pos):
            self.thesh_mag_X = pos
            self.renders()

        def onchangethesh_dir_Y(pos):
            self.thesh_mag_Y = pos
            self.renders()

        cv2.namedWindow('Find_threshold_window')

        cv2.createTrackbar('thesh_h_X', 'Find_threshold_window',
                           self.thesh_h_X, 255, onchangethesh_h_X)
        cv2.createTrackbar('thesh_h_Y', 'Find_threshold_window',
                           self.thesh_h_Y, 255, onchangethesh_h_Y)
        cv2.createTrackbar('thesh_l_X', 'Find_threshold_window',
                           self.thesh_l_X, 255, onchangethesh_l_X)
        cv2.createTrackbar('thesh_l_Y', 'Find_threshold_window',
                           self.thesh_l_Y, 255, onchangethesh_l_Y)
        cv2.createTrackbar('thesh_s_X', 'Find_threshold_window',
                           self.thesh_s_X, 255, onchangethesh_s_X)
        cv2.createTrackbar('thesh_s_Y', 'Find_threshold_window',
                           self.thesh_s_Y, 255, onchangethesh_s_Y)

        cv2.createTrackbar('thesh_sobelx_X', 'Find_threshold_window',
                           self.thesh_sobelx_X, 255, onchangethesh_sobelx_X)
        cv2.createTrackbar('thesh_sobelx_Y', 'Find_threshold_window',
                           self.thesh_sobelx_X, 255, onchangethesh_sobelx_Y)
        cv2.createTrackbar('thesh_sobely_X', 'Find_threshold_window',
                           self.thesh_sobely_X, 255, onchangethesh_sobely_X)
        cv2.createTrackbar('thesh_sobely_Y', 'Find_threshold_window',
                           self.thesh_sobely_Y, 255, onchangethesh_sobely_Y)
        cv2.createTrackbar('thesh_mag_Y', 'Find_threshold_window',
                           self.thesh_mag_Y, 255, onchangethesh_mag_Y)

        self.renders()

        cv2.waitKey(0)

        cv2.destroyWindow('Find_threshold_window')
示例#4
0
import os
from calibration import calib
import tkinter


def directory():
    window = tkinter.Tk()  # 최상위 레벨 윈도우창 생성

    window.title("Images Folder's Directory")
    window.geometry("720x400+100+100")
    window.resizable(1, 1)
    widget = tkinter.Label(
        window,
        text="Convert Image가 있는 폴더 경로를 입력해주세요.<버튼을 안만듦.. 입력 후 엔터 + 창 닫기>")
    widget.pack()

    def command(event):
        global dir
        dir = entry.get()  #경로 문자열 받아오기

    entry = tkinter.Entry(window)
    entry.bind("<Return>", command)  # call command
    entry.pack()
    window.mainloop()  # window창이 종료될때 까지 실행


directory()
ROOT_DIR = dir  # dir경로 받기
calib(ROOT_DIR)