VS2019+opencv4.2.0+opencv contrib4.2.0

小王莊發表於2020-11-25

github opencv下載地址
把下載完的opencv 和opencv-contrib(opencv和opencv-contrib必須是同一版本)都放在同一個資料夾中,再新建一個build資料夾
在這裡插入圖片描述
開啟cmake
1,2找路徑,然後點3處的configure,圖為點選configure的效果
在這裡插入圖片描述
√一個填一個然後generate
在這裡插入圖片描述
直到出現generate done
在這裡插入圖片描述
在這裡插入圖片描述
然後點生成然後一直等(半小時吧差不多)
在這裡插入圖片描述
然後結束了 那個失敗是python 沒啥事
然後看intall資料夾是這樣就可以了
在這裡插入圖片描述

配置環境變數

找bin目錄我的是這樣,然後新增到path裡去
F:\opencv\build\install\x64\vc16\bin

專案配置opencv

在這裡插入圖片描述
在這裡插入圖片描述
然後往附加依賴項裡面新增
在這裡插入圖片描述
4.2.0 debug版本
opencv_aruco420d.lib
opencv_bgsegm420d.lib
opencv_bioinspired420d.lib
opencv_calib3d420d.lib
opencv_ccalib420d.lib
opencv_core420d.lib
opencv_datasets420d.lib
opencv_dnn420d.lib
opencv_dnn_objdetect420d.lib
opencv_dpm420d.lib
opencv_face420d.lib
opencv_features2d420d.lib
opencv_flann420d.lib
opencv_fuzzy420d.lib
opencv_gapi420d.lib
opencv_hdf420d.lib
opencv_hfs420d.lib
opencv_highgui420d.lib
opencv_imgcodecs420d.lib
opencv_imgproc420d.lib
opencv_img_hash420d.lib
opencv_line_descriptor420d.lib
opencv_ml420d.lib
opencv_objdetect420d.lib
opencv_optflow420d.lib
opencv_phase_unwrapping420d.lib
opencv_photo420d.lib
opencv_plot420d.lib
opencv_reg420d.lib
opencv_rgbd420d.lib
opencv_saliency420d.lib
opencv_shape420d.lib
opencv_stereo420d.lib
opencv_stitching420d.lib
opencv_structured_light420d.lib
opencv_superres420d.lib
opencv_surface_matching420d.lib
opencv_text420d.lib
opencv_tracking420d.lib
opencv_video420d.lib
opencv_videoio420d.lib
opencv_videostab420d.lib
opencv_xfeatures2d420d.lib
opencv_ximgproc420d.lib
opencv_xobjdetect420d.lib
opencv_xphoto420d.lib
opencv_aruco420d.lib
opencv_bgsegm420d.lib
opencv_bioinspired420d.lib
opencv_calib3d420d.lib
opencv_ccalib420d.lib
opencv_core420d.lib
opencv_datasets420d.lib
opencv_dnn420d.lib
opencv_dnn_objdetect420d.lib
opencv_dpm420d.lib
opencv_face420d.lib
opencv_features2d420d.lib
opencv_flann420d.lib
opencv_fuzzy420d.lib
opencv_gapi420d.lib
opencv_hdf420d.lib
opencv_hfs420d.lib
opencv_highgui420d.lib
opencv_imgcodecs420d.lib
opencv_imgproc420d.lib
opencv_img_hash420d.lib
opencv_line_descriptor420d.lib
opencv_ml420d.lib
opencv_objdetect420d.lib
opencv_optflow420d.lib
opencv_phase_unwrapping420d.lib
opencv_photo420d.lib
opencv_plot420d.lib
opencv_reg420d.lib
opencv_rgbd420d.lib
opencv_saliency420d.lib
opencv_shape420d.lib
opencv_stereo420d.lib
opencv_stitching420d.lib
opencv_structured_light420d.lib
opencv_superres420d.lib
opencv_surface_matching420d.lib
opencv_text420d.lib
opencv_tracking420d.lib
opencv_video420d.lib
opencv_videoio420d.lib
opencv_videostab420d.lib
opencv_xfeatures2d420d.lib
opencv_ximgproc420d.lib
opencv_xobjdetect420d.lib
opencv_xphoto420d.lib

