Generally, you can use videocapture captrefrnc (0) to enable opencv.
After the system is reinstalled, to avoid installing a huge Visual Studio, we changed it to codeblocks. In addition, opencv was compiled using cmake + codeblocks, however, opencv compiled by default cannot enable the camera of the laptop. After trying other solutions, I thought about how to use k-lite codec pack and avisynth to write AVS scripts to solve the decoder. I used K-lite codec pack + AVS to open the camera.
If you also encounter the problem that opencv cannot open the camera and cannot solve it, try this solution.
Preparations:
1: Install the K-lite codec pack and select the full version to install it. In this way, you can obtain the graphstudionext
Http://www.codecguide.com/download_kl.htm
2: Install avisynth
Http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/
3: Install avisynth-as-DirectShow-capture.
Https://github.com/rdp-org/avisynth-as-directshow-capture
After the installation is complete, open graphstudionext
Enter the program, press Ctrl + F, or click graph-> Insert filter.
Find your camera. In general, there will be a cam keyword, my name is intergrated webcam, select it, and click Insert
Select your cam, and then use file-> Save As graph to save the. GRF file. For example, mine is E: \ cam. AVS.
The next step is to write an AVS script to open the GRF file.
Open notepad and enter directshowsource ("E: \ cam. GRF", audio = false, framecount = 1000000, FPS = 10)
Save as filename. AVS
Then, Use Media Player classic to open the file and test whether the file is successfully opened. If you can use Media Player classic to open the camera, the file is successfully opened.
After that, you only need to open the AVS file in opencv like opening a video file:
Videocapture captrefrnc ("E: \ cam. AVS ");
Opencv camera cannot be opened alternative solution