It only works for horizontal barcodes. It's certainly possible to extend this code to work for vertical ones as well. A Radon transform might be a good start. And if you want something more powerful there is Haar cascades or HOG descriptors + Linear SVM.