尊龙凯时人生就是搏

ʹÓÃCMake¹¹½¨LinuxÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ

ʹÓÃcmake¹¹½¨linuxÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ

ͻ񻣼

Ëæ×ÅÅ©ÒµÊÖÒÕµÄÒ»Ö±Éú³¤ £¬ÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòÕýÖð½¥Êܵ½¹Ø×¢¡£ÔÚ¿ª·¢ºÍ¹¹½¨ÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòʱ £¬Ñ¡ÔñÊʵ±µÄ¹¹½¨¹¤¾ßÖÁ¹ØÖ÷Òª¡£CMake ÊÇÒ»¸öÓÃÓÚ¹¹½¨¡¢²âÊԺʹò°üC/C++Ó¦ÓóÌÐòµÄ¿çƽ̨¹¤¾ß¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃCMakeÀ´ÉèÖÃLinuxÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄ¹¹½¨Àú³Ì £¬²¢ÌṩÏìÓ¦µÄʾÀý´úÂë¡£

CMake¼ò½é

CMakeÊÇÒ»¸ö¿ªÔ´µÄ¿çƽ̨×Ô¶¯¹¹½¨ÏµÍ³ £¬¿ÉÒÔÌìÉúMakefile»òÆäËû²î±ð²Ù×÷ϵͳËùÖ§³ÖµÄ¹¹½¨¾ç±¾¡£ËüʹÓüòÆÓµÄÉèÖÃÎļþÀ´½çËÃ÷ÈÕû¸ö¹¹½¨Àú³Ì £¬²¢ÇÒ¿ÉÒÔ×Ô¶¯¼ì²âϵͳÇéÐκͿâµÄÒÀÀµ¹Øϵ¡£CMakeµÄÉèÖúÜÊÇÎÞа £¬ÊÊÓÃÓÚÖݪֲî±ðµÄÏîÄ¿¡£

ÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄ¹¹½¨ÉèÖÃ

ÔÚÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄ¹¹½¨Àú³ÌÖÐ £¬ÎÒÃÇÐèҪ˼Á¿ÒÔϼ¸¸ö·½ÃæµÄÉèÖãº

2.1 ÉèÖñàÒëÆ÷ºÍ±àÒëÑ¡Ïî

ÔÚCMakeLists.txtÎļþÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖÃCMAKE_C_COMPILER»òCMAKE_CXX_COMPILER±äÁ¿À´Ö¸¶¨±àÒëÆ÷¡£ÎÒÃÇ»¹¿ÉÒÔÉèÖÃCMAKE_CXX_FLAGS»òCMAKE_C_FLAGS±äÁ¿À´Ìí¼Ó±àÒëÑ¡Ïî £¬ÀýÈçÓÅ»¯¼¶±ð¡¢ÖÒÑÔ¼¶±ðµÈ¡£Ê¾ÀýÈçÏ£º

cmake_minimum_required(VERSION 3.10)

project(SmartAgriApp)

set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")

µÇ¼ºó¸´ÖÆ

2.2 Ö¸¶¨Ô´ÎļþºÍ°üÀ¨Ä¿Â¼

ͨ¹ýʹÓÃadd_executableÏÂÁîÖ¸¶¨Ô´Îļþ £¬²¢Í¨¹ýtarget_include_directoriesÏÂÁîÖ¸¶¨ÐèÒª°üÀ¨µÄĿ¼¡£Ê¾Àý´úÂëÈçÏ£º

add_executable(app main.cpp helper.cpp)
target_include_directories(app PUBLIC include)

µÇ¼ºó¸´ÖÆ

2.3 Ìí¼ÓÒÀÀµ¿â

ÔÚÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòÖÐ £¬¿ÉÄÜÐèÒªÒýÈëÍⲿ¿âÀ´ÊµÏÖһЩ¹¦Ð§¡£Í¨¹ýʹÓÃfind_packageÏÂÁîÕÒµ½ËùÐèµÄ¿â £¬²¢Ê¹ÓÃtarget_link_librariesÏÂÁËüÃÇÁ´½Óµ½ÎÒÃǵÄÓ¦ÓóÌÐòÖС£ÀýÈç £¬ÈôÊÇÎÒÃǵÄÓ¦ÓóÌÐòÐèҪʹÓÃOpenCV¿â £¬ÎÒÃÇ¿ÉÒÔÔÚCMakeLists.txtÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺

find_package(OpenCV REQUIRED)
target_link_libraries(app ${OpenCV_LIBS})

µÇ¼ºó¸´ÖÆ

2.4 ÌìÉú¿ÉÖ´ÐÐÎļþ

×îºó £¬Í¨¹ýʹÓÃadd_executableÏÂÁîÀ´ÌìÉú¿ÉÖ´ÐÐÎļþ £¬²¢Ê¹ÓÃinstallÏÂÁ¿ÉÖ´ÐÐÎļþ×°Öõ½Ö¸¶¨µÄλÖá£Ê¾Àý´úÂëÈçÏ£º

add_executable(app main.cpp helper.cpp)
install(TARGETS app DESTINATION bin)

µÇ¼ºó¸´ÖÆ

ʾÀý´úÂë

ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄʾÀý´úÂë:

#include <iostream>
#include <opencv2/opencv.hpp>

void processImage(cv::Mat& image) {
   // ͼÏñ´¦ÀíÂß¼­
}

int main() {
   cv::VideoCapture cap(0);
   if (!cap.isOpened()) {
      std::cerr << "ÎÞ·¨·­¿ªÏà»ú" << std::endl;
      return -1;
   }

   cv::Mat frame;
   while (cap.read(frame)) {
      processImage(frame);
      cv::imshow("ÖÇÄÜÅ©ÒµÓ¦ÓóÌÐò", frame);

      if (cv::waitKey(1) == 27) {
         break;
      }
   }

   cv::destroyAllWindows();
   return 0;
}

µÇ¼ºó¸´ÖÆ

×ܽá

ͨ¹ýʹÓÃCMakeÀ´ÉèÖÃLinuxÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄ¹¹½¨Àú³Ì £¬ÎÒÃÇ¿ÉÒÔÎÞаµØ½ç˵±àÒëÆ÷¡¢±àÒëÑ¡Ïî¡¢Ô´Îļþ¡¢ÒÀÀµ¿âµÈ¡£CMakeÌṩÁËÒ»¸ö¾«Á·¶øÇ¿Ê¢µÄ¹¹½¨ÏµÍ³ £¬Ê¹µÃ¿ª·¢ÖÇÄÜÅ©ÒµÓ¦ÓóÌÐò±äµÃÔ½·¢Àû±ãºÍ¸ßЧ¡£

²Î¿¼ÎÄÏ×£º

CMake¹Ù·½Îĵµ: https://cmake.org/documentation/

OpenCV¹Ù·½Îĵµ: https://docs.opencv.org/

£¨×¢£ºÎÄÕÂÖеÄʾÀý½ö¹©²Î¿¼ £¬ÏêϸµÄÉèÖúʹúÂë¿ÉÄÜÒò²î±ðµÄÏîÄ¿¶øÓÐËù²î±ð¡££©

ÒÔÉϾÍÊÇʹÓÃCMake¹¹½¨LinuxÖÇÄÜÅ©ÒµÓ¦ÓóÌÐòµÄÉèÖü¼ÇɵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