OPENCV's java,c++ development environment configuration

Source: Internet
Author: User

1.OpenCV Download and installation configuration

OPENCV: http://opencv.org/downloads.html

Latest Version: opencv3.0.0

Note: The supported visual studio2013

We can download stable version: opencv2.4.11

Install: Double-click opencv-2.4.11 to extract to a directory

Configuration: In the System environment variable path, add the appropriate path.

32-bit add: C:\opencv\opencv2.4.11\build\x86\vc10\bin

64-bit additions: C:\opencv\opencv2.4.11\build\x86\vc10\bin and C:\opencv\opencv2.4.11\build\x86 \vc10\bin

2.VisualStudio OpenCV Commissioning

Create a new console program

Follow the navigation step by step to complete the project creation

Configuration item's include directory, point to the installation directory for OPENCV, as shown in

The configuration project relies on the Lib directory and the dependent libraries, as shown in

After the environment is configured, write the test code.

#include"stdafx.h"#include<opencv2/opencv.hpp>#include<iostream>#include<fstream>#include<sstream>#include<math.h>voidTrain_and_test_lda () {stringFn_csv =string("At.txt"); //string fn_csv = String ("Feret.txt");Vector<mat>allimages,train_images,test_images; Vector<int>Alllabels,train_labels,test_labels; Try{read_csv (fn_csv, Allimages, alllabels); } Catch(cv::exception&e) {Cerr<<"Error Opening file"<< Fn_csv <<". Reason:"<< e.msg <<Endl; //There's a problem with the file, we can't do anything, quit.Exit1); }    if(Allimages.size () <=1) {        stringError_message ="This demo needs at least 2 images. Add more images to your data set!";    Cv_error (Cv_stserror, error_message); }     for(intI=0; I<allimages.size (); i++) equalizehist (Allimages[i],allimages[i]); intPhotonumber =allimages.size ();  for(intI=0; I<photonumber; i++)    {        if((I%g_photonumberofoneperson) <g_howmanyphotofortraining)            {Train_images.push_back (allimages[i]);        Train_labels.push_back (Alllabels[i]); }        Else{test_images.push_back (allimages[i]);        Test_labels.push_back (Alllabels[i]); }    }    /*ptr<facerecognizer> model = Createeigenfacerecognizer ();//define PCA Models Model->train (Train_images, Train_ labels);//training PCA model, here the model contains all eigenvalues and eigenvectors, no loss of Model->save ("eigenface.yml");//Save training results for use in testing*/Ptr<FaceRecognizer> Fishermodel =Createfisherfacerecognizer (); Fishermodel->train (Train_images,train_labels);//training Fishermodel with saved, reduced-dimensional images, and the contents of the back are nothing like the original code.Fishermodel->save ("fisherlda.yml"); intIcorrectprediction =0; intPredictedlabel; intTestphotonumber =test_images.size ();  for(intI=0; i<testphotonumber;i++) {Predictedlabel= fishermodel->predict (test_images[i]); if(Predictedlabel = =test_labels[i]) icorrectprediction++; }    stringResult_message = Format ("Test Number =%d/actual Number =%d.", Testphotonumber, icorrectprediction); cout<< Result_message <<Endl; cout<<"accuracy ="<<float(icorrectprediction)/testphotonumber<<Endl;}intMain () {cout<<"LDA ="<<Endl;    Train_and_test_lda (); return 0 ;}

After the compilation is passed, the normal operation instructions OPENCV the environment is configured correctly.

3.Eclipse OPENCV Development Environment Configuration

In Eclipse, create a new Java project, as shown in

After the new success, modify the project's build path to add an external jar, as shown in

Select C:\opencv\Opencv2.4.11\build\java\opencv-2411.jar

Open Opencv-2411.jar, select Native Library location, click Edit

32-bit system pointing to: C:\opencv\opencv2.4.11\build\java\x86

64-bit system pointing to: C:\opencv\opencv2.4.11\build\java\x64

Write the test code:

Import Org.opencv.core.Core; Import Org.opencv.core.CvType; Import Org.opencv.core.Mat;  Public class TESTOPENCV {    publicstaticvoid  main (string[] args)       {          System.loadlibrary (core.native_library_name);           = Mat.eye (3, 3, CVTYPE.CV_8UC1);          " Mat = "+ mat.dump ());}       }

The run output is as follows, i.e. the environment is configured correctly:

OPENCV's java,c++ development environment configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.