I'am under ubuntu 20.04
here is my gradle settings :
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation "joda-time:joda-time:2.2"
implementation "junit:junit:4.12"
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.apache.commons:commons-lang3:3.5'
testImplementation 'junit:junit:4.13'
implementation 'org.apache.logging.log4j:log4j-api:2.18.0'
implementation 'org.apache.logging.log4j:log4j-core:2.18.0'
implementation "nu.pattern:opencv:2.4.9-7"
}
And my App.java :
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package silentevil;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import nu.pattern.OpenCV;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.videoio.VideoCapture;
public class App {
public static void loadOpenCVNativeLibrary() {
nu.pattern.OpenCV.loadShared();
//nu.pattern.OpenCV.loadLocally();
}
public String getGreeting() {
return "Hello World!";
}
public static void main(String[] args) {
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());
System.out.println(new App().getGreeting());
}
}
Without the import org.opencv.imgcodecs.Imgcodecs; and the import org.opencv.videoio.VideoCapture;
It works but i would like to test the webcam.
I have these errors :
App.java:21: error: package org.opencv.imgcodecs does not exist
import org.opencv.imgcodecs.Imgcodecs;
^
App.java:23: error: package org.opencv.videoio does not exist
import org.opencv.videoio.VideoCapture;
How can in install theses libs or why are they not included ?
edit :
I've also tried to import a compiled jar with gradle :
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation "joda-time:joda-time:2.2"
implementation "junit:junit:4.12"
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.apache.commons:commons-lang3:3.5'
testImplementation 'junit:junit:4.13'
implementation 'org.apache.logging.log4j:log4j-api:2.18.0'
implementation 'org.apache.logging.log4j:log4j-core:2.18.0'
//implementation "nu.pattern:opencv:2.4.9-7"
implementation files('lib/opencv-460.jar')
}
i've changed my code also :
package silentevil;
//import nu.pattern.OpenCV;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.videoio.VideoCapture;
public class App {
public static void loadOpenCVNativeLibrary() {
//nu.pattern.OpenCV.loadShared();
//nu.pattern.OpenCV.loadLocally();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public String getGreeting() {
return "Hello World!";
}
public static void main(String[] args) {
//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());
System.out.println(new App().getGreeting());
}
}
but when i do the import jar with gradle i have this error :
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long org.opencv.core.Mat.n_Mat(int, int, int, double, double, double, double)'
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.<init>(Mat.java:77)
at silentevil.App.main(App.java:40)
regards