locked-fg / JFeatureLib

Free Java library for image features and point/region detectors used in ComputerVision
38 stars 14 forks source link

Missing log4j dependency for SURF with scala/sbt #29

Open samos123 opened 8 years ago

samos123 commented 8 years ago

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.(IJFacade.java:41) at de.lmu.ifi.dbs.jfeaturelib.features.SURF.run(SURF.java:97) at Surf$delayedInit$body.apply(Surf.scala:20) at scala.Function0$class.apply$mcV$sp(Function0.scala:40) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.collection.immutable.List.foreach(List.scala:318) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32) at scala.App$class.main(App.scala:71) at Surf$.main(Surf.scala:14) at Surf.main(Surf.scala) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 12 more

locked-fg commented 8 years ago

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,

samos123 commented 8 years ago

Thanks for confirming it's working as expected I will try to switch to Java and report back :)

samos123 commented 8 years ago

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

samos123 commented 8 years ago

@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 :)

locked-fg commented 8 years ago

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 ;-)