OpenCV : Open Source Computer Vision Library,开源的计算机视觉和机器学习库,可以支持 C++、Python 等开发平台
这里使用 Visual Studio 2022 创建 OpenCV 的测试工程
【新建系统变量】 OPENCV_DIR,并在 系统变量 path 中添加 %OPENCV_DIR%\bin
这里直接创建一个 C++ helloworld 的工程
拷贝OpenCV 官方的测试代码,替换 helloworld 工程默认的代码
https://docs.opencv.org/4.6.0/dd/d6e/tutorial_windows_visual_studio_opencv.html
#include
#include
#include
#include
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: " << argv[0] << " ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if( image.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
$(OPENCV_DIR)\..\..\include
$(OPENCV_DIR)\lib
opencv_world460.lib,【Debug】版本添加 opencv_world460d.lib

点击编译,可以正常编译通过
因为运行需要输入参数(图片路径),所以这里到生成产物的路径下,使用 cmd.exe 运行
D:\work\opencv\demo\1112\opencv_demo_01\x64\Release>opencv_demo_01.exe 1.png

opencv_world460.dll,应该是环境变量没有配置好,需要配置 %OPENCV_DIR%\bin 到系统环境变量 path 中
还是需要多练习,多用一用,才能真正掌握 OpenCV 的开发技术,才能真正了解 OpenCV 到底能用来干什么
当前计算机视觉技术迅速发展,OpenCV 除了在PC 电脑上运行,还可以在嵌入式处理器平台上运行,如嵌入式Linux 中