Kindly refer to the below steps:
1. Install and download the Visual Studio 2013, CMake, opencv, and opencv_contrib.
2. Create a folder as opencv-3.1.0-dev and in this directory create other two folders one called to build and the other called sources. The paths will look like this:
opencv-3.1.0-dev\build and opencv-3.1.0-dev\sources.
3. Then unzip opencv-master.zip and opencv_contrib-master.zip
4. In the sources directory created in step 3, paste opencv and opencv_contrib directories
5. Then open CMake and provide two paths, one for the build directory and the other for the sources directory
6. Press configure, a lot of lines highlighted in red will appear. Also, select the correct bit version based on your needs, same procedure works for 32-bit and 64-bit
7. Select whatever you want to create, and also provide the path of the non-free modules.
8. After that press the configure button again and new lines will be highlighted in red.
9. Make sure that you do not select BUILD_opencv_contrib_world before pressing generate
10. The last step with CMake is to press generate.
11. Make sure generating is done before continuing. After that, open the build that was empty, and you will find a bunch of files. The most important file is OpenCV.sln. Right-click on the .sln file and start it with the visual studio 2013 that is used in CMake.
12. Create the 3 files with the order. Change the mode into Release. These steps take some what around 10 to 15 minutes.
13. then, copy all the .dll files that are present at opencv-3.1.0-dev\build\bin\Release directory and the cv2.pyd and paste them in the site-packages directory in Pyhton27\Lib\site-packages.
14. To verify the build open Python and execute import cv2. If there are no errors then, execute cv2.__version__, and you should get 3.1.0-dev.
Sign up for this Intellipaat's Python Course fast, to Learn Python concepts in detail and get certified.