Beispiel #1
0
def thresholding(img):
    #    x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=55, thresh_max=100)
    #    mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(70, 255))
    #    dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3))
    #    s_thresh = utils.hls_select(img,channel='s',thresh=(160, 255))
    #    s_thresh_2 = utils.hls_select(img,channel='s',thresh=(200, 240))
    #
    #    white_mask = utils.select_white(img)
    #    yellow_mask = utils.select_yellow(img)

    x_thresh = utils.abs_sobel_thresh(img,
                                      orient='x',
                                      thresh_min=10,
                                      thresh_max=230)
    mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(30, 150))
    dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3))
    hls_thresh = utils.hls_select(img, thresh=(180, 255))
    lab_thresh = utils.lab_select(img, thresh=(155, 200))
    luv_thresh = utils.luv_select(img, thresh=(225, 255))
    #Thresholding combination
    threshholded = np.zeros_like(x_thresh)
    threshholded[((x_thresh == 1) & (mag_thresh == 1)) | ((dir_thresh == 1) &
                                                          (hls_thresh == 1)) |
                 (lab_thresh == 1) | (luv_thresh == 1)] = 1

    #    threshholded = np.zeros_like(x_thresh)
    #    threshholded[((x_thresh == 1)) | ((mag_thresh == 1) & (dir_thresh == 1))| (white_mask>0)|(s_thresh == 1) ]=1

    return threshholded
Beispiel #2
0
def thresholding(img):
    #print(img.shape)
    #setting all sorts of thresholds
    #cv2.imshow("orig", img)
    x_thresh = utils.abs_sobel_thresh(img,
                                      orient='x',
                                      thresh_min=10,
                                      thresh_max=230)
    #cv2.imshow("x_thresh",x_thresh*255)
    mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(30, 150))
    #cv2.imshow("mag_thresh",mag_thresh*255)
    dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3))
    #cv2.imshow("dir_thresh",dir_thresh*255)
    hls_thresh = utils.hls_select(img, thresh=(180, 255))
    #cv2.imshow("hls_thresh",hls_thresh*255)
    lab_thresh = utils.lab_select(img, thresh=(155, 200))
    #cv2.imshow("lab_thresh",lab_thresh*255)
    luv_thresh = utils.luv_select(img, thresh=(225, 255))
    #cv2.imshow("luv_thresh",luv_thresh)

    #Thresholding combination
    threshholded = np.zeros_like(x_thresh)
    threshholded[((x_thresh == 1) & (mag_thresh == 1)) | ((dir_thresh == 1) &
                                                          (hls_thresh == 1)) |
                 (lab_thresh == 1) | (luv_thresh == 1)] = 1
    #cv2.imshow("threshholded", threshholded*255)
    #cv2.waitKey(0)
    return threshholded
Beispiel #3
0
def thresholding(img):
    x_thresh = utils.abs_sobel_thresh(img,
                                      orient='x',
                                      thresh_min=10,
                                      thresh_max=230)
    mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(30, 150))
    dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3))
    hls_thresh = utils.hls_select(img, thresh=(180, 255))
    lab_thresh = utils.lab_select(img, thresh=(155, 200))
    luv_thresh = utils.luv_select(img, thresh=(225, 255))
    #Thresholding combination
    threshholded = np.zeros_like(x_thresh)
    threshholded[((x_thresh == 1) & (mag_thresh == 1)) | ((dir_thresh == 1) &
                                                          (hls_thresh == 1)) |
                 (lab_thresh == 1) | (luv_thresh == 1)] = 1

    return threshholded
Beispiel #4
0
trans_on_test=[]
for img in undistorted:
    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)
    trans = cv2.warpPerspective(img, M, img.shape[1::-1], flags=cv2.INTER_LINEAR)
    trans_on_test.append(trans)
    
thresh = []
binary_wrapeds = []
histogram = []
for img in undistorted:
    x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=55, thresh_max=100)
    mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(70, 255))
    dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3))
    s_thresh = utils.hls_select(img,channel='s',thresh=(160, 255))
    s_thresh_2 = utils.hls_select(img,channel='s',thresh=(200, 240))
    
    white_mask = utils.select_white(img)
    yellow_mask = utils.select_yellow(img)
  
    combined = np.zeros_like(mag_thresh)
#    combined[(x_thresh==1) | ((mag_thresh == 1) & (dir_thresh == 1)) | (s_thresh==1)] = 1
#    combined[((mag_thresh == 1) & (dir_thresh == 1))] = 1
    combined[((x_thresh == 1) | (s_thresh == 1)) | ((mag_thresh == 1) & (dir_thresh == 1))| (white_mask>0)|(s_thresh_2 == 1) ]=1
    
    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)
    binary_warped = cv2.warpPerspective(combined, M, img.shape[1::-1], flags=cv2.INTER_LINEAR)
    
plt.figure(figsize=(20, 40))
for i in range(0, (len(undistorted_test_images))):
    plt.subplot(len(undistorted_test_images), 2, 2 * i + 1)
    plt.title('original image')
    plt.imshow(test_imgs2[i])
    plt.subplot(len(undistorted_test_images), 2, 2 * i + 2)
    plt.title('after mag_thresh_method')
    plt.imshow(mag_thresh_method[i], cmap='gray')
plt.savefig('mag_thresh_method.png')

# In[14]:

#hls_thresholding methdods
hls_thresh_method = []
for img in test_imgs2:
    hls_thresh = utils.hls_select(img, channel='s', thresh=(180, 255))
    hls_thresh_method.append(hls_thresh)

plt.figure(figsize=(20, 40))
for i in range(0, (len(undistorted_test_images))):
    plt.subplot(len(undistorted_test_images), 2, 2 * i + 1)
    plt.title('original image')
    plt.imshow(test_imgs2[i])
    plt.subplot(len(undistorted_test_images), 2, 2 * i + 2)
    plt.title('after hls_thresh_method')
    plt.imshow(hls_thresh_method[i], cmap='gray')
plt.savefig('hls_thresh_method.png')

# In[15]:

#dir_thresholding methdods