- 1 year ago
Is there any way to install OpenCV in C++ on Windows without using any IDE but only in cmd?
Yes, you can install OpenCV in C++ on Windows using the Command Prompt (cmd) without relying on any specific IDE. Here's a step-by-step guide:
Download OpenCV: Visit the official OpenCV website (https://opencv.org/releases/) and download the Windows version of OpenCV. Choose the appropriate version and extract the downloaded file to a location on your computer.
Set Environment Variables: Add the OpenCV binaries directory to the system's
PATH
environment variable. Open the Command Prompt and run the following command, replacing<path_to_opencv>
with the actual path to the extracted OpenCV directory:shellsetx /M PATH "%PATH%;<path_to_opencv>\bin"
Example:
shellsetx /M PATH "%PATH%;C:\opencv\bin"
Compile C++ Code: Write your C++ code using a text editor and save it with a
.cpp
extension. For example, create a file namedmy_program.cpp
.Compile the Code: In the Command Prompt, navigate to the directory where your C++ code is located. Use the following command to compile the code, replacing
<path_to_opencv>
with the actual path to the OpenCV installation directory:shellcl /EHsc /I "<path_to_opencv>\include" my_program.cpp /link /LIBPATH:"<path_to_opencv>\lib" opencv_worldXXX.lib
Example:
shellcl /EHsc /I "C:\opencv\include" my_program.cpp /link /LIBPATH:"C:\opencv\lib" opencv_worldXXX.lib
Replace
XXX
with the appropriate version number. For example, if you have OpenCV 4.5.3, you would useopencv_world453.lib
.Run the Executable: After successful compilation, an executable file (
my_program.exe
) will be generated. Execute it by running the following command in the Command Prompt:shellmy_program.exe
By following these steps, you can install and use OpenCV in C++ on Windows using only the Command Prompt (cmd) without relying on any specific IDE.