Friday, March 4, 2016

Processing and OpenCV for Video Movement Detection

Hi everybody!

Find below a little experiment done with Processing and OpenCV for Processing to detect movement in a Camera-Video-Stream. I put together the Capture Sample from Processing and the Contour Sample from OpenCV for Processing (https://github.com/atduskgreg/opencv-processing/blob/master/examples/BackgroundSubtraction/BackgroundSubtraction.pde) to achieve this.

import gab.opencv.*;

import processing.video.*;

Capture cam;
OpenCV opencv;

int lastContourRefresh = millis();
int contourRefreshTreshold = 100000;

void setup() {
  size(1280, 720);

  opencv = new OpenCV(this,1280, 720);
  opencv.startBackgroundSubtraction(2,3,0.5);

  String[] cameras = Capture.list();
  
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    
    // The camera can be initialized directly using an 
    // element from the array returned by list():
    cam = new Capture(this, cameras[0]);
    println("chosen cam: " + cameras[0]);
    cam.start();     
  }      
}

void draw() {
  
  if(cam.available()) {
     cam.read();
  }
  
  image(cam, 0, 0);

    try {
         opencv.loadImage(cam);
    } catch (RuntimeException e ) {
      
    }
    opencv.updateBackground();
    opencv.dilate();
    opencv.erode();
    
    noFill();
    stroke(255, 0, 0);
    strokeWeight(3);
    
    for (Contour contour : opencv.findContours()) {
      contour.draw();
    }
    
    lastContourRefresh = millis();
}

Wednesday, July 22, 2015

Jira Mylyn Connector for Eclipse Mars

For all of you who use Jira with Mylyn and just switched to Eclipse Mars: there is actually no Jira-Connector available if you ask for in the Mylyn Repository-Dialog. So you have to install it for your own by adding the update-site: http://update.atlassian.com/atlassian-eclipse-plugin/rest/e3.7

Even if the connector is supposed to be used up to Eclipse Luna it also works with Eclipse Mars.

Wednesday, April 29, 2015

Testing AngularJS Services with Jasmine

If you write unit test for your angularjs application you may already read the documentation provided by the angularjs website. It has a lot of good information but i missed the description of how to test services that i wrote for my application. For angularjs services the jasmine setup code looks like:

beforeEach(inject(function(_$controller_){
    $controller = _$controller_;
  }));


The _$controller_ is an internal representation of the angularjs controller service, $controller is a local variable.

So, how does injecting of a custom service work? Well, it is easy...

beforeEach(inject(function(_YourService_){
    $localService = _YourService_;
  }));


And the service code:
yourAppServices.factory('YourService', [function($http, ESCommons) {
  return {...}]);

Monday, April 27, 2015

Voxxed - News for Java Developers

If you are looking for the latest news about Java and Web-Technologies you might want to have a look at voxxed.com! This site presentates a lot of information about Java and similiar topics (Grooovy, JavaScript, BigData).

Saturday, April 4, 2015

Javaland 2015 - Day 2

Better late then never here it is, my summary of our second day at Javaland 2015 :-)!

After a first day with a lot of interesting talks and fantastic rides with the Black Mamba we started day 2 at Javaland. This day came up with a lot of JavaFX talks. Perfect, because the last Project at work made heavy use of JavaFX. So i decided to take a look how other programmers work with JavaFX.

Hendrik Ebbers from Canoo and Alexander Casall (Saxonia AG) started after the Keynote with "Enterprise Applications with JavaFX". They gave an overview how to build JavaFX Applications that communicate with JEE Backend Systems and gave some best practice tips how to bind data models to their corresponding view (Model-View-View-Model Pattern), and how to synchronize views between two instances of one JavaFX Application. Theyalso mentioned some interessting JavaFX Libraries that addresses the named Topics:


Well, as you can see, Java Developers are not very creativ when inventing a Name for a library ;-)

IoT

