Skip to content

Index


CPP

install using apt
# install headers, shared library and cmake config files
sudo apt install libopencv-dev

Demo

#include <iostream>
#include <opencv2/opencv.hpp>

int main() {
    std::cout << "Hello, OpenCV!" << std::endl;
    std::cout << "OpenCV version: " << CV_VERSION << std::endl;

    // Create a simple colored image (blue background)
    cv::Mat image(300, 400, CV_8UC3, cv::Scalar(255, 0, 0));

    // Draw a white rectangle and green text
    cv::rectangle(image, cv::Point(50, 50), cv::Point(350, 250), cv::Scalar(255, 255, 255), 3);
    cv::putText(image, "Hello OpenCV", cv::Point(60, 150),
                cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 255, 0), 2);

    // Display the image
    cv::imshow("Demo", image);
    cv::waitKey(0);

    return 0;
}
cmake_minimum_required(VERSION 3.10)
project(hello_opencv)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find OpenCV
find_package(OpenCV REQUIRED)



# Build the executable
add_executable(hello_opencv hello_cv.cpp)
# Include OpenCV headers
target_include_directories(hello_opencv PRIVATE ${OpenCV_INCLUDE_DIRS})
# Link against OpenCV libraries
target_link_libraries(hello_opencv ${OpenCV_LIBS})