Configuring the OPENCV Java Development environment in IntelliJ idea 13

Source: Internet
Author: User
Tags scalar

Preparatory work:

    1. Download Idea 13 (here, for example, version 13, hereafter referred to as idea);
    2. Download Java JDK (for configuring the Basic Java Development environment);
    3. Download OpenCV 2.4.9 (Here's an example of version 2.4.9, according to this article, the 2.4 version of OPENCV began to support the Java API interface);
    4. Install idea;
    5. Install the JDK and configure the JDK in idea;
    6. Unzip the downloaded OpenCV 2.4.9 to a directory, for example, the extracted path is "D:\OPENCV", which contains the build folder and the source folder.

To configure the development environment:

1) Create a new generic Java project in idea, named "Learningopencv".

2) Open the Project Structure window and you can use the Ctrl+alt+shift+s shortcut or open it via the menu "File->project Structure".

3) Look to the left side of the Project Structure window, find "Libraries" and click. Click After, as shown in.

4) Add the OpenCV library. Click the "+" sign above the "Project Structure" window and select "Java". Select the Java class for OpenCV ("D:\opencv\build\java\opencv-249.jar") via the popup dialog box. As shown in.

Click "OK" to form.

Click "OK" to close the dialog box.

5) Set up the test code. Create a new Java class under the SRC directory named "Opencvjavatest". Write the test code further.

1 ImportOrg.opencv.core.Core;2 ImportOrg.opencv.core.CvType;3 ImportOrg.opencv.core.Mat;4 ImportOrg.opencv.core.Scalar;5 6 /**7 * Created by better on 2014/10/4.8  */9  Public classopencvjavatest{Ten  One     Static{system.loadlibrary (core.native_library_name);} A  -      Public Static voidMain (string[] args) { -System.out.println ("Welcome to OpenCV" +core.version); theMat m =NewMat (5, CVTYPE.CV_8UC1,NewScalar (0)); -System.out.println ("OpenCV Mat:" +m); -Mat MR1 = M.row (1); -Mr1.setto (NewScalar (1)); +Mat MC5 = M.col (5); -Mc5.setto (NewScalar (5)); +System.out.println ("OpenCV Mat data:\n" +m.dump ()); A     } at}

Run the main function to see what happens after the run. A link error occurred (DLL not found).

Exception in thread "main" Java.lang.UnsatisfiedLinkError:no opencv_java249 in Java.library.path .

Fix the error below.

6) Configure run-time parameters. Open the Run/debug Configurations dialog box from the toolbar () or the menu "Run->edit configurations ...".

On the right side of the dialog window, locate the text box for the VM Options tab. As shown in the Red Arrows.

In the text box, fill in the parameters, "-djava.library.path=d:/opencv/build/java/x86;D:/opencv/build/x86/vc12/bin". Note that the directory to be filled in should be the relative directory that was generated when the OPENCV was decompressed. Fill in the following.

7) Run the test code and observe the program output.

Welcome to OpenCV 2.4.9.05*10*cv_8uc1, iscont=true, issubmat=false, nativeobj=0x4b5b868, Dataaddr=0x4b5eeb0 ]opencv Mat data:[0, 0, 0, 0, 0, 5, 0, 0, 0, 0;   1, 1, 1, 1, 1, 5, 1, 1, 1, 1;   0, 0, 0, 0, 0, 5, 0, 0, 0, 0;   0, 0, 0, 0, 0, 5, 0, 0, 0, 0;   0, 0, 0, 0, 0, 5, 0, 0, 0, 0]

8) end.

Further reading:

1) OpenCV's Java API official online documentation.

2) OPENCV's official Java Development Guide.

3) OpenCV's official website.

Configuring the OPENCV Java Development environment in IntelliJ idea 13

Related Article

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.