Sunday, September 22, 2013

Color Extractor

While almost all of my JavaFX friends are somewhere in SF attending a small, unknown Java conference I have refined the code of the Color Extractor application (formerly known as HSV Adjuster). ;-)

Here is a screencast showing the application in action:




Here is a screenshot:



In short, the application now combines the input signal with the HSV mask you can create using the three sliders. The application writes this information into the alpha channel of the input image stream, resulting in pictures like above.

The neat thing is that the image stream is taken from your webcam, and thus it is an interactive way to explore the effects of different settings.

This solves also the greatest shortcoming of the HSV Adjuster application, which didn't yet combine the alpha information with the input image but only showed the alpha channel in black and white. The latter has its own aesthetic appeal, but I think the color extractor application better shows the original intend I had.

Implementation Notes:


The application is written in Scala, the GUI Frontend was done in JavaFX and the image processing works with OpenCV by using its Java bindings. OpenCV can split each color channel (RGB) and combine it with alpha channel information (see the alphaBlend method in the source code below).

The conversion of OpenCV Mat data to images which can be displayed by ImageView components is done by the toImage function - in contrast to earlier versions of my Webcam API layer I'm using the approach discussed here - this optimization speeds up the application considerably.


Source code of the application is available here. Below you can find the source of the main application for fast reference.

Guys, I wish you a nice time in SF and hope we'll see stunning new work for the JVM platform.





2 comments:

  1. I too am learning OpenCV with Scala and ScalaFX.
    Do you have any tips? I'm having trouble, given ScalaFX's very limited documentation and examples that are all over the board.

    ReplyDelete
    Replies
    1. You can follow the OpenJFX mailing list or @JavaFXpert on twitter for staying up to date with JavaFX development, as well as @fxexperience which gives you a weekly update about JavaFX related news.

      As far as Scala and JavaFX is concerned: you have to keep in mind that Scala + JavaFX is not the same as ScalaFX. ScalaFX is more like a DSL for creating UIs with the underlying JavaFX technology.

      The source code for this article (and most of the other posts as well) is plain Scala.

      I think you can get best results if you stay in a JVM Language where you are comfortable with and get proficient with JavaFX. After this it is easier to combine JavaFX with lets say Scala or Clojure for example. As for learning Scala, at the time of writing this comment there is a free online course on Coursera, which will definitely help you get to speed with Scala.

      Delete