ÔÚLinuxϵͳÉÏʹÓÃCLion¾ÙÐлúеѧϰµÄÉèÖÃÒªÁì
ÔÚlinuxϵͳÉÏʹÓÃclion¾ÙÐлúеѧϰµÄÉèÖÃÒªÁì
»úеѧϰÊÇÏÖÔÚÅÌËã»ú¿ÆѧÁìÓòµÄÈÈÃÅÑо¿Æ«Ïò£¬Ëüͨ¹ýʹÓÃÊý¾ÝºÍͳ¼ÆÒªÁ죬ÈÃÅÌËãÐÔÄܹ»×Ô¶¯´ÓÂÄÀúÖÐѧϰ²¢¸ÄÉÆÐÔÄÜ¡£ÎªÁËÀû±ã»úеѧϰµÄ¿ª·¢ºÍµ÷ÊÔ£¬ÎÒÃÇ¿ÉÒÔʹÓÃJetBrains¿ª·¢µÄCLion¼¯³É¿ª·¢ÇéÐΣ¨IDE£©¡£±¾ÎĽ«ÏÈÈÝÔÚlinuxϵͳÉÏʹÓÃclion¾ÙÐлúеѧϰµÄÉèÖÃÒªÁì¡£
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃCLion¡£¿ÉÒÔͨ¹ý¹Ù·½ÍøÕ¾£¨https://www.jetbrains.com/clion/£©ÏÂÔØCLionµÄLinux°æ±¾£¬²¢Æ¾Ö¤Ö¸Ê¾¾ÙÐÐ×°Öá£
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÉèÖÃCLionÒÔÖ§³Ö»úеѧϰ¿ª·¢¡£Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃCMake£¬ËüÊÇÒ»¸ö¿çƽ̨µÄÏîÄ¿¹¹½¨¹¤¾ß¡£ÔÚÖÕ¶ËÖÐÊäÈëÒÔÏÂÏÂÁîÀ´×°ÖÃCMake£º
sudo apt-get install cmake
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬ÎÒÃÇÐèҪװÖÃOpenCV£¬ÕâÊÇÒ»¸öÆÕ±éÓÃÓÚÅÌËã»úÊÓ¾õºÍ»úеѧϰµÄ¿ªÔ´¿â¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°ÖÃOpenCV£º
sudo apt-get install libopencv-dev
µÇ¼ºó¸´ÖÆ
ÔÚCLionÖн¨ÉèÒ»¸öеÄC++ÏîÄ¿¡£Ñ¡Ôñ¡°File¡± ->¡°New Project¡±À´·¿ªÐ½¨ÏîÄ¿Ïòµ¼¡£Ñ¡Ôñ¡°C++ Executable¡±×÷ΪÏîÄ¿ÀàÐÍ£¬²¢ÉèÖÃÏîÄ¿Ãû³ÆºÍÉúÑĵÄ·¾¶¡£
ÔÚÏîÄ¿ÉèÖÃÖУ¬ÎÒÃÇÐèÒª¸æËßCLionÎÒÃÇÏ£ÍûʹÓÃCMake¹¹½¨ÏîÄ¿¡£µã»÷¡°File¡± -> ¡°Settings¡±·¿ªÉèÖöԻ°¿ò£¬È»ºóÑ¡Ôñ¡°Build, Execution, Deployment¡± -> ¡°CMake¡±Ñ¡Ï¡£µã»÷ÓÒ²àµÄ¡°+¡±°´Å¥£¬Ìí¼ÓÒ»¸öеÄCMakeÉèÖá£Ñ¡ÔñÄãµÄCMakeLists.txtÎļþ£¬²¢ÉèÖÃÊÂÇéĿ¼¡£
ÏÖÔÚÎÒÃÇ¿ÉÒÔ×îÏȱàд»úеѧϰ´úÂëÁË¡£ÎÒÃÇÒÔÒ»¸ö¼òÆÓµÄʾÀýÀ´ËµÃ÷£¬ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃǽ«Ê¹ÓÃOpenCV¿âѵÁ·Ò»¸ö¼òÆÓµÄͼÏñ·ÖÀàÆ÷¡£ÏÂÃæÊÇʾÀý´úÂ룺
#include <iostream> #include <opencv2/opencv.hpp> int main() { cv::Mat image = cv::imread("image.jpg", cv::IMREAD_GRAYSCALE); if (image.empty()) { std::cerr << "Failed to read image" << std::endl; return 1; } cv::namedWindow("Image", cv::WINDOW_NORMAL); cv::imshow("Image", image); cv::waitKey(0); return 0; }
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃÇÊ×ÏÈʹÓÃOpenCVµÄimreadº¯Êý¼ÓÔØÒ»ÕŻҶÈͼÏñ¡£È»ºó£¬ÔÚͼÏñ´°¿ÚÖÐÏÔʾͼÏñ£¬²¢ÆÚ´ýÓû§°´ÏÂí§Òâ¼ü¡£×îºó£¬ÎÒÃÇ·µ»Ø0ÒÔÌåÏÖ³ÌÐòÕý³£¿¢Ê¡£
ÏÖÔÚÎÒÃÇ¿ÉÒÔ±àÒëºÍÔËÐÐ×ðÁú¿Ê±»úеѧϰ´úÂëÁË¡£µã»÷CLion¹¤¾ßÀ¹ØÁ¬Ä¡°Build¡±°´Å¥À´¹¹½¨ÏîÄ¿¡£¹¹½¨Íê³Éºó£¬ÎÒÃÇ¿ÉÒÔµã»÷¹¤¾ßÀ¹ØÁ¬Ä¡°Run¡±°´Å¥À´ÔËÐгÌÐò¡£
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔÚlinuxϵͳÉÏʹÓÃclion¾ÙÐлúеѧϰµÄÉèÖÃÒªÁ졣ͨ¹ýƾ֤ÉÏÊö°ì·¨£¬Äã¿ÉÒÔÀû±ãµØ¾ÙÐлúеѧϰµÄ¿ª·¢ºÍµ÷ÊÔ¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇÔÚLinuxϵͳÉÏʹÓÃCLion¾ÙÐлúеѧϰµÄÉèÖÃÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