Another big Topic at day two was IoT - Internet of things. Maybe you did not know this term you probably get in touch with it. Since not even Computers and Smartphones but also TVs, Refrigerators, Watches and lot more devices can connect to the Internet we talk about the IoT. To get an easy introduction into that Topic i decided to watch "IoT Magic Show" with Stephen Chin (yeah, the men with the Motorcycle :-) ). Stephen and a colleague explained IoT with the help of three Magic tricks. The most impressing one was the first one. Three People from the audience had to choose one gamingcard and Stephens colleague had to guess what gaming they had choosen. As you might guess he guessed right every Card!
The trick mainly based on an really tiny RFID-Chip inside every Card. With a Little RFID detector hidden in his Hand, he hovered over the Card with the face down. The RFID-Chip transmitted the type of the Card to the detector. Over a Network the result was transmitted to a RasberryPI and finally send to Google Glasses.
That showed how Network capable devices can communicate with each other.

2048

Need a break after a lot of reading? How about playing 2048 to relax? If you don't know 2048 the game you may want to checkout http://gabrielecirulli.github.io/2048/. It is fun and easy to learn!

Bruno Borges and a colleague showed their implementation of 2048 with JavaFX in the next talk. They covered how they did the databinding, the design and the animations with JavaFX to achieve the typical 2048 Feeling. Finally they introduced the port to Android Devices, done with JavaFXPort (http://www.javafxports.org/page/home). You can find the app in the Play-Store https://play.google.com/store/apps/details?id=org.jpereda.game2048

Groovy Traits

A less visited talk but not less interessting was "Traits and their usage inside groovy" by Jochen Theodorou. Jochen talked about the reason why they invented and implemented traits and why it is better to use traits then mixins.
With a lot of examples he showed use cases and best practices.

Projector Pattern

Finally we visited "Efficency and Flexibility of the projector pattern" by Dierk König. Maybe you don't know the pattern it is very likely that you already used this pattern when you programmed some GUI Application. In short words the projector pattern is when you work with an API that describes what the GUI should Display, but not how things are displayed. For this reason you use a Projector and only the projector knows how to Display GUI Elements.

Tuesday, March 31, 2015

Orbit, a new Akka competitive

Bioware the developer of a lot of famous Computer Games announced an Open Source Project for distributed Applications. This project is used by Bioware itself for there Systems, written in Java and distributed with a BSD Licence.
If you know Akka you instantly feel at home when looking at Orbit and its Documentation. So go on and start into the orbit from https://github.com/electronicarts/orbit ;-)

Sunday, March 29, 2015

Javaland 2015

Javaland 2015


It is only a few days since a colleague of mine and i went to Javaland in Phantasialand near Brühl, so it is not to late to give you a summary of the talks i visited. Hope you enjoy :-)

Day 1

Day 1 started with "Lambdas and Streams, Functional Programming with JDK 8" by Simon Ritter. Even for those that were familiar with Lambdas and Streams Simon came up with some best practices using these new Technologies. He highly recommended to avoid using for-each and showed code examples how to do that while working with streams.

Next there was "Understanding Java Bytecode" with Rafael Winterhalter. He started with an introduction to Java Bytecode so everybody got an idea what that is and how you can use it to enhance your application. In the second part of his talk he introduced his ByteCode Framework "Byte Buddy". Byte Buddy has a fluent pattern based API to generate code during runtime. Check it out on http://bytebuddy.net

For all fans of NoSQL DBs Stefan Hochdörfer had a very interesting talk where he showed how to use PostgreSQL Features to mimic some NoSQL DB behavior. This can be done using one or more in combination of the following PostgreSQL Data types:
  • Arrays
  • hstore
  • JSON / JSONB
  • XML
With a ton full of examples he showed how to access fields of these types and how to manipulate them. It was very interesting to see how to access Array fields or JSON fields in one select Statement. You can find the PowerPoint at http://t.co/Qq9VsG7ugz

Even we visit JAVAland Javascript was subject of a lot of talks. So of "TypeScript, Javascript für Java-Entwickler" ("TypeScript, JavaScript for Java-Developers") by Kai Tödter. TypeScript is developed by Microsoft under an OpenSource Licence and brings known OO Features to Javascript. For more Information and Demos visit http://www.typescriptlang.org/.

