opencv官網例程(4.7.0版本)運行示例

使用官網 https://opencv.org/releases/ 下載4.7版本
下載好後添加環境變量到安裝路徑下

以及在系統變量中添加OpenCV_DIR(也可以用set的方式從Cmakelist裏添加)

打開我們下載後的路徑,將example_cmake裏的CMakeLists.txt和Makefile複製出來到samples/cpp的路徑下

修改複製後的Cmakelist文件

官方示例
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS})
替換成
4.7版本,cpp名稱已全部修改
add_executable(facedetect facedetect.cpp)
target_link_libraries(facedetect ${OpenCV_LIBS})

add_executable(facial_features facial_features.cpp)
target_link_libraries(facial_features ${OpenCV_LIBS})


add_executable(falsecolor falsecolor.cpp)
target_link_libraries(falsecolor ${OpenCV_LIBS})


add_executable(fback fback.cpp)
target_link_libraries(fback ${OpenCV_LIBS})

add_executable(ffilldemo ffilldemo.cpp)
target_link_libraries(ffilldemo ${OpenCV_LIBS})

add_executable(filestorage filestorage.cpp)
target_link_libraries(filestorage ${OpenCV_LIBS})

add_executable(fitellipse fitellipse.cpp)
target_link_libraries(fitellipse ${OpenCV_LIBS})

add_executable(flann_search_dataset flann_search_dataset.cpp)
target_link_libraries(flann_search_dataset ${OpenCV_LIBS})

add_executable(grabcut grabcut.cpp)
target_link_libraries(grabcut ${OpenCV_LIBS})

add_executable(image_alignment image_alignment.cpp)
target_link_libraries(image_alignment ${OpenCV_LIBS})


add_executable(imagelist_creator imagelist_creator.cpp)
target_link_libraries(imagelist_creator ${OpenCV_LIBS})

add_executable(imagelist_reader imagelist_reader.cpp)
target_link_libraries(imagelist_reader ${OpenCV_LIBS})

add_executable(imgcodecs_jpeg imgcodecs_jpeg.cpp)
target_link_libraries(imgcodecs_jpeg ${OpenCV_LIBS})

add_executable(inpaint inpaint.cpp)
target_link_libraries(inpaint ${OpenCV_LIBS})

add_executable(intelligent_scissors intelligent_scissors.cpp)
target_link_libraries(intelligent_scissors ${OpenCV_LIBS})

add_executable(intersectExample intersectExample.cpp)
target_link_libraries(intersectExample ${OpenCV_LIBS})

add_executable(kalman kalman.cpp)
target_link_libraries(kalman ${OpenCV_LIBS})

add_executable(kmeans kmeans.cpp)
target_link_libraries(kmeans ${OpenCV_LIBS})

add_executable(laplace laplace.cpp)
target_link_libraries(laplace ${OpenCV_LIBS})

add_executable(letter_recog letter_recog.cpp)
target_link_libraries(letter_recog ${OpenCV_LIBS})

add_executable(lkdemo lkdemo.cpp)
target_link_libraries(lkdemo ${OpenCV_LIBS})

add_executable(logistic_regression logistic_regression.cpp)
target_link_libraries(logistic_regression ${OpenCV_LIBS})

add_executable(lsd_lines lsd_lines.cpp)
target_link_libraries(lsd_lines ${OpenCV_LIBS})

add_executable(mask_tmpl mask_tmpl.cpp)
target_link_libraries(mask_tmpl ${OpenCV_LIBS})

add_executable(matchmethod_orb_akaze_brisk matchmethod_orb_akaze_brisk.cpp)
target_link_libraries(matchmethod_orb_akaze_brisk ${OpenCV_LIBS})

add_executable(minarea minarea.cpp)
target_link_libraries(minarea ${OpenCV_LIBS})

add_executable(morphology2 morphology2.cpp)
target_link_libraries(morphology2 ${OpenCV_LIBS})

add_executable(neural_network neural_network.cpp)
target_link_libraries(neural_network ${OpenCV_LIBS})

add_executable(npr_demo npr_demo.cpp)
target_link_libraries(npr_demo ${OpenCV_LIBS})

add_executable(opencv_version opencv_version.cpp)
target_link_libraries(opencv_version ${OpenCV_LIBS})

