I am writing a lambda function in Java ad want to use the opencv library. I am having a hard time understanding how to set it up. Please help. I can set it up just fine locally but I am really confused about the lambda part.
Edit: To be precise I am having trouble with System.LoadLibrary() function. The dll is in the project files but lambda cannot find it.
Opencv is dependent on underlying OS library files. For windows we need to have opencv_javaXXX.dll file and for windows we need libOpencv_javaXXX.so file (where XXX is the opencv version). In case if you don't have these files please generate using this link http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html
AWS lambda basically uses an AMI name: amzn-ami-hvm-2016.03.3.x86_64-gp2. This is a 64 bit linux machine. To get the libOpencv_javaXXX.so I spinned up an EC2 instance using AMI name: amzn-ami-hvm-2016.03.3.x86_64-gp2 (This is a public AMI on amazon) and installed opencv for java on this machine.
Once you have libOpencv_javaXXX.so , add it to classpath (I added it to src/main/resources) and then use following code to load it from JVM process.
System.load(new ClassPathResource("/libopencv_javaXXX.so").getFile().getAbsolutePath());
System.LoadLibrary() loads the library from java lib path and System.Load() will load the native library from the absolute path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With