/CVTest

OpenCV test

Primary LanguageC++

OpenCV Test Project

A simple C++ project demonstrating OpenCV integration using vcpkg package manager.

Prerequisites

  • Visual Studio 2022 Community (with C++ development tools)
  • Git
  • vcpkg package manager

Setup

1. Install vcpkg and OpenCV

# Clone vcpkg (if not already done)
git clone https://github.com/Microsoft/vcpkg.git S:\Dev\GitHub\microsoft\vcpkg

# Bootstrap vcpkg
cd S:\Dev\GitHub\microsoft\vcpkg
.\bootstrap-vcpkg.bat

# Install OpenCV
.\vcpkg.exe install opencv:x64-windows

# Integrate with Visual Studio
.\vcpkg.exe integrate install

2. Build the Project

# Configure CMake with vcpkg toolchain
cmake -B build -DCMAKE_TOOLCHAIN_FILE="S:/Dev/GitHub/microsoft/vcpkg/scripts/buildsystems/vcpkg.cmake"

# Build the project
cmake --build build --config Release

3. Run the Program

.\build\Release\OpenCVTest.exe

Visual Studio Code Setup

This project includes VS Code configuration files:

  • .vscode/tasks.json - Build tasks for CMake
  • .vscode/launch.json - Debug and run configurations
  • .vscode/c_cpp_properties.json - C++ IntelliSense configuration

Running and Debugging in VS Code

  1. Build: Press Ctrl+Shift+B or use Command Palette → "Tasks: Run Task"
  2. Run: Press Ctrl+F5 or use Command Palette → "Debug: Start Without Debugging"
  3. Debug: Press F5 or use Command Palette → "Debug: Start Debugging"

Project Structure

CVTest/
├── .vscode/                 # VS Code configuration
│   ├── tasks.json
│   ├── launch.json
│   └── c_cpp_properties.json
├── build/                   # Build output (git ignored)
├── CMakeLists.txt          # CMake configuration
├── main.cpp                # Main program
└── README.md               # This file

What the Program Does

The program demonstrates basic OpenCV functionality:

  1. Creates a 300x400 pixel image
  2. Draws a green circle
  3. Adds "Hello OpenCV!" text
  4. Saves the result as test_output.jpg
  5. Displays OpenCV version and image dimensions

Dependencies

  • OpenCV 4.11.0 (installed via vcpkg)
  • CMake 3.10+
  • MSVC compiler (Visual Studio 2022)

Notes

  • The vcpkg toolchain file path is hardcoded for this specific setup
  • Adjust paths in VS Code configuration files if vcpkg is installed elsewhere
  • Output images are ignored by Git (see .gitignore)