After lunch we did a deep dive,  Daniel Mitterdorfer explained in "Make or Break: The Big Impact of Small Changes in Performance" how small changes in Java Code can influence or even break CPU Functionalities like CPU Caches and Branch Predictions. For Performance analysing he used JMH (http://openjdk.java.net/projects/code-tools/jmh/) that showed the differences after small changes. You can find his slides here: http://daniel.mitterdorfer.name/talks/2015/make-or-break/#/

Because Java Bytecode is fun i visited "Programming Java Bytecode with Jitescript" presented by Joe Kutner. Joe gave an introduction to Java Bytecode and ended with some Demos of Jitescript. Jitescript itself is only meant to create new classes during runtime, modifcation of existing Bytecode is not possible. If you are interested in Frameworks that manipulates or analyse Bytecode you should checkout Byteman, Javaassist or DRGarbage.

Friday, March 6, 2015

Your Project Website on github

You have some projects on github and you need some webspace for a small Project Webpage or generated Software artifacts? Then https://pages.github.com/ is something for you. With a few steps you create a new repository at github that hosts all your webpages. A short description guides you through all necessary steps. Have fun!

Saturday, February 28, 2015

Pitfall during first Steps with Grails

Yesterday we started a coding night at our company with the goal to checkout the benefits of seperated programming of backend and frontend code. We were free in choosing technologies so i decided to use Grails for the backend and Angular.js as the frontend technology. The first tries saving an entity failed and i did not explain it to myself why that was happening. A simple Adress Entity with some fields (name, street etc. ) but saving did nothing. The solution came to me after i enabled the SQL Debug Logging in Grails (open DataSource.groovy and add logSql=true to the dataSource Definition). The logging revealed that all fields were non nullable so inserting failed without an error message. Not really nice by Grails :-)

About the result of my experiments i will inform you later, so check my block.

Friday, January 9, 2015

Debug Information when using Java's Printing Services

If you work with javax.print and want to know which parameters are sent to the printing device use following VM parameter to enable some debug information on standard out:

-Dsun.print.ippdebug=true

Saturday, January 3, 2015

Quick Dependency resolving with Grape

Most of the time i use Groovy with the GroovyShell or as a Groovy-Shell Script (remember my Blog-Post in October). Doing it that way you can achieve a lot with some lines of Groovy Script and the Groovy Standard Library Classes. But what if you need some classes from some third party libraries?
If you run your Groovy Script inside the GroovyShell you can simply modify the file groovy-starter.conf (resides in the conf folder of your GroovyShell installation). Add the classpath to the required library and you are done.
But this can get quite difficult if the library has further dependencies and you did not have these ones. Or you have these dependencies but only as maven dependencies, living in a gigantic maven repo on your local harddrive.
To get around this issue Groovy provides a Maven like mechanism called Grape. Grape does all the dependency resolving for you by doing lookups in well known Maven Repositories. So for example, if you like to have the FTPClient class from org.apache.commons.net in your Groovy Script, add the following Grape Statement:

@Grapes(
    @Grab(group='commons-net', module='commons-net', version='3.2')
)


Then add the import statement for the FTPClient class and you are done! The full script with its overwhelming functionality ;-):

@Grapes(
    @Grab(group='commons-net', module='commons-net', version='3.2')
)
import org.apache.commons.net.ftp.*;

FTPClient ftpClient = new FTPClient();


 If the required dependency does not exist in the repositories known by Grape you can tell Grape where to go to find it. Simply add this statement:

@GrabResolver(name='myrepo', root='http://mymavenrepo.org/')

Grape is "supported" by mvnrepository.com. If you look for a dependency mvnrepository.com tells you the grape-code for instant usage!

Sunday, December 14, 2014

Collada Unmarshaller

Hey everybody! I just pushed my Collada Unmarshaller to github. It simply does unmarshalling with jaxb. Not more!

You find the sources here: https://github.com/laubfall/collada-loader

Wednesday, December 10, 2014

Stackoverflow in JavaFX ChangeListeners

