Barcode Detection
The Barcode Detection feature is exposed via CBarcodeDetection class.
The class allows the detection of full-page and zonal barcodes by accepting any of the following two parameter classes:
CBarcodePageParamsCBarcodeZonalParams
Below are code snippets for full-page barcode detection and zonal barcode detection
Full-page barcode detection
Section titled “Full-page barcode detection”CIDRS objIdrs = CIDRS::Create();
// Load the source imageCImageIO objImageIO = CImageIO::Create(objIdrs);CPage objPage = objImageIO.LoadPage("path/to/image");
// Create the barcode detection parameters -> detect Ean13 using maximum accuracy setting and thread count set to number of physical cores of the running machineCBarcodeContext objBarcodeContext = CBarcodeContext::Create(BarcodeType::Ean13);CBarcodePageParams objPageBarcodeParams = CBarcodePageParams::Create(objBarcodeContext);objPageBarcodeParams.SetWorkDepth(Workdepth::MaximumAccuracy);objPageBarcodeParams.SetThreadingMode(ThreadingMode::Optimized);
// run barcode detectionCBarcodeDetection objBarcodeDetection = CBarcodeDetection::Create(objIdrs, objPageBarcodeParams);CBarcodeArray xDetectedBarcodes = objBarcodeDetection.DetectBarcodes(objPage);
// now the CBarcodeArray contains a list with the detected barcodes// Load the image to CPageCIDRS objIDRS = new CIDRS();CImageIO objImageIO = new CImageIO(objIDRS);CImage objImage = objImageIO.LoadImage("my file");
// Create the barcode detection parameters -> detect Ean13 using maximum accuracy setting and thread count set to number of physical cores of the running machineCBarcodeContext objBarcodeContext = new CBarcodeContext(BarcodeType.Ean13);CBarcodePageParams objPageBarcodeParams = new CBarcodePageParams(objBarcodeContext){ Workdepth = Workdepth.MaximumAccuracy, ThreadingMode = ThreadingMode.Optimized};
// run barcode detectionCBarcodeDetection objBarcodeDetection = new CBarcodeDetection(objIDRS, objPageBarcodeParams);CIDRSObjArray<CBarcode> xDetectedBarcodes = objBarcodeDetection.DetectBarcodes(objImage);
// now the xDetectedBarcodes contains a list with the detected barcodesZonal barcode detection
Section titled “Zonal barcode detection”CIDRS objIdrs = CIDRS::Create();
// Load the source imageCImageIO objImageIO = CImageIO::Create(objIdrs);CPage objPage = objImageIO.LoadPage("path/to/image");
CBarcodeZonalSettingsArray xBarcodeZonalSettings = CBarcodeZonalSettingsArray::Create();
// define the settings for first zone: search for Ean13 barcode type in area (0, 0) -> (300, 300)CBarcodeContext objBarcodeContextZone1 = CBarcodeContext::Create(BarcodeType::Ean13);IDRS_RECT rcZone1 = { 0, 0, 300, 300 };CPolygon objZone1 = CPolygon::Create(rcZone1);CBarcodeZonalSettings objZonalSettings1 = CBarcodeZonalSettings::Create();objZonalSettings1.SetContext(objBarcodeContextZone1);objZonalSettings1.GetZones.AddTail(objZone1);
// define the settings for first zone: search for QRCode barcode type in areas (0, 0) -> (300, 300) and (200, 0) -> (400, 400)CBarcodeContext objBarcodeContextZone2 = CBarcodeContext::Create(BarcodeType::QRCode);IDRS_RECT rcZone2 = { 200, 0, 400, 400 };CPolygon objZone2 = CPolygon::Create(rcZone2);CBarcodeZonalSettings objZonalSettings2 = CBarcodeZonalSettings::Create();objZonalSettings2.SetContext(objBarcodeContextZone2);objZonalSettings2.GetZones.AddTail(objZone1);objZonalSettings2.GetZones.AddTail(objZone2);
// set the zonal settingsxBarcodeZonalSettings.AddTail(objZonalSettings1);xBarcodeZonalSettings.AddTail(objZonalSettings2);CBarcodeZonalParams objBarcodeZonalParams = CBarcodeZonalParams::Create();objBarcodeZonalParams.SetZonalSettings(xBarcodeZonalSettings);
// run barcode detectionCBarcodeDetection objBarcodeDetection = CBarcodeDetection::Create(objIdrs, objBarcodeZonalParams);CBarcodeArray xDetectedBarcodes = objBarcodeDetection.DetectBarcodes(objPage);
// now the CBarcodeArray contains a list with the detected barcodes// Load the source imageCIDRS objIDRS = new CIDRS();CImageIO objImageIO = new CImageIO(objIDRS);CImage objImage = objImageIO.LoadImage("my file");
CIDRSObjArray<CBarcodeZonalSettings> xBarcodeZonalSettings = new CIDRSObjArray<CBarcodeZonalSettings>();
// define the settings for first zone: search for Ean13 barcode type in area (0, 0) -> (300, 300)CBarcodeContext objBarcodeContextZone1 = new CBarcodeContext(BarcodeType.Ean13);CIDRSRect rcZone1 = new CIDRSRect( 0, 0, 300, 300 );CBarcodeZonalSettings objZonalSettings1 = new CBarcodeZonalSettings(){ Context = objBarcodeContextZone1};objZonalSettings1.Zones.Add(new CPolygon(rcZone1));
// define the settings for second zone: search for QRCode barcode type in areas (0, 0) -> (300, 300) and (200, 0) -> (400, 400)CBarcodeContext objBarcodeContextZone2 = new CBarcodeContext(BarcodeType.QrCode);CIDRSRect rcZone2 = new CIDRSRect( 200, 0, 400, 400 );CBarcodeZonalSettings objZonalSettings2 = new CBarcodeZonalSettings(){ Context = objBarcodeContextZone2};objZonalSettings2.Zones.Add(new CPolygon(rcZone1));objZonalSettings2.Zones.Add(new CPolygon(rcZone2));
// set the zonal settingsxBarcodeZonalSettings.Add(objZonalSettings1);xBarcodeZonalSettings.Add(objZonalSettings2);CBarcodeZonalParams objBarcodeZonalParams = new CBarcodeZonalParams{ ZonalSettings = xBarcodeZonalSettings};
// run barcode detectionCBarcodeDetection objBarcodeDetection = new CBarcodeDetection(objIDRS, objBarcodeZonalParams);CIDRSObjArray<CBarcode> xDetectedBarcodes = objBarcodeDetection.DetectBarcodes(objImage);
// now the CBarcodeArray contains a list with the detected barcodes