Missing log4j dependency for SURF with scala/sbt
I'm trying to extract Surf features without success. It seems it's missing a log4j dependency.
The code that I'm using:
import de.lmu.ifi.dbs.jfeaturelib.features.SURF
import ij.process.ColorProcessor;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import javax.imageio.ImageIO;
/**
* Example of extracting SURF features from section "Detecting the scale-invariant SURF features" in chapter 8.
*/
object Surf extends App {
// Read input image
val f = new File("test.jpg");
val image = new ColorProcessor(ImageIO.read(f));
val descriptor = new SURF();
descriptor.run(image);
val features = descriptor.getFeatures();
println(features);
}
build.sbt
name := "opencv2-scala-test"
organization := "samos"
exportJars := true
// Some dependencies like `javacpp` are packaged with maven-plugin packaging
classpathTypes += "maven-plugin"
libraryDependencies ++= Seq(
// "de.lmu.ifi.dbs.jfeaturelib" % "JFeatureLib" % "1.6.3",
"gov.nih.imagej" % "imagej" % "1.47"
)
libraryDependencies += "org.apache.logging.log4j" % "log4j-core" % "2.5"
libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % "2.5"
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.13"
Error that's seen:
java -jar opencv2-scala-test-assembly-0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at de.lmu.ifi.dbs.jfeaturelib.features.surf.IJFacade.
HI, just tested it with plain Java and a call from the commandline
public class SurfDemo {
public static void main(String[] args) throws IOException, URISyntaxException {
// load the image
InputStream stream = SurfDemo.class.getClassLoader().getResourceAsStream("test.jpg");
ColorProcessor image = new ColorProcessor(ImageIO.read(stream));
// initialize the descriptor
SURF descriptor = new SURF();
// run the descriptor and extract the features
descriptor.run(image);
// obtain the features
List<double[]> features = descriptor.getFeatures();
// print the features to system out
for (double[] feature : features) {
System.out.println(Arrays2.join(feature, ", ", "%.5f"));
}
}
}
Works without errors. Any Idea? Otherwise I tend to think it's a sbt issue,
Thanks for confirming it's working as expected I will try to switch to Java and report back :)
It's working like you said. So it seems related to sbt / scala..
I've updated the repo jFeatureLib examples to fix some issues and add the surf demo there: https://github.com/locked-fg/JFeatureLib-Demo/pull/1
@locked-fg I'm opening it again as I can reproduce the issue in my repo: https://github.com/samos123/scala-feature-extraction
When using maven to build the scala project everything works as expected but when using sbt it fails with the log4j class not found exception.
I will be sticking with Maven for now but may investigate more into this later on. Any feedback would be appreciated :)
Thanks for your energy in that point. I'm trying to find a colleague who's willing to invest some energy ( @muuki88 - if you feel bored, feel free to join ;-)