yolo、tensorflow(darkflow)で以下のランタイムエラーが出てしまいます。
python、プログラム初心者のため、原因が分かりません。
検討違いな質問かもしれませんが、ご教授お願いします。
<<<<エラー>>>>
RuntimeError: out of range value for argument "y"
(RuntimeError: out of range value for argument "x"となる場合あり)
該当箇所 meters = depth_frame.get_distance(tlx+int(brx-tlx/2), bry+int(tly-bry/2))
python
1import pyrealsense2 as rs 2from darkflow.net.build import TFNet 3import cv2 4import numpy as np 5 6options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1} 7tfnet = TFNet(options) 8 9class_names = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 10'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 11'dog', 'horse', 'motorbike', 'person', 'pottedplant', 12'sheep', 'sofa', 'train', 'tvmonitor'] 13 14num_classes = len(class_names) 15class_colors = [] 16for i in range(0, num_classes): 17hue = 255*i/num_classes 18col = np.zeros((1,1,3)).astype("uint8") 19col[0][0][0] = hue 20col[0][0][1] = 128 21col[0][0][2] = 255 22cvcol = cv2.cvtColor(col, cv2.COLOR_HSV2BGR) 23col = (int(cvcol[0][0][0]), int(cvcol[0][0][1]), int(cvcol[0][0][2])) 24class_colors.append(col) 25 26config = rs.config() 27config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) 28config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) 29 30pipeline = rs.pipeline() 31profile = pipeline.start(config) 32 33try: 34while True: 35frames = pipeline.wait_for_frames() 36depth_frame = frames.get_depth_frame() 37color_frame = frames.get_color_frame() 38if not depth_frame or not color_frame: 39continue 40 41depth_image = np.asanyarray(depth_frame.get_data()) 42color_image = np.asanyarray(color_frame.get_data()) 43 44result = tfnet.return_predict(color_image) 45 46for item in result: 47tlx = item['topleft']['x'] 48tly = item['topleft']['y'] 49brx = item['bottomright']['x'] 50bry = item['bottomright']['y'] 51label = item['label'] 52meters = depth_frame.get_distance(tlx+int(brx-tlx/2), bry+int(tly-bry/2)) 53dep = item['confidence'] 54 55if dep > 0.4: 56 57for i in class_names: 58if label == i: 59class_num = class_names.index(i) 60break 61 62box_color = (255, 128, 0) 63cv2.rectangle(color_image, (tlx, tly), (brx, bry), box_color, 2) 64 65text = label + " " + ('%.2f' % meters) 66cv2.rectangle(color_image, (tlx, tly - 15), (tlx + 100, tly + 5), box_color, -1) 67cv2.putText(color_image, text, (tlx, tly), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,0), 1) 68 69cv2.imshow("Show FLAME Image", color_image) 70 71k = cv2.waitKey(10); 72if k == ord('q'): break; 73 74finally: 75pipeline.stop() 76cv2.destroyAllWindows() 77 78
回答1件
あなたの回答
tips
プレビュー