def fit_lines(lines):
    """
    Args:
        lines: List of hough Lines

    return:
        The right Line and the left line
    
    """
    right_line = None
    left_line = None
    for line in lines:
        for x1, y1, x2, y2 in line:

            l1 = Line([x1, x2], [y1, y2])
            if l1.is_vertical():
                if l1.is_left_line():
                    if not left_line:
                        left_line = l1
                    else:
                        left_line = left_line.fit(l1)
                else:
                    if not right_line:
                        right_line = l1
                    else:
                        right_line = right_line.fit(l1)
            else:
                pass
    return right_line, left_line
 def __init__(self, num_train, num_test):
     self.thresh = 0.001
     line_pts = np.zeros((2,2))
     #don't want line vertical or near vertical
     while abs(line_pts[0][1] - line_pts[1][1]) <= self.thresh:
         line_pts = np.random.uniform(-1,1, (2,2))
     self.line = Line(line_pts[0], line_pts[1])
     num_train = max(1, num_train)
     self.num_train = num_train
     self.train_set = np.random.uniform(-1,1, (num_train, 2))
     self.train_labels = self.line.calc_pts(self.train_set)
     num_test = max(1,num_test)
     self.num_test = num_test
     self.test_set = np.random.uniform(-1,1, (num_test, 2))
     self.test_labels = self.line.calc_pts(self.test_set)
Exemple #3
0
def compute_lines(sol, tidy_path, all_lines):
    with open(tidy_path, 'U') as f:
        renamed_src = f.read()

    #pprint.pprint(sol.getDict())

    #This code renames all variables as placeholders, and saves a mapping
    #from placeholder to original name and abstract variable object
    mappings = {}
    ctr = 0
    for lvar in sol.local_vars:
        placeholder = '___' + str(ctr) + '___'
        try:
            renamed_src = identifier_renamer.rename_identifier(
                renamed_src, lvar.local_name, placeholder)
        except:
            raise RenamerException('Failed to rename ' + str(sol.solnum))

        ctr += 1

        mappings[placeholder] = (lvar.local_name, lvar.abstract_var)
    #print mappings

    #This code breaks solutions down into line objects
    raw_lines = renamed_src.split('\n')
    line_no = 0 #there is no line zero, but it will get incremented at the start of every loop
    for raw_line in raw_lines:
        line_no += 1
        stripped_line = raw_line.strip()

        #ignore empty lines
        if stripped_line == '':
            continue
        indent = len(raw_line) - len(stripped_line)

        blanks = re.findall(r'___\d___', stripped_line)
        #print 'blanks',blanks
        if len(blanks) > 0:
            local_names, abstract_variables = zip(*[mappings[blank] for blank in blanks])
        else:
            local_names = ()
            abstract_variables = ()
        #print local_names, abstract_variables

        template = re.sub(r'___\d___', '___', stripped_line)

        line_values = {}
        for loc_nam in local_names:
            #print 'line_no: ', line_no, [a for (a,b) in sol.trace['__lineNo__'] if b==line_no] #zip(*sol.trace['__lineNo__'])
            #print 'line_no: ', line_no, 'loc_nam', loc_nam, [ [d for (c,d) in sol.trace[loc_nam] if c==a and d!='myNaN' ] for (a,b) in sol.trace['__lineNo__'] if b==line_no]
            line_values[loc_nam] = []
            for loc_val in [ [d for (c,d) in sol.trace[loc_nam] if c==a ] for (a,b) in sol.trace['__lineNo__'] if b==line_no]:
                #if loc_val[0]!='myNaN':
                line_values[loc_nam].append(loc_val[0])
        #print 'line_values',line_values

        step_values = []
        for loc_nam in local_names:
            step_values.append(tuple(line_values[loc_nam]))
        #print 'step_values', step_values
        
        this_line_as_general_line = Line(template, abstract_variables, indent, step_values);
        this_line_in_solution = (this_line_as_general_line, local_names);
        
        sol.lines.append( this_line_in_solution );

        #print 'adding ',this_line_as_general_line,' to all_lines'
        add_to_setlist(this_line_as_general_line,all_lines)
Exemple #4
0
                        np.array([]),
                        minLineLength=min_line_length,
                        maxLineGap=max_line_gap)
print(lines)

# <a id="line"/>

# ### Class Line

# In[48]:

get_ipython().run_line_magic('pinfo', 'Line')

# In[49]:

l1 = Line([318, 361], [425, 395])
l2 = Line([313, 354], [421, 392])

# In[50]:

l1.m, l1.b

# In[51]:

l1.is_vertical()

# In[52]:

l1.is_left_line()

# In[53]:
Exemple #5
0
        message = 'Vehicle is ' + '{:+.2f} m'.format(
            off_center) + ' left of center'
    else:
        message = 'Vehicle is ' + '{:+.2f} m'.format(
            off_center) + ' right of center'

    # adding required text onto the output images
    font = cv2.FONT_HERSHEY_SIMPLEX
    text1 = 'Left line curvature: {:.0f} m'.format(left_curvature)
    cv2.putText(result, text1, (50, 50), font, 1, [255, 255, 255], 2)
    text2 = 'Right line curvature: ' + '{:.0f}'.format(right_curvature) + 'm'
    cv2.putText(result, text2, (50, 100), font, 1, [255, 255, 255], 2)
    cv2.putText(result, message, (50, 150), font, 1, [255, 255, 255], 2)

    return result


# initial variables needed
with open('camera_cal.pickle', 'rb') as input_file:
    mtx, dist = pickle.load(input_file)
M = getTransformMatrices()
Minv = np.linalg.inv(M)
# initializing lines
left_lane = Line()
right_lane = Line()
# video processing and saving
video_output = 'output_video/project_video_output.mp4'
clip1 = VideoFileClip("project_video.mp4")
video_clip = clip1.fl_image(
    process_image)  #NOTE: this function expects color images!!
video_clip.write_videofile(video_output, audio=False)