xingwangsfu / caffe-yolo

YOLO (Real-Time Object Detection) in caffe
521 stars 337 forks source link

Run yolo_main.py on video #11

Open jshankar opened 7 years ago

jshankar commented 7 years ago

I modified yolo_main.py to work on video instead of image as follows . It doesn't however work.Is there anything else I need to change ?

net = caffe.Net(model_filename, weight_filename, caffe.TEST) transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2,0,1)) transformer.set_channel_swap('data', (2,1,0)) cap = cv2.VideoCapture(video_filename);

ret, img = cap.read(); while(ret): inputs = img out = net.forward_all(data=np.asarray([transformer.preprocess('data', inputs)])) print out.iteritems() img_cv = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) results = interpret_output(out['result'][0], img.shape[1], img.shape[0]) show_results(img_cv,results, img.shape[1], img.shape[0]) cv2.waitKey(10000) ret, img = cap.read() end = datetime.now()

Banus commented 7 years ago

YOLO expects inputs in the range [0,1] while the OpenCV img has range [0, 255]. The function caffe.io.load_image takes already care of that by calling skimage.img_as_float. You need simply to rescale the OpenCV image by adding the following option to the transformer:

transformer.set_raw_scale('data', 1.0 / 255.0)