OverflowError:使用cv2.line()

时间:2019-05-11 06:42:47

标签: python opencv

正在遵循有关车道检测的教程。以下代码的工作时间约为10秒,然后窗口崩溃并显示此错误:

OverflowError: Python int too large to convert to C long at` 

File "lanes-vid.py", line 94, in <module>
    line_image=display_lines(frame,averaged_lines)
  File "lanes-vid.py", line 48, in display_lines
    cv2.line(line_image, (x1,y1), (x2,y2), (255,0,0), 10)

它可以正常工作,可以稍后在视频中崩溃,但是我在cropped_image和HoughTransform上进行了一些设置调整。 现在它崩溃太早了。 (理想情况下,它不会崩溃)

def average_slope_intercept(image, lines):

    left_fit=[]
    right_fit=[]
    for line in lines:
        x1, y1, x2, y2 = line.reshape(4)
        parameters = np.polyfit((x1, x2),(y1,y2),1)
        slope=parameters[0]
        intercept=parameters[1]
        if slope < 0:
            left_fit.append((slope, intercept))
        else:
            right_fit.append((slope, intercept))
    left_fit_average=np.average(left_fit, axis=0)
    right_fit_average=np.average(right_fit, axis=0)
    #print(left_fit_average,'left')
    #print(right_fit_average, 'right')
    left_line=make_coordinates(image, left_fit_average)
    right_line=make_coordinates(image, right_fit_average)

    return np.array([left_line,right_line])


def display_lines(image, lines):

    line_image=np.zeros_like(image)
    if lines is not None:
        for x1,y1,x2,y2 in lines:


            cv2.line(line_image, (x1,y1), (x2,y2), (255,0,0), 10)
    return line_image


def region_of_interest(image):


    height = image.shape[0]
    polygons=np.array([
    [(200.342,911.317),(1590.17,905.69),(1012.29,615.958),(913.8,608.82),(800,618.812)]])
    mask=np.zeros_like(image)
    cv2.fillPoly(mask, np.int32(polygons), 255)
    masked_image=cv2.bitwise_and(image, mask)
    return masked_image


cap=cv2.VideoCapture("video.mp4")

while(cap.isOpened()):

    _, frame=cap.read()
    canny_image = canny(frame)
    cropped_image=region_of_interest(canny_image)

    lines= cv2.HoughLinesP(cropped_image,1,np.pi/180, 50, np.array([]),minLineLength=15,maxLineGap=20)
    averaged_lines=average_slope_intercept(frame, lines)
    line_image=display_lines(frame,averaged_lines)
    combo_image=cv2.addWeighted(frame, 0.7, line_image, 1,1)
    cv2.imshow('result',combo_image)
    cv2.waitKey(2)

0 个答案:

没有答案