add_executable(pca pca.cpp)
target_link_libraries(pca ${OpenCV_LIBS})

add_executable(peopledetect peopledetect.cpp)
target_link_libraries(peopledetect ${OpenCV_LIBS})

add_executable(phase_corr phase_corr.cpp)
target_link_libraries(phase_corr ${OpenCV_LIBS})

add_executable(points_classifier points_classifier.cpp)
target_link_libraries(points_classifier ${OpenCV_LIBS})

add_executable(polar_transforms polar_transforms.cpp)
target_link_libraries(polar_transforms ${OpenCV_LIBS})

add_executable(qrcode qrcode.cpp)
target_link_libraries(qrcode ${OpenCV_LIBS})

add_executable(segment_objects segment_objects.cpp)
target_link_libraries(segment_objects ${OpenCV_LIBS})

add_executable(select3dobj select3dobj.cpp)
target_link_libraries(select3dobj ${OpenCV_LIBS})

add_executable(simd_basic simd_basic.cpp)
target_link_libraries(simd_basic ${OpenCV_LIBS})

add_executable(smiledetect smiledetect.cpp)
target_link_libraries(smiledetect ${OpenCV_LIBS})

add_executable(squares squares.cpp)
target_link_libraries(squares ${OpenCV_LIBS})

add_executable(stereo_calib stereo_calib.cpp)
target_link_libraries(stereo_calib ${OpenCV_LIBS})

add_executable(stereo_match stereo_match.cpp)
target_link_libraries(stereo_match ${OpenCV_LIBS})

add_executable(stitching stitching.cpp)
target_link_libraries(stitching ${OpenCV_LIBS})

add_executable(stitching_detailed stitching_detailed.cpp)
target_link_libraries(stitching_detailed ${OpenCV_LIBS})

add_executable(train_HOG train_HOG.cpp)
target_link_libraries(train_HOG ${OpenCV_LIBS})

add_executable(train_svmsgd train_svmsgd.cpp)
target_link_libraries(train_svmsgd ${OpenCV_LIBS})

add_executable(travelsalesman travelsalesman.cpp)
target_link_libraries(travelsalesman ${OpenCV_LIBS})

add_executable(tree_engine tree_engine.cpp)
target_link_libraries(tree_engine ${OpenCV_LIBS})

add_executable(videocapture_basic videocapture_basic.cpp)
target_link_libraries(videocapture_basic ${OpenCV_LIBS})

add_executable(videocapture_audio videocapture_audio.cpp)
target_link_libraries(videocapture_audio ${OpenCV_LIBS})

add_executable(videocapture_audio_combination videocapture_audio_combination.cpp)
target_link_libraries(videocapture_audio_combination ${OpenCV_LIBS})

add_executable(videocapture_camera videocapture_camera.cpp)
target_link_libraries(videocapture_camera ${OpenCV_LIBS})

add_executable(videocapture_gphoto2_autofocus videocapture_gphoto2_autofocus.cpp)
target_link_libraries(videocapture_gphoto2_autofocus ${OpenCV_LIBS})

add_executable(videocapture_gstreamer_pipeline videocapture_gstreamer_pipeline.cpp)
target_link_libraries(videocapture_gstreamer_pipeline ${OpenCV_LIBS})

add_executable(videocapture_image_sequence videocapture_image_sequence.cpp)
target_link_libraries(videocapture_image_sequence ${OpenCV_LIBS})

add_executable(videocapture_microphone videocapture_microphone.cpp)
target_link_libraries(videocapture_microphone ${OpenCV_LIBS})

add_executable(videocapture_obsensor videocapture_obsensor.cpp)
target_link_libraries(videocapture_obsensor ${OpenCV_LIBS})

add_executable(videocapture_openni videocapture_openni.cpp)
target_link_libraries(videocapture_openni ${OpenCV_LIBS})

add_executable(videocapture_realsense videocapture_realsense.cpp)
target_link_libraries(videocapture_realsense ${OpenCV_LIBS})

add_executable(videocapture_starter videocapture_starter.cpp)
target_link_libraries(videocapture_starter ${OpenCV_LIBS})

add_executable(videowriter_basic videowriter_basic.cpp)
target_link_libraries(videowriter_basic ${OpenCV_LIBS})

add_executable(warpPerspective_demo warpPerspective_demo.cpp)
target_link_libraries(warpPerspective_demo ${OpenCV_LIBS})

add_executable(watershed watershed.cpp)
target_link_libraries(watershed ${OpenCV_LIBS})

add_executable(3calibration 3calibration.cpp)
target_link_libraries(3calibration ${OpenCV_LIBS})

add_executable(application_trace application_trace.cpp)
target_link_libraries(application_trace ${OpenCV_LIBS})


add_executable(asift asift.cpp)
target_link_libraries(asift ${OpenCV_LIBS})

add_executable(audio_spectrogram audio_spectrogram.cpp)
target_link_libraries(audio_spectrogram ${OpenCV_LIBS})

add_executable(bgfg_segm bgfg_segm.cpp)
target_link_libraries(bgfg_segm ${OpenCV_LIBS})

add_executable(calibration calibration.cpp)
target_link_libraries(calibration ${OpenCV_LIBS})

add_executable(camshiftdemo camshiftdemo.cpp)
target_link_libraries(camshiftdemo ${OpenCV_LIBS})

add_executable(cloning_demo cloning_demo.cpp)
target_link_libraries(cloning_demo ${OpenCV_LIBS})

add_executable(cloning_gui cloning_gui.cpp)
target_link_libraries(cloning_gui ${OpenCV_LIBS})

add_executable(connected_components connected_components.cpp)
target_link_libraries(connected_components ${OpenCV_LIBS})

add_executable(contours2 contours2.cpp)
target_link_libraries(contours2 ${OpenCV_LIBS})

add_executable(convexhull convexhull.cpp)
target_link_libraries(convexhull ${OpenCV_LIBS})

add_executable(cout_mat cout_mat.cpp)
target_link_libraries(cout_mat ${OpenCV_LIBS})

add_executable(create_mask create_mask.cpp)
target_link_libraries(create_mask ${OpenCV_LIBS})


add_executable(dbt_face_detection dbt_face_detection.cpp)
target_link_libraries(dbt_face_detection ${OpenCV_LIBS})

add_executable(delaunay2 delaunay2.cpp)
target_link_libraries(delaunay2 ${OpenCV_LIBS})

add_executable(demhist demhist.cpp)
target_link_libraries(demhist ${OpenCV_LIBS})

add_executable(detect_blob detect_blob.cpp)
target_link_libraries(detect_blob ${OpenCV_LIBS})


add_executable(detect_mser detect_mser.cpp)
target_link_libraries(detect_mser ${OpenCV_LIBS})

add_executable(dft dft.cpp)
target_link_libraries(dft ${OpenCV_LIBS})

add_executable(digits_lenet digits_lenet.cpp)
target_link_libraries(digits_lenet ${OpenCV_LIBS})

add_executable(digits_svm digits_svm.cpp)
target_link_libraries(digits_svm ${OpenCV_LIBS})

add_executable(dis_opticalflow dis_opticalflow.cpp)
target_link_libraries(dis_opticalflow ${OpenCV_LIBS})

add_executable(drawing drawing.cpp)
target_link_libraries(drawing ${OpenCV_LIBS})

add_executable(distrans distrans.cpp)
target_link_libraries(distrans ${OpenCV_LIBS})

add_executable(edge edge.cpp)
target_link_libraries(edge ${OpenCV_LIBS})


add_executable(ela ela.cpp)
target_link_libraries(ela ${OpenCV_LIBS})

add_executable(em em.cpp)
target_link_libraries(em ${OpenCV_LIBS})

add_executable(essential_mat_reconstr essential_mat_reconstr.cpp)
target_link_libraries(essential_mat_reconstr ${OpenCV_LIBS})

到此,就可以直接使用vs2022打開cmakelist生成全部示例的exe了

但是由於cpp都是使用的相對路徑,所以需要把samples\data下的圖片,全部複製到使用vs生成exe的路徑下samples\cpp\out\build\x64-Debug(默認設置如下)
到此配置全部結束,可以正常運行所有官網示例
題外話:當然新建一個c++空項目加載cpp過來打開也是可以的,但是切換時候很不方便,就這樣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章