目标解码模拟激光条码扫描器的行为。然而,读者不是看整个视野,而是试图解码仅位于激光瞄准点下的条形码。这可以防止操作人员不小心读取附近的其他条形码。
支持设备:
配置dmcc:
启用或禁用目标解码(或检索它的状态)。
默认值:OFF
例子
readerDevice.getDataManSystem()。sendCommand(“设置解码器。TARGET-DECODING”);
readerDevice.getDataManSystem()。sendCommand(“设置解码器。TARGET-DECODING”);
self.readerDevice.dataManSystem()。sendCommand(“设置解码器。TARGET-DECODING”)
[self.readerDevice。dataManSystem sendCommand:@"SET DECODER. "TARGET-DECODING”);
设置(或获取)定心窗口的大小。数字是以图像的百分比表示的。
如果条形码与定心窗口重叠,则对该条形码进行解码。因此,定心窗口不一定需要包含整个条形码。
默认值:50 50 10 10
例子
readerDevice.getDataManSystem()。sendCommand(“设置解码器。定心窗50 50 5 5”);
self.readerDevice.dataManSystem()。sendCommand(“设置解码器。正窗50 50 5 5")
[self.readerDevice。dataManSystem sendCommand:@"SET DECODER. "定心窗50 50 5 5"];
如果将中心窗口添加到SVG结果中,则设置(或获取)。
默认值:ON
例子
readerDevice.getDataManSystem()。sendCommand(“设置解码器。DISPLAY-TARGET”);
self.readerDevice.dataManSystem()。sendCommand(“设置解码器。DISPLAY-TARGET”)
[self.readerDevice。dataManSystem sendCommand:@"SET DECODER. "DISPLAY-TARGET”);
备注
以下是摄像头AP中启用目标解码(黄色的小矩形为目标解码窗口)时摄像头扫描预览的示例I:
目标解码窗口(矩形)的颜色和线的权重可以通过:
MWOverlay。targetRectLineColor = Color.RED;MWOverlay。targetRectLineWidth = 2;
MWOverlay.setTargetRectLineUIColor (UIColor.red) MWOverlay.setTargetRectLineWidth (2)
[MWOverlay setTargetRectLineUIColor:[UIColor redColor]];[MWOverlay setTargetRectLineWidth: 2];
如果您想一次扫描更多的条形码,在一个扫描会话,您可以使用多码阅读。
支持设备:
配置dmcc:
设置解码器为获得成功的读取结果应找到的码数。
缺省值:1
例子
readerDevice.getDataManSystem()。sendCommand(“多码。NUM-CODES 3”);
self.readerDevice.dataManSystem()。sendCommand(“多码。NUM-CODES 3”)
[self.readerDevice。dataManSystem sendCommand:@"SET MULTICODE. "NUM-CODES 3”);
定义阅读器如何解释要查找的代码数量。
默认值:OFF
例子
readerDevice.getDataManSystem()。sendCommand(“多码。部分结果”);
self.readerDevice.dataManSystem()。sendCommand(“多码。部分结果”)
[self.readerDevice。dataManSystem sendCommand:@"SET MULTICODE. "部分结果”);
如果该代码是在最近的N次读取中读取的,则不要读取该代码。
默认值:0(不限)。
例子
readerDevice.getDataManSystem()。sendCommand(“设置解码器。REREAD-NOT-LAST-N 1 ");
self.readerDevice.dataManSystem()。sendCommand(“设置解码器。REREAD-NOT-LAST-N 1”)
[self.readerDevice。dataManSystem sendCommand:@"SET DECODER. "REREAD-NOT-LAST-N 1 ");
定义为每个符号组寻找的期望最大编码数:
任何单个符号的期望值都不能超过MULTICODE参数。NUM-CODES,要查找的代码总数。第一个参数是符号组,第二个参数是最大码数。
缺省值:所有组为1
例子
readerDevice.getDataManSystem()。sendCommand(“多码。Max-num-codes 1 3");
self.readerDevice.dataManSystem()。sendCommand(“多码。max - num - code 1 3")
[self.readerDevice。dataManSystem sendCommand:@"SET MULTICODE. "Max-num-codes 1 3"];
备注
如果启用了多码读取,则在onReadResultReceived回调函数中使用getSubResults ()ReadResults对象的方法。如果禁用多码读取,此方法返回null。
解析器帮助我们将解码的结果提取为结构化格式(JSON、Key-Value),用于搜索、排序和验证。解析器有六种类型:
此外,cmbSDK中还有使用AUTO解析器类型的选项,它会尝试找出最适合的一种。
支持设备:
使用setParser ()方法从ReaderDevice对象设置要使用的解析器类型,或者getParser ()获取所选类型。在与阅读器设备有效连接后设置解析器类型。默认为无。
例子
readerDevice.setParser (ResultParser.AAMVA);
self.readerDevice.parser = CMBResultParserAAMVA
self.readerDevice.parser = CMBResultParserAAMVA;
当你启用所需的解析器类型后,你可以在ReadResult的onReadResultReceived回调函数中从接收的结果中获得结构化格式:
//从结果results中以json格式返回解析后的文本。//从结果results中返回解析后的文本。
let results:[CMBReadResult] = readResults?readResults一样吗?(CMBReadResult) ? ?[] //从结果中返回json格式的解析文本let parsedJSON = results.first?parsedJSON //返回从结果let parsedText = results.first
NSArray* results = readResults.readResults;//从结果中返回json格式的解析文本NSString* parsedJSON = [[results firstObject] parsedJSON];//返回从结果中解析的文本NSString* parsedText = [[results firstObject] parsedText];
可以使用此功能指定将用于定位和解码符号的图像的确切区域。如果两个条形码彼此非常接近,并且您需要确保只阅读目标区域的代码,那么这将是很有帮助的。减少感兴趣的区域并不一定会减少解码时间或增加图像传输速率。
支持设备:
配置dmcc:
(获取|设置)译码器。roi - % [x w y h]
检查0-100的范围,以及宽度和高度的最小值5,以及args之间隐含的约束,例如给定轴的总和不超过100。
例子
readerDevice.getDataManSystem()。sendCommand(“设置解码器。Roi-percent 10 80 10 80");
self.readerDevice.dataManSystem()。sendCommand(“设置解码器。Roi-percent 10 80 10 80")
[self.readerDevice。dataManSystem sendCommand:@"SET DECODER. "Roi-percent 10 80 10 80"];
SDK可以从图像文件中解码条形码(仅限相机API)。支持的图像格式包括BMP、PNG和JPG。图像不能超过5000 x 5000像素。
支持设备:
要扫描图像,应用程序必须首先将图像读入内存,然后使用的形象。负载DMCC命令解码。对象readerDevice必须在发送的形象。负载命令。下面是使用sendCommand方法初始化的形象。负载函数。
例子
readerDevice.getDataManSystem () .sendCommand (String.format”的形象。负载%d", imageData.length), imageData, 500, false, (dataManSystem, response) -> { if (response.getError() != null) { // IMAGE.LOAD DMCC finished with error, handle the error here } });
self.readerDevice.dataManSystem () ? .sendCommand(”的形象。负载\(imageData.count)", with: imageData, timeout: 100, expectBinaryResponse: false, callback: { (response) in if response?.status != DMCC_STATUS_NO_ERROR { // IMAGE.LOAD DMCC finished with error, handle the error here } })
注:imageData是图像的数据。
[self.readerDevice。dataManSystem sendCommand:[NSString stringWithFormat:@"负载%lu", [imageData length]] withData:imageData timeout:100 expectBinaryResponse:NO callback:^(CDMResponse *response) { if (response.status != DMCC_STATUS_NO_ERROR) { // IMAGE.LOAD DMCC finished with error, handle the error here } }];
注意:imageData是图像的NSData。
就像实时扫描一样,当的形象。负载命令完成后,结果将在您的ReaderDevice的使用以下方法委派:
ReaderDevice读取器,ReadResults结果
func didReceiveReadResult(fromReader reader: CMBReaderDevice,结果readResults: CMBReadResults!)
- (void)didReceiveReadResultFromReader:(CMBReaderDevice *)reader results:(CMBReadResults *)readResults;
下面您将看到一个从设备的图片库中选择并扫描图像的示例
private void pickImageFromGallery(){意图pickPhoto =新的意图(意图。ACTION_PICK android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);startActivityForResult (pickPhoto PICK_IMAGE);} @覆盖protected void onActivityResult(int requestCode, int resultCode, Intent data) {if(requestCode == PICK_IMAGE && resultCode == RESULT_OK && data != null && data. getdata () != null && readerDevice != null && readerDevice. getconnectionstate () == ConnectionState.Connected) {try (InputStream imageStream = getContentResolver().openInputStream(data. getdata ());ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {int nRead;Byte [] bytes = new Byte [1024];while (nRead = imageStream. while)读取(bytes, 0, bytes.length)) != -1){缓冲区。write(bytes, 0, nRead);} buffer.flush ();final byte[] byteArray = buffer.toByteArray(); readerDevice.getDataManSystem().sendCommand(String.format("IMAGE.LOAD %d", byteArray.length), byteArray, 500, false, (dataManSystem, response) -> { if (response.getError() != null) { Toast.makeText(MainActivity.this, "ERROR [" + response.getError().toString() + "]: " + response.getError().getLocalizedMessage(), Toast.LENGTH_LONG).show(); } }); } catch (IOException e) { e.printStackTrace(); } } super.onActivityResult(requestCode, resultCode, data); }
func showImagePicker(){让imagePickerController = UIImagePickerController() imagePickerController。allowsEditing = false imagePickerController.delegate = self imagePickerController。sourceType = . photollibrary self。// MARK: UIImagePickerControllerDelegate methods func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.]InfoKey: Any]){选择器。release (animated: true, completion: nil) let imagePath = info[UIImagePickerController.InfoKey]imageURL] !NSURL守卫让imageData = try?数据。init(contentsOf: imagePath.absoluteURL!) else {return} self.readerDevice.dataManSystem()?负载\(imageData.count)", with: imageData, timeout: 100, expectBinaryResponse: false, callback: { (response) in if response?.status != DMCC_STATUS_NO_ERROR { // IMAGE.LOAD DMCC finished with error, handle the error here } }) }
- (void)showImagePicker {UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];imagePickerController。allowsEditing = NO;imagePickerController.delegate = self;[imagePickerController setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];[self presentViewController:imagePickerController animated:YES completion:nil];} #pragma mark - UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{[self解散viewcontrolleranimated:YES completion:nil];NSURL *imagePath = [info valueForKey:UIImagePickerControllerImageURL];NSData *imageData = [NSData dataWithContentsOfURL:imagePath];if (imageData) {[self.readerDevice.]dataManSystem sendCommand:[NSString stringWithFormat:@"负载 %lu", [imageData length]] withData:imageData timeout:100 expectBinaryResponse:NO callback:^(CDMResponse *response) { if (response.status != DMCC_STATUS_NO_ERROR) { // IMAGE.LOAD DMCC finished with error, handle the error here } }]; } }
由于在一些一维条形码中缺乏错误纠正,甚至缺乏校验和值,许多都容易发生误读和短读(其中只有部分条形码被解码)。诸如印刷质量差、光线不一致、图像模糊、极端倾斜和其他变量都可能造成这种情况。
SDK缓解误读和短读的方法之一是使用一个称为位置验证的特性。当启用时,SDK将更加努力地验证一维条码的边缘和完整位置;从而极大地减少了读错误。请注意,位置验证可能会降低扫描性能,特别是在启用了多个符号或在具有较慢cpu的值线设备上使用时。
位置验证可用于以下条形码类型(粗体部分默认启用此功能):代码11,代码25,Codabar代码93,代码39,代码128Telepen,MSI普莱西UPC / EAN。
在处理读取错误时,考虑将位置验证与SDK的其他特性结合使用,例如设置最小读取长度和调整解码器的努力级别(参见DMCC命令decoder . effort)。
支持设备:
配置API:
例子
BarcodeScanner.MWBsetParam (BarcodeScanner。MWB_CODE_MASK_39 BarcodeScanner。MWB_PAR_ID_VERIFY_LOCATION BarcodeScanner.MWB_PAR_VALUE_VERIFY_LOCATION_ON);
MWB_setParam(MWB_CODE_MASK_39, UInt32(MWB_PAR_ID_VERIFY_LOCATION), UInt32(MWB_PAR_VALUE_VERIFY_LOCATION_ON))
MWB_setParam(MWB_CODE_MASK_39, MWB_PAR_ID_VERIFY_LOCATION, MWB_PAR_VALUE_VERIFY_LOCATION_ON);
默认情况下,当你使用相机API创建阅读器设备时,全屏预览是使用的。如果你想使用部分屏幕预览你需要创建ViewGroup容器在你的布局为android或视图容器,然后将该容器作为参数发送到阅读器设备构造函数中,否则,如果该参数没有设置或如果零设置后,将使用全屏预览。
当使用部分屏幕预览时,来自相机的帧被填充在预览容器中,如果预览容器的长宽比与相机的长宽比不同,我们将执行裁剪以避免扭曲。
支持设备:
例子
首先在布局/故事板中创建容器。
<?XML版本="1.0"编码="utf-8"?> < android.support.constraint。ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#333333" tools:context="cognex.com.cmbcamerademo.ScannerActivity"> .... .
稍后,当您创建读取器设备时,将该容器作为读取器设备构造函数中的参数发送
readerDevice = readerDevice。getPhoneCameraDevice(这个,param_cameraMode, PreviewOption。默认值,(ViewGroup) findViewById(R.id.rlPreviewContainer));
将新添加的UIView连接到ViewController中的一个出口
@IBOutlet弱var previewContainer: UIView!
然后使用previewContainer作为构造函数中的参数来创建readerDevice
让readerDevice = CMBReaderDevice。readerOfDeviceCamera(:自我。cameraMode previewOptions: CDMPreviewOption。init(rawValue: 0), previewView:self.previewContainer)
将新添加的UIView连接到ViewController中的一个出口
IBOutlet UIView *previewContainer;
然后使用previewContainer作为构造函数中的参数来创建readerDevice
CMBReaderDevice *readerDevice = [CMBReaderDevice readerOfDeviceCameraWithCameraMode:cameraMode previewOptions:kCDMPreviewOptionDefaults previewView:self.previewContainer];
这是它的样子