直接在文本文档中编写程序的效率太低,主要是限于函数的联想功能!
一般采用集成软件进行代码编写,可以使用KDevelop,类似Windows中的VS。
在KDE中编写程序的方式跟windows中的VS相同,稍有区别的是需要在CMakeLists.txt文档中添加相应的库函数。
main.cpp如下:
------------------------
#include <iostream>
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat mat=cv::Mat::zeros(3,3,CV_8UC1);
std::cout<<(int)mat.at<uchar>(0.0)<<std::endl;
std::cout << "Hello, world! My friend!" << std::endl;
return 0;
}
--------------------------
CMakeLists.txt如下:
--------------------------
project(***)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(*** main.cpp)
target_link_libraries(*** ${OpenCV_LIBS})
install(TARGETS *** RUNTIME DESTINATION bin)
--------------------------
其中 *** 是工程名。
编译执行后,结果如下:
--------------------------
启动:/home/***********************************
0
Hello, world! My friend!
*** 正常退出 ***
--------------------------
经测试,OpenCV可以在KDE中正常运行!
其它的库,例如pcl、eigen等,与OpenCV的使用方式相似。