OpenCV 4.0学习笔记

OpenCV 4.0学习笔记

g++

//#include 
//#include 
//#include 
//#include 

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

void check_opencv_version()
{
    cout << "OpenCV version : " << CV_VERSION << endl;
    cout << "Major version : " << CV_MAJOR_VERSION << endl;
    cout << "Minor version : " << CV_MINOR_VERSION << endl;
    cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl;

    if (CV_MAJOR_VERSION < 3)
    {
        // Old OpenCV 3 code goes here.
    }
    else
    {
        // New OpenCV 4 code goes here.
    }
}

int main()
{
	check_opencv_version();
}
g++ -c ../main.cpp -o  main.o  `pkg-config --cflags --libs opencv4`
g++ -o main.out main.o  `pkg-config --cflags --libs opencv4`

Cmake 配置

mingw版下载

cmake配置:

cmake_minimum_required(VERSION 3.17)
project(OpenCV)

set(CMAKE_CXX_STANDARD 14)

aux_source_directory(./src DIR_SRC)

# open cv 目录
set(OPENCV_DIR D:/OpenCV-MinGW-Build-OpenCV-4.5.2-x64)

# include目录
include_directories(${OPENCV_DIR}/include)
include_directories(include)

#库目录
link_directories(${OPENCV_DIR}/x64/mingw/lib)

# 库
link_libraries(opencv_core452
        opencv_highgui452
        opencv_imgproc452
        opencv_calib3d452
        opencv_dnn452
        opencv_features2d452
        opencv_flann452
        opencv_gapi452
        opencv_imgcodecs452
        opencv_ml452
        opencv_objdetect452
        opencv_photo452
        opencv_stitching452
        opencv_video452
        opencv_videoio452
        )
add_executable(OpenCV ${DIR_SRC})

cv::Mat

How to initialize a cv::Mat using a vector of floats?

#include 
#include 

using namespace cv;
using namespace std;

int main(int argc, char *argv[])
{
    vector vec{0.1, 0.9, 0.2, 0.8, 0.3, 0.7, 0.4, 0.6, 0.5, 1};

    Mat m1(vec);
    cout << m1 << endl;
    cout << "===========" << endl;

    Mat m2(1, vec.size(), CV_32FC1, vec.data());
    cout << m2 << m2.type() << endl;
    cout << "===========" << endl;
    
    Mat1f m3(vec.size(), 1, vec.data());
    cout << m3 << endl;
    cout << "===========" << endl;

    Mat1f m4(1, vec.size(), vec.data());
    cout << m4 << endl;
    cout << "===========" << endl;

    cout << "as seen below all Mat and vector use same data" << endl;
    cout << vec[0] << endl;
    m1 *= 2;
    cout << vec[0] << endl;
    m2 *= 2;
    cout << vec[0] << endl;
    m3 *= 2;
    cout << vec[0] << endl;
    m4 *= 2;
    cout << vec[0] << endl;

    return 0;
}

参考

  • opencv4.0学习笔记

你可能感兴趣的:(OpenCV,OpenCV,ubuntu)