Create a new C++ Win32 Console Application in visual studio.
Set the project as Debug or Release mode.
Set your platform as x86 or x64 (Configuration Manager).
Configure project properties: (The following steps will depend on the selection of build mode, platform, vs version and opencv version.
Configuration Properties -> VC++ Directories:
Executable Directories: add the directory to dll files - OpenCVDir\build(PLATFORM, e.g. x64)(VISUAL STUDIO VERSION, e.g. vc12)\bin. This can also be done by adding the directory to Path, the environment variable.
Include Directories: add the directory to include files - OpenCVDir\build\include
Library Directories: add the directory to library files - OpenCVDir\build(PLATFORM, e.g. x64)(VISUAL STUDIO VERSION, e.g. vc12)\lib
Linker -> General: Use Library Dependency Inputs = Yes
Linker -> Input -> Additional Dependencies: add lib files. Format: NAME+VERSION+(d).lib, d means debug mode. Release mode should use those without d.