JavaFXs ChangeListeners are an easy way to monitor changes on JavaFX Properties and do some work if a change happened. But as easy as that is you easily can run into a stackoverflow because you'd changed the monitored property inside the ChangeListener.
Imagine you like to sort a Collection every time it is modified. Do sorting inside the ChangeListener raises a Stackoverflow because the sort itself raises a change event. So, how can we prevent that? The answer is simple: remove the ChangeListener before the code that modifies the property and then add it again!

public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pair<String, L>> change){
        change.getList().removeListener(this);
        Collections.sort(change.getList(), comparator());
        change.getList().addListener(this);
    }


In this example we monitor a list and sort it when its content changes.

Saturday, November 15, 2014

JavaFX TabPane and Tab change

At the moment i am working with JavaFX building a little Application that has a lot of configurable parameters. For the reason of not getting lost on a dialog with thousand of different checkboxes, textfields and so on, the parameter controls should be grouped with the JavaFX control TabPane. A TabPane was quickly done but soon i realized that it is not so easy to prevent the user from changing the current tab if the parameters grouped in this tab have invalid values. Instead of switching to the selected tab i rather like to show a validation error message. So i did some reading on the JavaFX API but there is no way out of the box to achieve this behavior. You can do some work if the tab has changed but not before it is changed. If you have a similar issue with the TabPane maybe my solution will work for you :-)

class StateAwareChangeListener implements ChangeListener<Tab>
  {

    /**
     * go to previous tab if validation fails and this flag is true.
     */
    private boolean roleback;

    /**
     * If validation is ok change the tab.
     *
     * {@inheritDoc}
     *
     */
    @Override
    public void changed(ObservableValue<? extends Tab> arg0, Tab arg1, Tab arg2)
    {
      if (roleback) {
        roleback = false;
        return;
      }

      boolean validateConfig = validateIfChangeIsPossible();
      if (validateConfig == false) {
        roleback = true;
        tabPane.getSelectionModel().select(arg1);
      }
    }
  }

This listener calls the method validateIfChangeIsPossible that you have to implement by yourself. If changing the tab is possible return true. If false the old tab is selected again. You can also parse the new tab as a parameter into validateIfChangeIsPossible, if you need the information.

Finally add this class as a ChangeListener to the selectedItemProperty of the TabPane:

tabPane.getSelectionModel().selectedItemProperty().addListener(new StateAwareChangeListener()); 

Friday, October 31, 2014

Execute Groovy as a Shell-Script

A colleague of me told me today that it is possible to run Scala Scripts directly in a shell. Because i am more familiar with Groovy i started some research if it is possible to do this with Groovy as well. To do it short: Yes we can :-) Take a look: http://groovy.codehaus.org/Running

Tuesday, October 28, 2014

JavaFX SceneBuilder or how to add more Cols and Rows to a GridPane

Yeah, i know it sounds simple: add some additional columns and / or rows to a GridPane with the SceneBuilder. Minute over minute i looked at the Properties-View of the GridPane but no way to add columns or rows.
Solution: right click on the GridPane in the hierachy view and simply select what you want to do ;-)


Sunday, October 19, 2014

Android Dependencies in local maven repo

After my last blog you may ask: "what about android dependencies that are not part of public maven repositories? I like to have 4.4.2 but everthing i found was 4.1.1!" Don't worry :-) There is a nice tool to install all android dependencies in your local repository. So take a look:
https://github.com/mosabua/maven-android-sdk-deployer

Saturday, October 18, 2014

Maven for Android

For all of you who won't miss Maven Support in your Android Projects:
https://code.google.com/p/maven-android-plugin/

This Maven-Plugin helps you building an Android Application (apk) and manage necessary Dependencies. Nice one :-)

Tuesday, October 7, 2014

Wohooo! Didn't know that i already have a blog :-). But good too know. So lets start with some Java Stuff.
Yesterday i installed the latestet version of the Android Development Toolkit. Most of my projects make use of Maven so i also tried to install the M2E Maven Eclipse integration. But i had no luck. The installation quit with a missing dependency (com.google.guave). The solution came to me in form of a two year old stackoverflow thread: http://stackoverflow.com/questions/11391297/maven-android-and-eclipse-coexistence-problems
Install the M2E from the following update site: http://rgladwell.github.com/m2e-android/updates/master/
That worked for me :-) Happy Coding