At present, the level of urbanization in China has exceeded 50% and the number of car ownership has reached 140 million. The consequent problem of traffic congestion has become increasingly prominent. It is increasingly important that how to get the basic vehicle information in real time and accurately so that the traffic department can timely manage the vehicles of the specific road sections and intersections. At present, some related methods and algorithms have high real-time performance, but the accuracy is not high or the contrary. Accordingly, this paper proposes a method of automatic vehicle detection based on YOLOV2 framework which has both real-time and accuracy. The method improves the YOLOv2 framework model, optimizes the important parameters in the model, expands the grid size, and improves the number and sizes of anchors in the model, which can automatically learn the vehicle features and realize real-time and high-precision vehicle automatic detection and vehicle class identification. The evaluation on home-made dataset shows that compared with YOLOv2 and Faster RCNN, the accuracy rate is raised to 91.80 %, the recall rate to 63.86 %.