Ejemplo n.º 1
0
 def OnAccept(self, e):
     w = warp.warper()
     config = {"i_path": self.morphed_path, "o_path": "/home/tom/TEST/", "warp_frames": 50, "o_type": ".jpg"}
     w.UpdateConfig(config)
     pairs = len(self.morphed_path) - 1
     if pairs > 5:
         w.Run_parallel(num_proc=3)
     elif pairs > 3:
         w.Run_parallel(num_proc=2)
     else:
         w.Run()
Ejemplo n.º 2
0
def process(image):
    global left_line, right_line, detected

    undist = cal_undistort(image, objp, imgp)

    thresh_s = (170, 255)
    thresh_sx = (50, 255)
    thresh_sy = (50, 255)
    thresh_mag = (50, 255)
    thresh_gdir = (0.7, 1.3)
    com = cal_thresh_img(undist, thresh_s, thresh_sx, thresh_sy, thresh_mag, thresh_gdir)
    warped = warper(com, src, dst)

    if not detected:
        fit = sliding_window_search(warped)
        if fit != None:
            left_line.add_fit(fit[0])
            right_line.add_fit(fit[1])
            detected = True
    else:
        fit = sliding_window_search_with_known(warped, left_line.get_fit(), right_line.get_fit())
        if fit != None:
            left_line.add_fit(fit[0])
            right_line.add_fit(fit[1])
        else:
            detected = False

    left_fit, right_fit = left_line.get_fit(), right_line.get_fit()
    res = vis(undist, warped, left_fit, right_fit, src, dst)

    left_c, right_c = cal_curvature(warped, left_fit, right_fit)
    offset = cal_offset(undist, left_fit, right_fit)

    avg_c = (left_c + right_c)/2
    label_c = 'Radius of curvature: %.2f m' % (avg_c)
    offset_c = 'Offset from the center of lane: %.2f m' % (offset)

    cv2.putText(res, label_c, (20, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)
    cv2.putText(res, offset_c, (20, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)

    cv2.imwrite('./res.jpg', res)

    return res
Ejemplo n.º 3
0
def output_each_step():
    images = glob.glob('./test_images/*.jpg')
    objp, imgp = cal_calib_points('./camera_cal/calibration*.jpg')
    output_path = './output_images/'

    for img in images:
        print('Processing' + img)
        img_name = img.split('/')[-1]
        image = cv2.imread(img)

        undist = cal_undistort(image, objp, imgp)
        cv2.imwrite(output_path+'undist_'+img_name, undist)

        thresh_s = (170, 255)
        thresh_sx = (30, 255)
        thresh_sy = (30, 255)
        thresh_mag = (50, 255)
        thresh_gdir = (0.7, 1.3)
        com = cal_thresh_img(undist, thresh_s, thresh_sx, thresh_sy, thresh_mag, thresh_gdir)
        cv2.imwrite(output_path+'thresh_'+img_name, com*255)

        src = np.float32([[200, 720], [1100, 720], [595, 450], [685, 450]])
        dst = np.float32([[300, 720], [980, 720], [300, 0], [980, 0]])
        warped = warper(com, src, dst)
        cv2.imwrite(output_path+'warped_'+img_name, warped*255)

        fit_name = output_path+'fit_'+img_name
        left_fit, right_fit = sliding_window_search(warped, vis=True, file_name=fit_name)

        out_img = np.dstack((warped, warped, warped))*255
        ploty = np.linspace(0, warped.shape[0]-1, warped.shape[0] )
        left_fitx = left_fit[0]*ploty**2 + left_fit[1]*ploty + left_fit[2]
        right_fitx = right_fit[0]*ploty**2 + right_fit[1]*ploty + right_fit[2]

        res = vis(undist, warped, left_fit, right_fit, src, dst)
        cv2.imwrite(output_path+'final_'+img_name,res)
Ejemplo n.º 4
0
#images 9979 --> 9971
from_pt = ((816,573),(1421,545),(1081,1054),(1188,441))   # scaled x 2, rotated 45 degrees and translated
to_pt = ((850,575),(1420,546),(1103,1030),(1200,443)) # a 1x1 rectangle




#from_pt = ((1,1),(1,2),(2,2),(2,1)) # a 1x1 rectangle
#to_pt = ((4,4),(6,6),(8,4),(6,2))   # scaled x 2, rotated 45 degrees and translated


tr=transform.Affine_Fit(from_pt,to_pt)

t= tr.Get_Trafo()
print tr.To_Str()
T =  (t[0][3],t[1][3],t[2][3], t[0][4],t[1][4],t[2][4])
#T =  (t[0][3],t[0][4],t[1][3], t[1][4],t[2][4],t[2][4])
im1=Image.open("/media/Data/MEDIA/photography/2012-08-30-Berlin/100CANON/01_2000.JPG")
im2=Image.open("/media/Data/MEDIA/photography/2012-08-30-Berlin/100CANON/02_2000.JPG")
im3 = im2.transform(im1.size,Image.AFFINE,T)
im3.save("transformed.jpg")
im1.save("original.jpg")

warper = warp.warper()
t0=time.time()
warper.Run_parallel()
#warper.Run()
t1=time.time()
print t1-t0