How to get a top view using open cv?
I am not giving you a complete algorithm here, but since I worked on a similar project, I can give you some hints and tips.

First of all, changing an image taken from one perspective to a different one relatively easy only for planar surfaces. E.g., you have an image of a tall building with a road, and since buildings are usually build vertical in the air and roads tend to be flat on the ground, the planes of the building and the road are perpendicular. Now, if you want to get an image where you are looking straight in to the building (e.g. building plane parallel to image plane), you have two options:


either transform the image so that the building plane is the way you want it, and disregard the rest of the image (road plane will not be correctly transformed)
in addition to transforming the building plane, calculate and perform a transformation on the image part representing the road plane, and somehow stitch them together.


The transformation that allows you to "change" the perspective is called the planar perspective transformation or homography. A homography represents a (mathematical) connection between two images of a same object taken from different perspective, e.g. allows you to calculate the unknown image coordinates of a point in space in one of the images from known image coordinates of the same point in the image with a different perspective.

To be able to calculate a homography, you need to know four pairs of corresponding points. In case of bad camera, you will also have to take care of the camera intrinsic parameters. A very good post on this can be found here.

Now, if you really want to do it properly, you should understand all the terms I used up until now really well before doing anything else. That said, I have been working on a fairly large project, and some parts required to transform images of a road taken from a moving car in to images taken from the bird's perspective, which is what you want to do now. The project was dealing with various road signalization, traffic signs and road markings. Useful references would be:


MASTIF project site with all information related to the project
publication list for the project containing all published articles related to the project
Petar Palašek, Petra Bosilj, Siniša Šegvić: "Detecting and recognizing centerlines as parabolic sections of the steerable filter response" - a paper where I am a coauthor, shows a practical use for what you're trying to achieve, but is also a good source of further references. Has a brief explanation of homography - Section III should be the most interesting.
Ivan Sikirić, Karla Brkić, Siniša Šegvić: Recovering a comprehensive road appearance mosaic from video - a paper detailing how to calculate a rectifying transform used to change the image perspective.


This should give you all the material you need to get what you want to do. Good luck, it took us a while.