Create a program using OpenCV by creating new text file and inserting the code as below then saving as test.cpp
- #include<stdio.h>
- #include<opencv/cv.h>
- #include<opencv/highgui.h>
- int main(){
- IplImage* img=cvLoadImage("test.jpg",1);
- cvNamedWindow("Test",1);
- cvShowImage("Test",img);
- cvWaitKey();
- return 0;
- }
สมมติว่า test.jpg ในบรรทัดที่ 7 อยู่ในแฟ้มเดียวกันกับ test.cpp
We assume that test.jpg on line 7 is an image in the same folder as test.cpp
Create a CMake file by creating new text file and inserting the code as below then saving as CMakeLists.txt in the same folder as test.cpp
- cmake_minimum_required(VERSION 2.8)
- project( project_name)
- find_package( OpenCV REQUIRED )
- add_executable( project_name test.cpp )
- target_link_libraries( project_name ${OpenCV_LIBS} )
สร้างโปรแกรมสำหรับรัน โดยใช้คำสั่งตามด้านล่างใน Terminal
Generate the executable file by using the command as below on Terminal
- cd <folder of test.txt>
- cmake .
- make
รันโปรแกรม โดยใช้คำสั่งตามด้านล่างใน Terminal
Run the executable file by using the command as below on Terminal
- ./project_name
When you edit code again, you can use this command on Terminal to regenerate the executable file
- cd <folder of test.txt>
- make
No comments:
Post a Comment