4 Replies
      Latest reply on Jan 14, 2019 1:31 PM by gchiste
      LHarrison Level 1 Level 1 (0 points)

        Has anyone out there been using the Vision framework for doing barcode scanning (primarily EAN13/UPC, Code39 and Code128). I've been working on a scanning solution for a client, but have been having a few issues.

        1) Scanning light/white barcodes on dark backgrounds takes significantly longer/is more difficult than dark barcodes on light backgrounds. Has anyone else seen this issue, and is there any way to improve the recognition speed/quality in this case?

        2) Is it normal for the boundingBox of the VNBarcodeObservation to be basically a line for "1D" barcodes? (EAN13, Code39, etc.) Is there a way to get the full outline of the barcode from the observation?

        3) Trying to set the resolution/FPS of the camera is...ridiculously challenging. Any helpful tips for setting this for optimal barcode scanning? So far I've been defaulting to the standard session preset of AVCaptureSessionPresetHigh (which seems to default to 1920x1080@30fps on the iPad Pro), but have been wondering if recognition would be better in 4K @ 60fps.

         

        Sorry for such a long question, but all the examples I've been able to find so far are either fairly simple (QR code scanning, primarily) or focus more on other areas (face detection, object recognition).

         

        Thanks in advance.

        • Re: Barcode scanning issues
          gchiste Apple Staff Apple Staff (150 points)

          Hello,

           

          2) Is it normal for the boundingBox of the VNBarcodeObservation to be basically a line for "1D" barcodes? (EAN13, Code39, etc.) Is there a way to get the full outline of the barcode from the observation?

           

          Yes, this is normal for 1D barcodes.  Only the scan line is returned.  If you'd like the full outline of the barcode to be returned in the bounding box, you should file a bug report and request this enhancement.  That being said, if your barcode has a rectangular outline drawn around it, you could also conduct a VNDetectRectanglesRequest to find that rectangle in your image.

           

          3) Trying to set the resolution/FPS of the camera is...ridiculously challenging. Any helpful tips for setting this for optimal barcode scanning? So far I've been defaulting to the standard session preset of AVCaptureSessionPresetHigh (which seems to default to 1920x1080@30fps on the iPad Pro), but have been wondering if recognition would be better in 4K @ 60fps.

           

          You should use the lowest resolution possible that still allows your barcodes to be successfully scanned.  This resolution will depend on your particular use case.  For example (assuming a constant size for your barcode), if the barcode is right in front of the camera, you do not need a high resolution.  If the barcode is at a longer distance from the camera, you would require a higher resolution for successful scans.  So, there is not a "one size fits all" resolution for barcode scanning.  Something that you certainly want to keep in mind for performance reasons is that you should not try processing every single frame in your capture session.

           

          With respect to the frame rate and how often you should be submitting a detection request:

           

          You do not want to try to process every single frame.  Instead, you should be submitting your detection requests asynchronously, and only if there are no detection requests currently in flight!  So, a higher framerate is not going to help with performance here.  Even submitting a new detection request once the current one has completed may be overkill.  In general, running detection every 5th frame (assuming the previous request has already finished) at 30fps would be sufficient.

            • Re: Barcode scanning issues
              LHarrison Level 1 Level 1 (0 points)

              Yes, this is normal for 1D barcodes.  Only the scan line is returned.  If you'd like the full outline of the barcode to be returned in the  bounding box, you should file a bug report and request this enhancement.

               

              Thanks for the clarification. Will definitely file a bug report, as my client would like to be able to show the barcodes being scanned via an overlay rectangle in the preview layer.

               

              You should use the lowest resolution possible that still allows your barcodes to be successfully scanned.  This resolution will depend on your particular use case.  For example (assuming a constant size for your barcode), if the barcode is right in front of the camera, you do not need a high resolution.  If the barcode is at a longer distance from the camera, you would require a higher resolution for successful scans.  So, there is not a "one size fits all" resolution for barcode scanning.

               

              Ideally, my client would like to be able to scan from as far away as possible, as this is in a retail setting where the sales people will be standing with the customer scanning products for sale/provisioning. I will definitely look into the not-while-processing and not-every-frame tips. That should definitely help. And I was probably going to do that anyway so I can use some rectangle tracking requests so I can hopefully get better tracking as things move around (for those overlays I mentioned before).

               

              Thanks for the help!

               

              P.S. Any thoughts on the light vs. dark barcode issue? This is currently their primary concern and, ironically, is mostly an issue with Apple products (iPhone boxes, primarily).

                • Re: Barcode scanning issues
                  gchiste Apple Staff Apple Staff (150 points)

                  Assuming that the barcode symbology supports white-bars-on-dark-backgrounds, the reading speed should be similar regardless of the color of the bars.  Specifically referring to the iPhone packaging barcodes, there are a couple of factors that contribute to the difficulty in scanning these codes.

                   

                  1.  They are very small barcodes.

                   

                  2.  There is noticable bleed of the white ink from the printer.

                   

                  Combining these two issues results in a low quality bar code, which can be difficult to scan. The ink bleed, along with the small space between bars, can actually cause the spacing between bars to be almost invisible.

                  • Re: Barcode scanning issues
                    gchiste Apple Staff Apple Staff (150 points)

                    I encourage you to go ahead and file a bug report for this issue (the bar codes on that particular packaging not scanning as desired)!