KMGOCRManager.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // KMGOCRManager.h
  3. //
  4. //
  5. //
  6. //
  7. //
  8. #import <Foundation/Foundation.h>
  9. typedef NS_ENUM(NSUInteger, KMOCRType) {
  10. KMOCRType_Google,
  11. KMOCRType_Apple
  12. };
  13. extern NSString * KMGOCRLanguageCodeKey;
  14. extern NSString * KMGOCRLanguageStringKey;
  15. @interface KMGOCRResult : NSObject
  16. @property (nonatomic,retain) NSString *text;
  17. @property (nonatomic,retain) NSString *locale;
  18. @property (nonatomic,assign) CGRect textBounds;
  19. @end
  20. @class KMGOCRManager;
  21. @protocol KMGOCRManagerDelegate <NSObject>
  22. @optional
  23. - (void)GOCRManagerDidStartOCR:(KMGOCRManager *)manager;
  24. - (void)GOCRManagerDidFinishOCR:(KMGOCRManager *)manager;
  25. - (void)GOCRManager:(KMGOCRManager *)manager didCancelOCRImageAtIndex:(NSInteger)index;
  26. - (void)GOCRManager:(KMGOCRManager *)manager didStartOCRImageAtIndex:(NSInteger)index;
  27. - (void)GOCRManager:(KMGOCRManager *)manager didFinishOCRImageAtIndex:(NSInteger)index results:(NSArray<KMGOCRResult *> *)results;
  28. - (void)CHOCRManager:(KMGOCRManager *)manager didFinishOCRImageAtIndex:(NSInteger)index results:(NSArray *)results;//17方案
  29. - (void)GOCRManager:(KMGOCRManager *)manager didFailureOCRImageAtIndex:(NSInteger)index error:(NSError *)error;
  30. @end
  31. @interface KMGOCRManager : NSObject
  32. @property (nonatomic,assign) id<KMGOCRManagerDelegate> delegate;
  33. @property (nonatomic,readonly) NSMutableArray *images;
  34. @property (nonatomic,assign) KMOCRType OCRType;
  35. @property (nonatomic,retain) NSMutableArray *selectedLanguages;
  36. /* isGOCR : GOCR=NO/OCR=YES */
  37. @property (nonatomic,assign) BOOL isOCR;
  38. + (KMGOCRManager *)defaultManager;
  39. + (NSArray *)languages;
  40. - (void)createPDFFile:(NSString *)filePath imagePaths:(NSArray *)paths results:(NSArray *)resultsArray scale:(CGFloat)scale;
  41. - (void)recognitionImages:(NSArray *)images withLanguages:(NSArray *)languages;
  42. //- (void)recognitionImages:(NSArray *)images withLanguages:(NSArray *)languages fileType:(NSString * _Nullable)fileType filePath:(NSURL *)filePath;
  43. /**
  44. Google OCR 设置参数进行转档.
  45. @param images 需要转档的NSImage 数组对象
  46. @param languages 设置的识别s语言
  47. @param fileType 设置转档的文件格式,可为空
  48. @param filePath 设置保存文件的路径,可为空
  49. */
  50. - (void)recognitionImages:(NSArray *)images withLanguages:(NSArray *)languages fileType:(NSString * _Nullable)fileType filePath:(NSURL * _Nullable)filePath;
  51. - (void)cancelRecognition;
  52. @end
  53. @interface KMOCROperationQueue : NSOperationQueue
  54. + (instancetype)sharedInstance;
  55. - (void)addOCROperation:(NSOperation *)op;
  56. #pragma mark - cancel
  57. - (void)cancelAll;
  58. @end