import
1from darkflow.net.build import TFNet 2import cv2 3import numpy as np 4 5options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1} 6tfnet = TFNet(options) 7 8class_names = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 9 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 10 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 11 'sheep', 'sofa', 'train', 'tvmonitor'] 12 13num_classes = len(class_names) 14class_colors = [] 15for i in range(0, num_classes): 16 hue = 255*i/num_classes 17 col = np.zeros((1,1,3)).astype("uint8") 18 col[0][0][0] = hue 19 col[0][0][1] = 128 20 col[0][0][2] = 255 21 cvcol = cv2.cvtColor(col, cv2.COLOR_HSV2BGR) 22 col = (int(cvcol[0][0][0]), int(cvcol[0][0][1]), int(cvcol[0][0][2])) 23 class_colors.append(col) 24 25config = rs.config() 26config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) 27config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) 28 29pipeline = rs.pipeline() 30profile = pipeline.start(config) 31 32while True: 33 frames = pipeline.wait_for_frames() 34 result = tfnet.return_predict(frames) 35 depth_frame = frames.get_depth_frame() 36 if not depth_frame: continue 37 38 for item in result: 39 tlx = item['topleft']['x'] 40 tly = item['topleft']['y'] 41 brx = item['bottomright']['x'] 42 bry = item['bottomright']['y'] 43 label = item['label'] 44 dist_to_center = depth_frame.get_distance(int(tlx+ brx/2), int(tly + bry/2)) 45 dep = item['dist_to_center'] 46 47 if dep > 0.4: 48 49 for i in class_names: 50 if label == i: 51 class_num = class_names.index(i) 52 break 53 54 55 cv2.rectangle(frame, (tlx, tly), (brx, bry), class_colors[class_num], 2) 56 57 58 text = label + " " + ('%.2f' % dep) 59 cv2.rectangle(frame, (tlx, tly - 15), (tlx + 100, tly + 5), class_colors[class_num], -1) 60 cv2.putText(frame, text, (tlx, tly), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,0), 1) 61 62 63 cv2.imshow("Show FLAME Image", frame) 64 65 66 k = cv2.waitKey(10); 67 if k == ord('q'): break; 68 69 pipeline.stop() 70 cv2.destroyAllWindows() 71 72if __name__ == '__main__': 73 main() 74 75```python 76エラー 77``` File "yolodistancetry2.py", line 35, in <module> 78 result = tfnet.return_predict(frames) 79 File "C:\Users\Public\darkflow\darkflow\net\flow.py", line 78, in return_predict 80 'Image is not a np.ndarray' 81AssertionError: Image is not a np.ndarray 82 83```python 84コード 85```darkflow/darkflow/net 86flow.py内76~102行目 87 88def return_predict(self, im): 89 assert isinstance(im, np.ndarray), \ 90 'Image is not a np.ndarray' 91 h, w, _ = im.shape 92 im = self.framework.resize_input(im) 93 this_inp = np.expand_dims(im, 0) 94 feed_dict = {self.inp : this_inp} 95 96 out = self.sess.run(self.out, feed_dict)[0] 97 boxes = self.framework.findboxes(out) 98 threshold = self.FLAGS.threshold 99 boxesInfo = list() 100 for box in boxes: 101 tmpBox = self.framework.process_box(box, h, w, threshold) 102 if tmpBox is None: 103 continue 104 boxesInfo.append({ 105 "label": tmpBox[4], 106 "confidence": tmpBox[6], 107 "topleft": { 108 "x": tmpBox[0], 109 "y": tmpBox[2]}, 110 "bottomright": { 111 "x": tmpBox[1], 112 "y": tmpBox[3]} 113 }) 114 return boxesInfo 115 116のconfidenceの部分を書き換えれば、深度を出力することは可能でしょうか? 117プログラミング初心者のため投げやりになってしまい、申し訳ありません。 118ご教授頂けると幸いです。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/11/13 02:15
2019/11/13 02:58