分类 OpenCV 下的文章

“OpenCV的全称是Open Source Computer Vision Library,是一个跨平台的计算机视觉库。OpenCV是由英特尔公司发起并参与开发,以BSD许可证授权发行。”

从github下载vcpkg源码包

git clone https://github.com/Microsoft/vcpkg.git

进入源码目录

cd vcpkg

执行./bootstrap-vcpkg.sh

./bootstrap-vcpkg.sh

编译好后,进行安装

./vcpkg integrate install

vcpkg创建软链接

sudo ln -s /home/const/vcpkg/vcpkg /usr/bin

vcpkg用法

vcpkg list

输出:

ade:x64-linux                                      0.1.1f#1         ADE Framework is a graph construction, manipulat...
angle:x64-linux                                    2020-05-15#2     A conformant OpenGL ES implementation for Window...
assimp:x64-linux                                   5.0.1#4          The Open Asset import library
brotli:x64-linux                                   1.0.9#1          a generic-purpose lossless compression algorithm...
bzip2:x64-linux                                    1.0.8#1          bzip2 is a freely available, patent free, high-q...
curl:x64-linux                                     7.74.0#7         A library for transferring data with URLs
curl[non-http]:x64-linux                                            Enables protocols beyond HTTP/HTTPS/HTTP2
curl[openssl]:x64-linux                                             SSL support (OpenSSL)
curl[ssl]:x64-linux                                                 Default SSL backend

vcpkg search 用法

vcpkg search opencv4

输出:

vcpkg search opencv4
opencv4                  4.5.2            computer vision library
opencv4[ade]                              graph api
opencv4[contrib]                          opencv_contrib module
opencv4[cuda]                             CUDA support for opencv
opencv4[dnn]                              Enable dnn module
opencv4[eigen]                            Eigen support for opencv
opencv4[ffmpeg]                           ffmpeg support for opencv
opencv4[gdcm]                             GDCM support for opencv
opencv4[halide]                           Halide support for opencv
opencv4[ipp]                              Enable Intel Integrated Performance Primitives
opencv4[jasper]                           JPEG 2000 support for opencv
opencv4[jpeg]                             JPEG support for opencv
opencv4[lapack]                           LAPACK support for opencv
opencv4[nonfree]                          allow nonfree and unredistributable libraries
opencv4[openexr]                          OpenEXR support for opencv
opencv4[opengl]                           opengl support for opencv
opencv4[openmp]                           Enable openmp support for opencv
opencv4[ovis]                             opencv_ovis module
opencv4[png]                              PNG support for opencv
opencv4[qt]                               Qt GUI support for opencv
opencv4[quirc]                            Enable QR code module
opencv4[sfm]                              opencv_sfm module
opencv4[tbb]                              Enable Intel Threading Building Blocks
opencv4[tiff]                             TIFF support for opencv
opencv4[vtk]                              vtk support for opencv
opencv4[webp]                             WebP support for opencv
opencv4[world]                            Compile to a single package support for opencv

gocv介绍
gocv是OpenCV4在Go中的绑定,使用它可以在Go里做图像处理。
Github: https:/​/github.com/hybridgroup/gocv
opencv介绍
OpenCV的全称是Open Source Computer Vision Library,是一个跨平台的计算机视觉库。OpenCV是由英特尔公司发起并参与开发,以BSD许可证授权发行。

Ubuntu/Linux安装步骤

go get -u -d gocv.io/x/gocv
cd ~/go/pkg/mod/gocv.io/x/gocv@v0.27.0

编译动态库

sudo make install

编译静态库

sudo make install BUILD_SHARED_LIBS=OFF

验证安装

go run ./cmd/version/main.go

运行结果:

gocv version: 0.27.0
opencv lib version: 4.5.2

代码:

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>

using namespace std;
using namespace cv;
using namespace std;


int main(int argc, char* argv[])
{
    cout<<"OpenCV4 Example."<<endl;
    cout<<"OpenCV Version = "<<getVersionString()<<endl;
    webcam();
    
    return 0;
}

