Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use OpenCV with IntelliJ IDEA 12

I'm trying to use IntelliJ IDEA 12 to develop OpenCV 2.4.5 applications in Java. I've followed the instructions for Eclipse from the website here.

The problem I am running into is that I can add the jar to my library but I don't know how to add the natives to my classpath.

like image 881
Cadel Watson Avatar asked May 07 '13 06:05

Cadel Watson


1 Answers

First install Chocolatey via PowerShell by The Following command

Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iwr https://community.chocolatey.org/install.ps1 -UseBasicParsing | iex

After chocolatey installation

choco install opencv

The Above command will install the opencv latest version available

You will need to manually create an OPENCV_DIR environment variable then add %OPENCV_DIR%\bin to your PATH.Environment setup AFter this just add The following Maven dependencies

 <dependencies>
    <dependency>
        <groupId>org.openpnp</groupId>
        <artifactId>opencv</artifactId>
        <version>4.5.1-2</version>
    </dependency>
</dependencies>

Then add this piece of code ;

 OpenCV.loadLocally();

and boom it will work hunky dory!!!!

Bellow code snipet is to test .

 OpenCV.loadLocally();
    System.out.println("Welcome to OpenCV " + Core.VERSION);

    Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
    System.out.println("OpenCV Mat: " + m);
    Mat mr1 = m.row(1);
    mr1.setTo(new Scalar(1));
    Mat mc5 = m.col(5);
    mc5.setTo(new Scalar(5));
    System.out.println("OpenCV Mat data:\n" + m.dump());
like image 140
Shubham Chakraborty Avatar answered Oct 02 '22 08:10

Shubham Chakraborty