最新要闻

广告

手机

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

家电

快资讯: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 sourcesadd_executable(opencv_example example.cpp)# Link your application with OpenCV librariestarget_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过来打开也是可以的,但是切换时候很不方便,就这样

关键词: 很不方便 系统变量 正常运行