You can follow the steps in:
http://www.laganiere.name/opencvCook...hap1s1_2.shtml

These are the few points I noted when I installed openCV, it might help you:
  • In Step 7: If you get error saying cannot find CMAKE_MAKE _PROGRAM, either add path to mingw32-make.exe to the environment PATH variable or click "Advanced" and configure the path there.
  • Before configuring CMake3.2.3 WITH_IPP should be OFF. This is because mingw uses runTmChk which is a msvc library (Known bug).
  • Go to ..\openCV\sources -> OpenCVCompilerOptions.cmake -> comment out the line "add_extra_compiler_option(-Werror=non-virtualdtor).
  • Step 9: Add ..\openCV\build\install\x86\mingw\bin to PATH.


Good luck

Regards
Vikram