Updates for OpenCV 3 api (keeping OpenCV 2 back compatibility).
Tested with:
(working with both 2 and 3 major versions).
Main changes: