1. Trang chủ
  2. » Ngoại Ngữ

C++ install and configure opencv project in ubuntu C++ install and configure opencv project in ubuntu

19 288 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 19
Dung lượng 527,41 KB

Nội dung

C++ install and configure opencv project in ubuntu is presented with content: Install JVM openjdk8jdk, install OpenCV, configure project for OpenCV, example. Invite you to consult the document details.

C++ INSTALL AND CONFIGURE OPENCV PROJECT IN UBUNTU Author: Nguyen Van Ca Distributed Computing and Networking Research Laboratory Email: nguyenvanca2110@gmail.com Content I II III IV Install JVM openjdk-8-jdk Install OpenCV Configure project for OpenCV Example I Intall open JDK sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk sudo update-alternatives config java II Install OpenCV sudo apt-get upgrade sudo apt-get update sudo apt-get install cmake sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev sudo apt-get install libgtk2.0-dev sudo apt-get install python-numpy mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D CMAKE_INSTALL_PREFIX=/usr/local Or cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local or cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" make 10 sudo make install III Configure for OpenCV project Debug Mode Creat new project: Hello C++ Click Properties of the project In C/C++ Build a Choise Setting: GCC C++ Complier  Includes b GCC C++ Complier  Includes Add new Path: /usr/local/include/opencv /usr/local/include/opencv2 Because when we make OpenCV have: -D CMAKE_INSTALL_PREFIX=/usr/local c GCC C++ Linker  Libraries Add: opencv_calib3d opencv_contrib opencv_core opencv_features opencv_flann opencv_gpu opencv_highgui opencv_imgproc opencv_legacy opencv_ml opencv_nonfree opencv_objdetect opencv_ocl opencv_photo opencv_stitching opencv_superres opencv_ts opencv_video opencv_videostab Release Mode is same with Debug Mode Build OpenCV in Command Line Complier g++ DS_OpenCV.cpp -o DS_OpenCV `pkg-config opencv cflags libs` And then type sudo ldconfig Run OpenCV in Command Line /DS_OpenCV CODE // Library of OpenCV #include #include #include #include #include //============================================== // Library of C++ #include #include #include #include #include #include #include #include //============================================== // Library of Socket #include #include #include using namespace cv; using namespace std; //============================================== //Declare Function to process string to_string(int i); void receiveImage(int sock, int idimage); void recognizeGender(Mat image, string hardKey); void sendPOST(string harwareKey, int id_gender); //============================================== //Declare global variables static int idImage = 0; static string face_cascade_name = "/usr/local/share/OpenCV/lbpcascades/lbpcascad e_frontalface.xml"; static string eyes_cascade_name = "/usr/local/share/OpenCV/haarcascades/haarcasc ade_eye_tree_eyeglasses.xml"; //String to create POST message static string man = "gender=man&nPersons=1&HK="; static string woman = "gender=woman&nPersons=1&HK="; static string crowed = "gender=crowed&nPersons=1&HK="; static static static static string length; string space = "\r\n\r\n"; string content, contentSend; int lengthContent; static const char* httpRequest1; static const char* httpRequest2; static const char* httpRequest3; static string httpRequest = "POST /xibocms/listener.php HTTP/1.1\r\n" "Host: dcn402.asuscomm.com \r\n" "Content-Type: application/x-www-formurlencoded\r\n" "Content-Length: "; // Can move to Main functions // begin -static Ptr model = createLBPHFaceRecognizer(); // Load Database trained //model->load("database_gender.xml"); //Create model to recognize Face // Detect Face to recognize static CascadeClassifier face_cascade; //face_cascade.load(face_cascade_name); static CascadeClassifier eyes_cascade; //eyes_cascade.load(eyes_cascade_name) //if (!face_cascade.load(face_cascade_name)) // printf(" (!)Error loading\n"); //if (!eyes_cascade.load(eyes_cascade_name)) // printf(" (!)Error loading\n"); //lbph_cascade.load(face_cascade_name); // Check for invalid input // end //============================================== // Main Function int main() { // Preprocessing for recognize face model->load("database_gender.xml"); face_cascade.load(face_cascade_name); eyes_cascade.load(eyes_cascade_name); //===================== //Socket to receive Image int sockfd, newsockfd, pid; socklen_t clilen; // For Local Network int portno = 22222; // For DCN Cloud //int portno = 20222 struct sockaddr_in serv_addr, cli_addr; sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) perror("ERROR opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding"); listen(sockfd, 10); clilen = sizeof(cli_addr); for (;;) { idImage++; newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) { perror("ERROR on accept"); exit(1); } // Create child process pid = fork(); if (pid < 0) { perror("ERROR on fork"); exit(1); } if (pid == 0) { /* This is the client process */ close(sockfd); receiveImage(newsockfd, idImage); exit(0); } else { close(newsockfd); } } } return 0; //============================================== void receiveImage(int newsockfd, int idimage) { //idImage++; cout

Ngày đăng: 14/05/2017, 06:54

TỪ KHÓA LIÊN QUAN

w