KMGOCRManager.h 2.7 KB

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