Ask Your Question

x's profile - activity

2013-09-23 03:04:26 -0500 answered a question OpenCV to Java Desktop beginning a simple face detection and recognition project

I use OpenCV with JavaFX and I'm blogging every now and then about this topic.

2013-09-22 17:47:02 -0500 received badge  Supporter (source)
2013-09-22 17:30:45 -0500 received badge  Editor (source)
2013-09-22 17:22:58 -0500 commented answer Opencv java - Load image to GUI

cool! this is faster than HighGui.imencode(".png",mat,memory) I was using until discovering this post.

2013-09-22 15:25:13 -0500 answered a question how to prevent unsatisifiedLinkError in java web application?

native libs should be loaded only once per lifetime of the JVM.

thus, make sure that System.load("...dll") is only called once per lifetime of the uptime of your webserver. the need of loading the dll can be tested by calling a function of opencv like Core.getCPUTickCount - if it throws an UnsatisfiedLinkError you have to load it, otherwise you dont.

2013-09-22 15:19:46 -0500 answered a question How to display image on JAVA release

Use JavaFX to display results of your Image processing. I've created a series of blog posts which describe programs which use JavaFX' ImageView to display openCV results.

2013-09-22 14:34:08 -0500 answered a question which class can show an image in java?
val mat = Highgui.imread("some.png")
val memory = new MatOfByte
Highgui.imencode(".png", mat, memory)
new Image(new ByteArrayInputStream(memory.toArray()))

This gives you an javafx.scene.image.Image which can happily be used in JavaFX based applications.

A more involved, albeit faster method is the one described a similar question in this forum.

Below I'll give you source code to convert a Mat to an Image using this approach:

def toImage(matrix: Mat): Image = {
val cols = matrix.cols();
val rows = matrix.rows();
val elemSize = matrix.elemSize()
val data: Array[Byte] = new Array[Byte](cols * rows * elemSize.toInt)

matrix.get(0, 0, data)

val lType = matrix.channels() match {
  case 1 => BufferedImage.TYPE_BYTE_GRAY
  case 3 => {
    // bgr to rgb
    for (i <- 0 until data.length by 3) {
      val b = data(i)
      data(i) = data(i + 2)
      data(i + 2) = b
    }
    BufferedImage.TYPE_3BYTE_BGR
  }
  case 4 => {
    for (i <- 0 until data.length by 4) {
      val b = data(i)
      data(i) = data(i + 2)
      data(i + 2) = b
    }
    BufferedImage.TYPE_4BYTE_ABGR
  }
  case _ => sys.error("unsupported")
}

val image = new BufferedImage(cols, rows, lType)
image.getRaster().setDataElements(0, 0, cols, rows, data)
SwingFXUtils.toFXImage(image, null)

}

2013-09-22 14:28:19 -0500 answered a question ebooks opencv java

I've created some blog posts about using OpenCV on the JVM using Scala and JavaFX, maybe this is of some help for you.

2013-09-22 14:24:07 -0500 answered a question how do i create a runnable jar that use opencv

It's about distributing the dll / dylib which matches your OS and JDK. You have to deliver opencv_xxx.dll with your application and make sure you load the libs by System.load("/path/to/dll") before the first call to a opencv function.

2013-09-22 14:13:31 -0500 answered a question capture image to slow with java
val vc = new VideoCapture(0)  // expensive operation
vc.read(new Mat())  // runs fast (< 1ms)

I'm not releasing the camera in the video grabbing loop, since it would close the image stream and I would have to reconnect to the camera.

Initializing and starting up the camera takes more time (on my system about 2 sec (!) - so make sure your call to new VideoCapture(0) is made only once.

2013-09-22 13:45:20 -0500 answered a question opencv-2.4.4 in java.library.path error

Either you provide the right dll in the path where you start the application, you provide the java.library.path on startup (for example with a startup script), or you set an absolute path to the dll in your source code (not really recommended for production apps ;-) )

if you use an IDE like Eclipse - they all have separate means of setting the library path, for example for eclipse see

http://stackoverflow.com/questions/957700/how-to-set-the-java-library-path-from-eclipse

Thus, just to get started, you can write in your program the call to the System.load(...) method like this:

System.load("c:/my/path/to/the/opencv_lib.dll")
2013-09-22 13:34:45 -0500 answered a question Packaging OpenCV with a Java Program

AFAIK you must deliver the dll or dylib separately. That means that you need to distribute your jar file and the native lib.

You will need an installer which packages the native libraries along with your jar files and other resources. Probably you'll also want to deliver your own JRE with it. Installers like install4J (commercial) or NSIS (free, windows) can be of help for this task.

You have to make sure that you install the right native library on the target system (x86 vs x64).

2013-05-03 00:01:14 -0500 answered a question real time face tracking java

This page shows how to grab the webcam image and apply face recognition on it using JavaFX and Scala - maybe of help.

2013-05-02 23:50:44 -0500 answered a question imshow equivalence in Java

Hi,

I've implemented a simple GUI using JavaFX which shows a Mat datastructure using JavaFX facilities. The trick is to convert the Mat to a ByteArray:

  def mat2Image(mat: Mat): Either[Exception,Image] = {
      val memory = new MatOfByte
      try {
            Highgui.imencode(".png", mat, memory)
            Right(new Image(new ByteArrayInputStream(memory.toArray())))
      } catch {
        case e  : Exception => Left(e)
      }
    }