TBDecoder.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // TBDecoder.h
  3. // sdk_gen3_3g
  4. //
  5. // Created by Tom on 15/6/24.
  6. // Copyright (c) 2015年 Taobao.com. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import <CoreVideo/CoreVideo.h>
  10. #import <TBDecodeSDK/tbItf.h>
  11. #import <TBDecodeSDK/TBDecodeResult.h>
  12. typedef enum {
  13. PreDetect_By_Normal = 0,
  14. PreDetect_By_xNN = 1
  15. } PreDetectTool;
  16. typedef struct {
  17. float codeProportion; ///< 疑似二维码的宽度所占比例,用于上层放大 zoom. value = 0 代表没找到
  18. CGPoint codeCenterInInterest;
  19. CGPoint sweetPointForExposure;
  20. PreDetectTool preDetectTool;
  21. float codeRadius;
  22. } PreDetectResult;
  23. #define MAX_HOT_NUM 10
  24. // 模糊检查
  25. TBEXTERN_C NSString * const TBDecodeBlurNotification;
  26. TBEXTERN_C NSString * const TBDecodeBlurNotificationInfoKey;
  27. TBEXTERN_C NSString * const TBDecodeLogToFileNotification; ///< 算法层 log ,logToFile
  28. TBEXTERN_C NSString * const TBDecodeLogToFileNotificationTagKey;
  29. TBEXTERN_C NSString * const TBDecodeLogToFileNotificationLogKey;
  30. TBEXTERN_C NSString * const TBDecodeTrackInfoNotification; // 解码信息埋点通知
  31. TBEXTERN_C NSString * const TBDecodeTrackInfoNotificationSeedKey;
  32. TBEXTERN_C NSString * const TBDecodeTrackInfoNotificationUcIdKey;
  33. TBEXTERN_C NSString * const TBDecodeTrackInfoNotificationFlagKey; //FLAG_DEFAULT = 0, FLAG_NEED_LSB = 1
  34. TBEXTERN_C NSString * const TBDecodeTrackInfoNotificationParamsKey;
  35. @interface TBDecoder : NSObject
  36. /**
  37. * 解析视频中的码,先将图片根据rect裁剪,然后resample为YES时将剪裁后的图片缩放到360x360再解析,解析时的通用配置参见@TBDecodeConfig
  38. *
  39. * @param buffer 待解析的CVPixelBufferRef
  40. * @param rect 解析的图片范围,传入CGRectZero或CGRectNull时解析整张图片
  41. * @param resample YES:将裁剪后的图片缩放到360x360,提高识别速度;NO:不做缩放,识别率更高但识别速度下降明显,一般情况下推荐使用YES。
  42. * @param type 解析类型,可以是多种解析类型的或值,例如条形码ONED = ( EAN13 | EAN8 | UPCA | UPCE | CODE39 | CODE93 | CODE128 | ITF )
  43. * @param PreDetectResult 解出码之前的探测结果
  44. *
  45. * @return 解析结果,解析失败或者没有解析到数据时返回nil
  46. */
  47. + (NSArray<TBDecodeResult*> *)decodeCVPixelBuffer:(CVPixelBufferRef)buffer
  48. rectOfInterest:(CGRect)rect
  49. resample:(BOOL)resample
  50. type:(int)type
  51. cameraZoomFactor:(float)cameraZoomFactor
  52. preDetectResult:(PreDetectResult*)preDetectResult;
  53. /**
  54. * 解析视频中的码,先将图片根据rect裁剪,然后resample为YES时将剪裁后的图片缩放到360x360再解析,解析时的通用配置参见@TBDecodeConfig
  55. *
  56. * @param buffer 待解析的CVPixelBufferRef
  57. * @param rect 解析的图片范围,传入CGRectZero或CGRectNull时解析整张图片
  58. * @param resample YES:将裁剪后的图片缩放到360x360,提高识别速度;NO:不做缩放,识别率更高但识别速度下降明显,一般情况下推荐使用YES。
  59. * @param type 解析类型,可以是多种解析类型的或值,例如条形码ONED = ( EAN13 | EAN8 | UPCA | UPCE | CODE39 | CODE93 | CODE128 | ITF )
  60. * @param cameraZoomFactor 相机当前缩放比例,默认可以传 1
  61. * @param codeProportion 疑似二维码的宽度所占比例,用于上层放大zoom.value = 0代表没找到
  62. *
  63. * @return 解析结果,解析失败或者没有解析到数据时返回nil
  64. */
  65. + (NSArray<TBDecodeResult*> *)decodeCVPixelBuffer:(CVPixelBufferRef)buffer
  66. rectOfInterest:(CGRect)rect
  67. resample:(BOOL)resample
  68. type:(int)type
  69. cameraZoomFactor:(float)cameraZoomFactor
  70. codeProportion:(float*)codeProportion;
  71. /**
  72. 传入Y通道图片数据, 原图片高宽,解析途中二维码
  73. @param data Y通道图片数据
  74. @param imgWidth 原图宽度
  75. @param imgHeight 原图高度
  76. @param rect 解析的图片范围,传入CGRectZero或CGRectNull时解析整张图片
  77. @param resample YES:将裁剪后的图片缩放到360x360,提高识别速度;NO:不做缩放,识别率更高但识别速度下降明显,一般情况下推荐使用YES。
  78. @param type 解析类型,可以是多种解析类型的或值,例如条形码ONED = ( EAN13 | EAN8 | UPCA | UPCE | CODE39 | CODE93 | CODE128 | ITF )
  79. @param codeProportion 疑似二维码的宽度所占比例,用于上层放大zoom.value = 0代表没找到
  80. @return 解析结果,解析失败或者没有解析到数据时返回nil
  81. */
  82. + (NSArray<TBDecodeResult*> *)decodeBufferData:(NSData *)data
  83. imageWidth:(CGFloat)imgWidth
  84. imageHeight:(CGFloat)imgHeight
  85. rectOfInterest:(CGRect)rect
  86. resample:(BOOL)resample
  87. type:(int)type
  88. codeProportion:(float*)codeProportion;
  89. /**
  90. * 解析照片中的二维码和GEN3码,和条形码,目前不支持解隐藏码,建议直接用下面支持返回图片中所有码的接口
  91. *
  92. * @param image 待解析的UIImage
  93. *
  94. * @return 解析结果,解析失败或者没有解析到数据时返回nil
  95. */
  96. + (TBDecodeResult *)decodeUIImage:(UIImage *)image;
  97. /**
  98. * 解析照片中的二维码和GEN3码,和条形码,目前不支持解隐藏码
  99. *
  100. * @param image 待解析的UIImage
  101. *
  102. * @return 解析结果,数组,解析失败或者没有解析到数据时返回nil
  103. */
  104. + (NSArray<TBDecodeResult*> *)overallDecodeUIImage:(UIImage *)image;
  105. ///
  106. /// ⚠️⚠️ 由于不支持并发,以下方法都上了锁,等待其他解码器其他方法执行完再执行,所以以下不建议在主线程调用!!!!!!
  107. ///
  108. // 算法配置。没有/nil 则默认算法,扫码初始化时调用
  109. + (void)startCameraWithConfig:(NSDictionary*)config;
  110. ///在 startCamera 之后设置,可以设置过滤规则及延迟策略
  111. + (void)setFilterConfig:(NSString *)filterConfig;
  112. ///< 支持动态调整二值化次序,
  113. ///< 每一帧用一种二值化:[ [0], [1], [2], [3], [4] ]
  114. ///< 或者每一帧用多种二值化: [ [0,1], [2,3], [3,4] ]
  115. + (void)setBinarizerOrder:(NSArray *)binarizerOrder;
  116. ///< 成功返回 1、失败返回 0
  117. + (int)registCodeDSL:(NSString *)codeDSL IsAlbum:(BOOL)isAlbum;
  118. + (int)unregistCodeDSLIsAlbum:(BOOL)isAlbum;
  119. // 获取算法解码过程信息,避免性能问题,建议不要频繁调用
  120. + (NSDictionary *)getDecodeInfo;
  121. // 内存紧张,需要降级
  122. + (void)downGradeSdkMemoryAllocate;
  123. // 扫码结束时调用,回异步调用清除数据
  124. + (void)endCamera;
  125. @end