void webcam()
{
    Mat frame;
    VideoCapture cap;
    int deviceID = 0;             // 0 = open default camera
    int apiID = cv::CAP_ANY;      // 0 = autodetect default API
    cap.open(deviceID, apiID);
    if (!cap.isOpened()) {
        cerr << "ERROR! Unable to open camera\n";
        return;
    }
    cout << "Start grabbing" << endl << "Press any key to terminate" << endl;
    for (;;)
    {
        cap.read(frame);
        if (frame.empty()) {
            cerr << "ERROR! blank frame grabbed\n";
            break;
        }
        imshow("Live", frame);
        if (waitKey(40) >= 0)
            break;
    }
}

运行结果:

./opencv-demo 
OpenCV4 Example.
OpenCV Version = 4.5.2
Start grabbing
Press any key to terminate

运行效果:
opencv-webcam-capture.png

下载
https://github.com/opencv/opencv/archive/refs/tags/4.5.3.zip

解压

unzip 4.5.3.zip

建目录

cd opencv4.5.3 && mkdir build && cd build

配置

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.3 ..

编译

make -j8

安装

sudo make install

配置lib

sudo vi /etc/ld.so.conf.d/opencv4.5.3.conf

/usr/local/opencv4.5.3/lib

更新lib

sudo ldconfig

另外,如果要编译opencv_world选项的话,在cmake的时候加个参数就好。

cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_opencv_world=ON -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.3 ..

其它的一些参数示例:

     -D WITH_CUDA=ON \

    -D CUDA_ARCH_BIN="5.3" \
    -D CUDA_ARCH_PTX="5.3" \
    -D WITH_CUBLAS=ON \
    -D ENABLE_FAST_MATH=ON \
    -D CUDA_FAST_MATH=ON \
    -D ENABLE_NEON=ON \
    -D WITH_GSTREAMER=ON \
    -D WITH_LIBV4L=ON \
    -D BUILD_opencv_python2=OFF \
    -D BUILD_opencv_python3=ON \
    -D BUILD_TESTS=OFF \
    -D BUILD_PERF_TESTS=OFF \
    -D BUILD_EXAMPLES=OFF  \
    -D WITH_TBB=ON \
    -D BUILD_opencv_world=OFF \
    -D WITH_OPENGL=ON \
    -D WITH_GTK_2_X=ON \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D EIGEN_INCLUDE_PATH="/usr/include/eigen3" \
    -D WITH_XINE=ON \
    -D WITH_GDAL=ON \
    -D WITH_QT=ON \

cmake编译选项(ON是开(机)的意思; OFF是关(机)的意思)

-D CMAKE_BUILD_TYPE=RELEASE

编译模式,release/debug, 默认为release
-D CMAKE_INSTALL_PREFIX=/usr/local

安装路径
-D WITH_TBB=ON #Include Intel TBB support

(Intel开发的并行编程开发工具),默认为off
-D BUILD_TIFF=ON

Build libtiff from source(一种灵活的位图格式),默认为ON
-D WITH_V4L=ON 支持Vedio4Linux(是Linux中关于视频设备的内核驱动,为针对视频设备的应用视频设备的应用程序提供一系列接口函数,这些视频设备包括TV卡、视频捕捉卡和USB摄像头等,对于USB摄像头,其驱动程序中需要提供基本的I/O操作用于open、read、write、close函数的实现),默认为ON
-D INSTALL_C_EXAMPLES=ON Install C examples, 默认为off
-D INSTALL_PYTHON_EXAMPLES=ON Install Python examples, 默认为off
-D BUILD_EXAMPLES=ON Build all examples, 默认为off
-D WITH_QT=ON / #支持QT(c++图像用户界面开发框架,多用于开发GUI),默认为off

-D WITH_GTK=ON 支持跨平台通用图形工具包GTK, 默认为on
-D WITH_OPENGL=ON 支持开放图形库OpenGL,默认为off …
-D OPENCV_GENERATE_PKGCONFIG=ON Linux下我们使用opencv,需要使用pkg-config来进行环境变量的管理,这个软件需要.pc类型的文件作为软件配置信息
生成opencv.pc文件的配置(注意,opencv4生成的文件叫做opencv4.pc)

Referenced from:https://blog.csdn.net/zhizhengguan/article/details/107540971

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.3 -D OPENCV_EXTRA_MODULES=../opencv_contrib/modules -D BUILD_EXAMPLES=ON -D WITH_VA=ON ..