Dev Center
Table of contents

How to Read Barcodes from a Specific Area/Region

Read from a specific region of a video stream

If you are using DBR and DCE to read barcodes from a specific area of the video stream, you can simply define the scan area via DCE.

Note: Dynamsoft Camera Enhancer (DCE) is designed to provide APIs for camera control, camera preview, and other advanced features.

  • Android
  • Objective-C
  • Swift
import com.dynamsoft.dce.CameraEnhancer;
DSRect scanRegion = new DSRect();
scanRegion.top = 0.1f;
scanRegion.bottom = 0.9f;
scanRegion.right = 0.9f;
scanRegion.left = 0.1f;
scanRegion.measuredInPercentage = true;
try {
   // mCameraEnhancer is an instance of com.dynamsoft.dce.CameraEnhancer.
   mCameraEnhancer.setScanRegion(scanRegion);
} catch (CameraEnhancerException e) {
   e.printStackTrace();
}
NSError* err = nil;
DSRect* scanRegion = [[DSRect alloc] init];
scanRegion.top = 0.1;
scanRegion.bottom = 0.9;
scanRegion.right = 0.9;
scanRegion.left = 0.1;
scanRegion.measuredInPercentage = YES;
// dce is an instance of `DSCameraEnhancer`.
[dce setScanRegion:scanRegion error:&err];
let scanRegion:Rect? = Rect()
scanRegion?.top = 0.1
scanRegion?.bottom = 0.9
scanRegion?.left = 0.1
scanRegion?.right = 0.9
scanRegion?.measuredInPercentage = true
// dce is an instance of `CameraEnhancer`.
try? dce.setScanRegion(scanRegion)

Set an Region of Interest on a Still Image

The library scan the entire image by default when localizing the barcodes. However, if only a specific region of the image or video is required to locate the barcode, you can define a Region of Interest (ROI) via the target ROI parameter to restrict the scan area. The parameter can be set either via the SimplifiedCaptureVisionSettings or a JSON parameter template.

Notes:

  • You can either configure these settings via the SimplifiedCaptureVisionSettings struct or via a JSON template.
  • When using SimplifiedCaptureVisionSettings, you can only specify one region.
  • When using JSON template, you can specify more than one region.

Specify a ROI via SimplifiedCaptureVisionSettings

To update the setting via SimplifiedCaptureVisionSettings:

  • Android
  • Objective-C
  • Swift
try {
   // Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
   // Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
   SimplifiedCaptureVisionSettings captureVisionSettings = cvr.getSimplifiedSettings(EnumPresetTemplate.PT_READ_BARCODES);
   Quadrilateral roiQuad = new Quadrilateral();
   roiQuad.points[0] = new Point(15,30);
   roiQuad.points[1] = new Point(85,30);
   roiQuad.points[2] = new Point(85,70);
   roiQuad.points[3] = new Point(15,70);
   captureVisionSettings.roi = roiQuad;
   captureVisionSettings.roiMeasuredInPercentage = true;
   // Update the settings. Remember to specify the same template name you used when getting the settings.
   cvr.updateSettings(EnumPresetTemplate.PT_READ_BARCODES, captureVisionSettings);
} catch (CaptureVisionRouterException e) {
   e.printStackTrace();
}
NSError *error;
// Obtain current runtime settings. `cvr` is an instance of `DSCaptureVisionRouter`.
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
DSSimplifiedCaptureVisionSettings *captureVisionSettings = [self.cvr getSimplifiedSettings:DSPresetTemplateReadBarcodes error:&error];
DSQuadrilateral *roiQuad = [[DSQuadrilateral alloc] initWithPointArray:@[@(CGPointMake(15, 30)),@(CGPointMake(85, 30)),@(CGPointMake(85, 70)),@(CGPointMake(15, 70))]];
captureVisionSettings.roi = roiQuad;
captureVisionSettings.roiMeasuredInPercentage = true;
// Update the settings. Remember to specify the same template name you used when getting the settings.
[self.cvr updateSettings:DSPresetTemplateReadBarcodes settings:captureVisionSettings error:&error];
// Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
do{
   let captureVisionSettings = try cvr.getSimplifiedSettings(PresetTemplate.readBarcodes.rawValue)
   let roiQuad = Quadrilateral.init(pointArray: [CGPoint(x: 15,y: 30),CGPoint(x: 85,y: 30),CGPoint(x: 85,y: 70),CGPoint(x: 15, y: 70)])
   captureVisionSettings.roi = roiQuad
   captureVisionSettings.roiMeasuredInPercentage = true
   // Update the settings. Remember to specify the same template name you used when getting the settings.
   try cvr.updateSettings(PresetTemplate.readBarcodes.rawValue, settings: captureVisionSettings)
}catch{
   // Add code to do when error occurs.
}

Specify One or More ROI via a Template

Define a single ROI:

{
   "CaptureVisionTemplates": [
      {
            "Name" : "CV_0",
            "ImageROIProcessingNameArray": ["barcode-decoding-roi-1" ]
      }       
   ],
   "TargetROIDefOptions" : [
      {
         "Name" : "barcode-decoding-roi-1",
         "TaskSettingNameArray": ["barcode-decoding-task-1"],
         "Location": 
         {
            "Offset": {
               "MeasuredByPercentage" : 1,
               "FirstPoint" : [ 15, 30 ],
               "SecondPoint" : [ 85, 30 ],
               "ThirdPoint" : [ 85, 70 ],
               "FourthPoint" : [ 15, 70 ],
            }
         }
      }
   ]
}

You can define different ROIs in the TargetROIDefOptions. In the different ROIs you can specify different tasks or use the same task.

{
   "CaptureVisionTemplates": [
      {
            "Name" : "CV_0",
            "ImageROIProcessingNameArray": ["barcode-decoding-roi-1","barcode-decoding-roi-2" ]
      }       
   ],
   "TargetROIDefOptions" : [
      {
         "Name" : "barcode-decoding-roi-1",
         "TaskSettingNameArray": ["barcode-decoding-task-1"],
         "Location": 
         {
            "Offset": {
               "MeasuredByPercentage" : 1,
               "FirstPoint" : [ 15, 20 ],
               "SecondPoint" : [ 85, 40 ],
               "ThirdPoint" : [ 85, 40 ],
               "FourthPoint" : [ 15, 20 ]
            }
         }
      },{
         "Name" : "barcode-decoding-roi-2",
         "TaskSettingNameArray": ["barcode-decoding-task-1"],
         "Location": 
         {
            "Offset": {
               "MeasuredByPercentage" : 1,
               "FirstPoint" : [ 15, 60 ],
               "SecondPoint" : [ 85, 80 ],
               "ThirdPoint" : [ 85, 80 ],
               "FourthPoint" : [ 15, 60 ]
            }
         }
      }
   ]
}

This page is compatible for:

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 10.x
    • Version 10.2.0
    • Version 10.0.21
    • Version 10.0.20
    • Version 10.0.10
    • Version 10.0.0
  • Version 9.x
    • Version 9.6.42
    • Version 9.6.40
    • Version 9.6.33
    • Version 9.6.32
    • Version 9.6.31
    • Version 9.6.30
    • Version 9.6.20
    • Version 9.6.10
    • Version 9.6.0
    • Version 9.4.0
    • Version 9.2.0
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.0
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.0
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
  • Documentation Homepage
Change +