#Having issues with using openCV in c++

2 messages · Page 1 of 1 (latest)

rich talon
#

Hi there, pretty new to all this but when I try using opencv in c++ I keep running into some errors. With online forums which I understand almost nothing of, ive fixed all of the errors (yesterday), but now that I'm tryna work on it now, vsc is... not running ideally. I keep getting these errors BUT if I've built it with cmake, the .exe works perfectly. Just as intended but vsc seems to find errors i honestly dont know how.

Ive attached the errors as an image and you can find my code below.

main.cpp

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

int main() {
    std::cout << "OpenCV version: " << CV_VERSION << std::endl;
    
    cv::Mat img(300, 400, CV_8UC3, cv::Scalar(100, 150, 200));
    cv::putText(img, "Hello OpenCV!", cv::Point(50, 150), 
                cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255), 2);
    
    cv::imshow("Test Window", img);
    cv::waitKey(0);
    cv::destroyAllWindows();
    
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(OpenCVTest)

set(OpenCV_DIR "C:/opencv/build")

find_package(OpenCV REQUIRED)
add_executable(OpenCVTest main.cpp)

target_link_libraries(OpenCVTest ${OpenCV_LIBS})
woven egret
#

VS Code moment

and C++ build system moment