How to Use OpenCV with Java under NetBeans IDE كيف تستخدم أوبن سيفي عبر جافا في النات بينز



In this Tutorial we will start working with the OpenCV with Java using the NetBeans IDE, so before starting, you need to know how to use NetBeans and how to program JAVA using it. 

Download OpenCV: link
in the test of this article we are using windows 10 so we downloaded the exe file of openِCV: link but for you, you have to login to the link on top to get the last version's file.


After Downloading and installing Netbeans, OpenCV and Java JDK you need to:

1- Create a Project (java project):





2- Add the lib's:

Step 1: Add Library

Select Libraries from netbeans project, right Click on Libraries, click "Add Library". Select Libraries> right click Libraries>Click Add Library.


Step 2: Create Library

Click on "Create" button to create new library. Enter the Library Name as "OpenCV2.4.8". Click on "OK" Button.


Step 3: Customize Library

Select Classpath tab to add class path. Click on "Add JAR/Folder" to add class path. Select file path "c:\opencv\build\java\opencv-248.jar". Click on "OK" button.



Step 4: Add Library

Select Configured library as,"opencv2.4.8". Click on "Add Library" button to add library to project work space.



Step 5: Project Properties

Select project, right click on "Properties". Select "Run" option, Change VM options to add native library "-Djava.library.path="C:\opencv\build\java\x86"". If you have a 32-bit system, you need to select the x86 folder instead of x64.


2- Add the lib's:

Look at the fist code ():


package creating_and_displaying_the_matrix;

import org.opencv.core.*;

/**
 *
 * @author Walid Amriou
 */
public class Creating_and_Displaying_the_Matrix {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        //Loading the core library 
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        
        //Creating a matrix 
        Mat matrix = new Mat(5, 5, CvType.CV_8UC1, new Scalar(0));
        
        //Retrieving the row with index 0 
        Mat row0 = matrix.row(0); 
     
        //setting values of all elements in the row with index 0 
        row0.setTo(new Scalar(1)); 
     
        //Retrieving the row with index 3 
        Mat col3 = matrix.col(3);  
     
        //setting values of all elements in the row with index 3 
        col3.setTo(new Scalar(3));
        
        //Printing the matrix 
        System.out.println("OpenCV Mat data:\n" + matrix.dump()); 
        
        
    }
    
}

Mookhtabar team tested it in Windows 10 in 17/10/2018 at 16:30 :


Source: link

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel