title: Bounding box challenges while applying yolo project on videos (from coursera)
body: <p>i tried to process a video file instead of the image, at the end of the car detection program, from the coursera course on CNN. Unfortunately the bounding boxes are not in sync with the actual car locations and are offset by a few points on both X and Y axes... and seems to me that am messing up somewhere with the frame_width and height when i freeze a 'currentFrame' and feed it to the pre-processing, if at all. any thoughts on what could be wrong here? Didnt want to paste the entire project code so am pasting just the part where  am replacing the predict function with code to iterate to frames of a video.</p>
  <pre><code>import cv2 
  from tqdm import tqdm
  import imghdr 
  from numpy import expand_dims
  from keras.preprocessing.image import img_to_array
  
  video_out = (&quot;nb_images/out1.mp4&quot;)
  video_reader = cv2.VideoCapture(&quot;nb_images/road_video_trim2.mp4&quot;)
  nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT))
  frame_h = int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT))
  frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))        
  video_writer = cv2.VideoWriter(video_out,
                         cv2.VideoWriter_fourcc(*'MPEG'), 
                         50.0, 
                         (frame_w, frame_h))
  
  batch_size  = 1
  images      = []
  start_point = 0 #%
  show_window = False
  for i in tqdm(range(nb_frames)):
      _, image = video_reader.read()
      #blob = cv2.dnn.blobFromImage(image, 1 / 255.0, (frame_w, frame_h), swapRB=True, crop=False)    
      cv2.imwrite(&quot;currentFrame.jpg&quot;, image)
      image, image_data = preprocess_image(&quot;currentFrame.jpg&quot;, model_image_size = (608, 608))
      out_scores, out_boxes, out_classes = sess.run([scores, boxes, classes], feed_dict={yolo_model.input:image_data, K.learning_phase():0})
  
      #out_scores, out_boxes, out_classes, output_image = predict2(sess,&quot;currentFrame.jpg&quot;)
      colors = generate_colors(class_names)
      #draw_boxes(img, out_scores, out_boxes, out_classes, class_names, colors)
  
      draw_boxes(image, out_scores, out_boxes, out_classes, class_names, colors)
      #video_writer.write(images[i]) 
      imshow(image)
      video_writer.write(np.uint8(image))
  
  images = []
  if show_window: cv2.destroyAllWindows()
  video_reader.release()
  video_writer.release()       
  #else: # do detection on an image or a set of images
  image_paths = []
  </code></pre>
  <p>So, i figured what was going wrong here  ... this code snippet that does the initialization has a different image shape going. First i changed that.</p>
  <pre><code>class_names = read_classes(&quot;model_data/coco_classes.txt&quot;)
  anchors = read_anchors(&quot;model_data/yolo_anchors.txt&quot;)
  #image_shape = (720., 1280.)
  image_shape=(608., 608.)
  </code></pre>
  <p>Then the yolo calls ...</p>
  <pre><code>yolo_outputs = yolo_head(yolo_model.output, anchors, len(class_names))
  scores, boxes, classes = yolo_eval(yolo_outputs, image_shape)
  </code></pre>
  <p>And now - within my code i made these small changes ...</p>
  <pre><code>for i in tqdm(range(nb_frames)):
      _, image = video_reader.read()
      #blob = cv2.dnn.blobFromImage(image, 1 / 255.0, (frame_w, frame_h), swapRB=True, crop=False)    
      image = cv2.resize(image, (608, 608))
      cv2.imwrite(&quot;currentFrame.jpg&quot;, image)
      image, image_data = preprocess_image(&quot;currentFrame.jpg&quot;, model_image_size = (608, 608))
      out_scores, out_boxes, out_classes = sess.run([scores, boxes, classes], feed_dict={yolo_model.input:image_data, K.learning_phase():0})
      colors = generate_colors(class_names)    
      draw_boxes(image, out_scores, out_boxes, out_classes, class_names, colors)
      image = cv2.resize(np.array(image), (frame_w,frame_h))
      video_writer.write(np.uint8(image))
      imshow(image)
  </code></pre>
  <p>I think the initialization of the shape to 608,608 and the above resize is what made it work. The final frame came out like this.
  <a href="https://i.stack.imgur.com/mohaZ.jpg" rel="nofollow noreferrer">finalFrame</a></p>