Created
March 25, 2020 14:10
-
-
Save skanga/547b3afa4235fe4ab159e5cb062f46a7 to your computer and use it in GitHub Desktop.
Build OpenCV (with Java) from git sources on Ubuntu Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install OS tools needed for the build | |
sudo apt-get -y update | |
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev ant default-jdk | |
# Detect the default java home and set the env var for it | |
export JAVA_HOME=$(java -XshowSettings:properties -version 2>&1 > /dev/null | awk -F' ' '/java.home/ {print $3}') | |
export ANT_HOME=/usr/bin/ant | |
git clone https://github.com/opencv/opencv | |
cd opencv/ | |
mkdir build | |
cd build | |
cmake -D BUILD_SHARED_LIBS=OFF .. | |
make -j$(nproc) | |
# Create a test program in Java | |
cat << EOF > ./HelloCV.java | |
import org.opencv.core.Core; | |
import org.opencv.core.CvType; | |
import org.opencv.core.Mat; | |
public class HelloCV | |
{ | |
public static void main (String[] args) | |
{ | |
System.loadLibrary (Core.NATIVE_LIBRARY_NAME); | |
Mat mat = Mat.eye (3, 3, CvType.CV_8UC1); | |
System.out.println ("mat = " + mat.dump()); | |
} | |
} | |
EOF | |
# Detect the OpenCV jar file name | |
OPENCV_JAR=$(ls bin/opencv-*.jar) | |
# Build and run the test | |
javac -cp .:$OPENCV_JAR HelloCV.java | |
java -cp .:$OPENCV_JAR -Djava.library.path=lib HelloCV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment