How to modify a .cpp file in a Visual Studio project generated from CMake that contains the full OpenCV source code


I built OpenCV (with the examples included) from source by first using CMake to generate a Visual Studio Project.

I’d like to be able to modify anything in the full source of OpenCV in a single Visual Studio solution.

How do I modify a file inside the Visual Studio project generated from CMake that contains all of the source code from OpenCV?

The steps I took are as follows:

Step 1:

Step 2:

Step 3:

  • Create directory named build, located here: C:opencv341build
  • Open CMake GUI.
  • Fill in the following fields:
  • Where is the source code: C:opencv341
  • Where to build the binaries: C:opencv341build

Step 4: Press configure.

Step 5:

  • Check the BUILD_EXAMPLES option.
  • Check the BUILD_WITH_DEBUG_INFO option.
  • Add the contrib library by setting the following:
  • Set OPENCV_EXTRA_MODULES_PATH to: C:opencv341contrib

Step 6: Press configure again.

Step 7: Press Generate.

Step 8: Open the generated Visual Studio project.

Step 9: Build the ALL_BUILD sub-project in Debug Mode. When complete with zero errors build the INSTALL sub-project in Debug mode.

Step 10: Repeat step 9 in Release mode.

Step 11: Attempt to modify code in the yolo_object_detection.cpp file.

A window displays that says:

“Cannot open file.”

I am able to run the yolo_object_detection example in a new project I create with changing the appropriate properties to link to the built .lib files I just built.

When I navigate to the directory C:opencv341samplesdnn there is a sub directory named example_dnn_yolo_object_detection.dir which contains a debug and release folder, each with the following:

  • vc141.pdb
  • yolo_object_detection.obj
  • example_dnn_yolo_object_detection.log
  • (sample).6EA414B7.tlog

The location of the actual .cpp file is located here:
C:opencv341samplesdnn yolo_object_detection.cpp


Please enter your comment!
Please enter your name here