To find the location of a barcode, gradient method differences are commonly used. If we take the contrast gradient along the barcode, we get a high gradient in the horizontal direction, and a low gradient in the vertical direction. Therefore, when their difference (i.e. horizontal gradient-vertical gradient) is maximum, we take the position of the barcode.
Please refer to this article: Reading Barcodes
The following links also apply: Link 1 , Link 2
source share