Loops through each row in a binary image and gets the width of each group of black or white pixels
You don't need a number of pixels, you need to detect narrow bars and wide bars. Use first black and white bar width as a pattern with 15% margin for next bars. The wide bar has 2.0 to 3.0 times the width of a narrow bar. Try to detect start or stop code at the begin of selected line, if it is correct, then read the rest of the line...
After every 5 black+white bars (in the right direction) you can decode two digits, black bars define 1st and white 2nd ...
Bars have weights: 1st: 1, 2nd: 2, 3th: 4, 4th: 7: 5th 0. Add weights of every wide bars, and you get the digit (11 = 0).
If 3 lines give you the same result, this is probably your code...

EDIT:

You can see the algorithm on your code: