Fixed bugs in capturing of image sequences.

Adapted old pull request changes.
See http://code.opencv.org/issues/3306

Basically the line is scanned in opposite direction now, in order not to cope with specific formatting in the rest of the string.