2017-11-06 10 views
-5

このエラーが発生します。TypeErrorの取得:スライスインデックスは整数でなければなりません

Traceback (most recent call last): 
    File "C:\Users\rohit\Desktop\Python\driving-lane-departure-warning-master\main.py", line 19, in <module> 
    img_aug = process_frame(img) 
    File "C:\Users\rohit\Desktop\Python\driving-lane-departure-warning-master\lane.py", line 612, in process_frame 
    output = create_output_frame(offcenter, pts, img_undist_, fps, curvature, curve_direction, binary_sub) 
    File "C:\Users\rohit\Desktop\Python\driving-lane-departure-warning-master\lane.py", line 484, in create_output_frame 
    whole_frame[220+h/2:220+2*h/2, 20:20+w/2, :] = undist_birdview 
TypeError: slice indices must be integers or None or have an __index__ method 

誰でもこのエラーを取り除く方法を教えていただけますか? Pythonのバージョンを使用している

def create_output_frame(offcenter, pts, undist_ori, fps, curvature, curve_direction, binary_sub, threshold=0.6): 
    """ 
    :param offcenter: 
    :param pts: 
    :param undist_ori: 
    :param fps: 
    :param threshold: 
    :return: 
    """ 

    undist_ori = cv2.resize(undist_ori, (0,0), fx=1/output_frame_scale, fy=1/output_frame_scale) 
    w = undist_ori.shape[1] 
    h = undist_ori.shape[0] 

    undist_birdview = warper(cv2.resize(undist_ori, (0,0), fx=1/2, fy=1/2), M_b) 

    color_warp = np.zeros_like(undist_ori).astype(np.uint8) 

    # create a frame to hold every image 
    whole_frame = np.zeros((h*3,w*3, 3), dtype=np.uint8) 


    if abs(offcenter) > threshold: # car is offcenter more than 0.6 m 
     # Draw Red lane 
     cv2.fillPoly(color_warp, np.int_([pts]), (255, 0, 0)) # red 
    else: # Draw Green lane 
     cv2.fillPoly(color_warp, np.int_([pts]), (0,255, 0)) # green 

    newwarp = cv2.warpPerspective(color_warp, M_inv, (int(frame_width/input_scale), int(frame_height/input_scale))) 

    # Combine the result with the original image # result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0) 

    newwarp_ = cv2.resize(newwarp,None, fx=input_scale/output_frame_scale, fy=input_scale/output_frame_scale, interpolation = cv2.INTER_LINEAR) 

    output = cv2.addWeighted(undist_ori, 1, newwarp_, 0.3, 0) 

    ############## generate the combined output frame only for visualization purpose ################ 
    whole_frame[40:40+h, 20:20+w, :] = undist_ori 
    whole_frame[40:40+h, 60+w:60+2*w, :] = output 
    whole_frame[220+h/2:220+2*h/2, 20:20+w/2, :] = undist_birdview 
    whole_frame[220+h/2:220+2*h/2, 40+w/2:40+w, 0] = cv2.resize((binary_sub*255).astype(np.uint8), (0,0), fx=1/2, fy=1/2) 
    whole_frame[220+h/2:220+2*h/2, 40+w/2:40+w, 1] = cv2.resize((binary_sub*255).astype(np.uint8), (0,0), fx=1/2, fy=1/2) 
    whole_frame[220+h/2:220+2*h/2, 40+w/2:40+w, 2] = cv2.resize((binary_sub*255).astype(np.uint8), (0,0), fx=1/2, fy=1/2) 

    font = cv2.FONT_HERSHEY_SIMPLEX 
    if offcenter >= 0: 
     offset = offcenter 
     direction = 'Right' 
    elif offcenter < 0: 
     offset = -offcenter 
     direction = 'Left' 

    info_road = "Road Status" 
    info_lane = "Lane info: {0}".format(curve_direction) 
    info_cur = "Curvature {:6.1f} m".format(curvature) 
    info_offset = "Off center: {0} {1:3.1f}m".format(direction, offset) 
    info_framerate = "{0:4.1f} fps".format(fps) 
    info_warning = "Warning: offcenter > 0.6m (use higher threshold in real life)" 

    cv2.putText(whole_frame, "Departure Warning System with a Monocular Camera", (23,25), font, 0.8, (255,255,0), 1, cv2.LINE_AA) 
    cv2.putText(whole_frame, "Origin", (22,70), font, 0.6, (255,255,0), 1, cv2.LINE_AA) 
    cv2.putText(whole_frame, "Augmented", (40+w+25,70), font, 0.6, (255,255,0), 1, cv2.LINE_AA) 
    cv2.putText(whole_frame, "Bird's View", (22+30,70+35+h), font, 0.6, (255,255,0), 1, cv2.LINE_AA) 
    cv2.putText(whole_frame, "Lanes", (22+225,70+35+h), font, 0.6, (255,255,0), 1, cv2.LINE_AA) 
    cv2.putText(whole_frame, info_road, (40+w+50,70+35+h), font, 0.8, (255,255,0), 1,cv2.LINE_AA) 
    cv2.putText(whole_frame, info_warning, (35+w,60+h), font, 0.4, (255,255,0), 1,cv2.LINE_AA) 
    cv2.putText(whole_frame, info_lane, (40+w+50,70+35+40+h), font, 0.8, (255,255,0), 1,cv2.LINE_AA) 
    cv2.putText(whole_frame, info_cur, (40+w+50,70+35+80+h), font, 0.8, (255,255,0), 1,cv2.LINE_AA) 
    cv2.putText(whole_frame, info_offset, (40+w+50,70+35+120+h), font, 0.8, (255,255,0), 1,cv2.LINE_AA) 
    cv2.putText(whole_frame, info_framerate, (40+w+250,70), font, 0.6, (255,255,0), 1,cv2.LINE_AA) 

    return whole_frame 
+2

あなたは[MVCE](https://stackoverflow.com/help/mcve)を提供することはできますか? – jhpratt

答えて

0

:ここ

は、コードの一部ですか? 問題が2で除算されている可能性があります。 「h/2」と「w/2」をそれぞれ「h // 2」と「w // 2」に置き換えてください。

+0

あなたの時間を無駄にして申し訳ありません。私はこの問題を解決しました。それは部門の問題によるものでした。 –

0

これは、スライスインデックスが浮動小数点型または2重型の場合、またはスライスの構文が正しくない場合に発生します。スライスのシンタックスまたはスライスインデックスのタイプを確認してください。

可能性のあるエラーの例は:

a = [1,2,3,4] 
a = a[1.2:] 
TypeError: slice indices must be integers or None or have an __index__ method 

a = a[1,2:] 
TypeError: slice indices must be integers or None or have an __index__ method 

a = a[1:2,3:4,:] 
TypeError: slice indices must be integers or None or have an __index__ method 
関連する問題