release版本
opencv_aruco420.lib
opencv_bgsegm420.lib
opencv_bioinspired420.lib
opencv_calib3d420.lib
opencv_ccalib420.lib
opencv_core420.lib
opencv_datasets420.lib
opencv_dnn420.lib
opencv_dnn_objdetect420.lib
opencv_dpm420.lib
opencv_face420.lib
opencv_features2d420.lib
opencv_flann420.lib
opencv_fuzzy420.lib
opencv_gapi420.lib
opencv_hdf420.lib
opencv_hfs420.lib
opencv_highgui420.lib
opencv_imgcodecs420.lib
opencv_imgproc420.lib
opencv_img_hash420.lib
opencv_line_descriptor420.lib
opencv_ml420.lib
opencv_objdetect420.lib
opencv_optflow420.lib
opencv_phase_unwrapping420.lib
opencv_photo420.lib
opencv_plot420.lib
opencv_reg420.lib
opencv_rgbd420.lib
opencv_saliency420.lib
opencv_shape420.lib
opencv_stereo420.lib
opencv_stitching420.lib
opencv_structured_light420.lib
opencv_superres420.lib
opencv_surface_matching420.lib
opencv_text420.lib
opencv_tracking420.lib
opencv_video420.lib
opencv_videoio420.lib
opencv_videostab420.lib
opencv_xfeatures2d420.lib
opencv_ximgproc420.lib
opencv_xobjdetect420.lib
opencv_xphoto420.lib
opencv_aruco420.lib
opencv_bgsegm420.lib
opencv_bioinspired420.lib
opencv_calib3d420.lib
opencv_ccalib420.lib
opencv_core420.lib
opencv_datasets420.lib
opencv_dnn420.lib
opencv_dnn_objdetect420.lib
opencv_dpm420.lib
opencv_face420.lib
opencv_features2d420.lib
opencv_flann420.lib
opencv_fuzzy420.lib
opencv_gapi420.lib
opencv_hdf420.lib
opencv_hfs420.lib
opencv_highgui420.lib
opencv_imgcodecs420.lib
opencv_imgproc420.lib
opencv_img_hash420.lib
opencv_line_descriptor420.lib
opencv_ml420.lib
opencv_objdetect420.lib
opencv_optflow420.lib
opencv_phase_unwrapping420.lib
opencv_photo420.lib
opencv_plot420.lib
opencv_reg420.lib
opencv_rgbd420.lib
opencv_saliency420.lib
opencv_shape420.lib
opencv_stereo420.lib
opencv_stitching420.lib
opencv_structured_light420.lib
opencv_superres420.lib
opencv_surface_matching420.lib
opencv_text420.lib
opencv_tracking420.lib
opencv_video420.lib
opencv_videoio420.lib
opencv_videostab420.lib
opencv_xfeatures2d420.lib
opencv_ximgproc420.lib
opencv_xobjdetect420.lib
opencv_xphoto420.lib

測試程式碼:

#include <stdio.h>
#include <iostream>
#include "opencv2/opencv.hpp"  
#include"opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include"opencv2/xfeatures2d.hpp"

using namespace cv;

using namespace std;

int main()
{
    Mat img_1 = imread("F:/vsRep/opencvtest/opencvtest/chase.jpg");
    Mat img_2 = imread("F:/vsRep/opencvtest/opencvtest/face.jpg");

    Ptr<Feature2D> sift = xfeatures2d::SIFT::create();

    vector<KeyPoint> keypoints_1, keypoints_2;
    Mat descriptors_1, descriptors_2;

    sift->detectAndCompute(img_1, noArray(), keypoints_1, descriptors_1);
    sift->detectAndCompute(img_2, noArray(), keypoints_2, descriptors_2);

    //繪製特徵點(關鍵點)
    drawKeypoints(img_1, keypoints_1, descriptors_1, Scalar(0, 0, 255));
    drawKeypoints(img_2, keypoints_2, descriptors_2, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

    imshow("img_1", descriptors_1);
    imshow("img_2", descriptors_2);
    waitKey(0);

    return 0;

}