MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / recognize

Method recognize

src/main/ocr.ts:85–108  ·  view source on GitHub ↗
(image: string)

Source from the content-addressed store, hash-verified

83 }
84
85 recognize(image: string) {
86 if (!this.client) {
87 return;
88 }
89 image = image.substring(image.indexOf(",") + 1);
90
91 this.client
92 .generalBasic(image, {
93 language_type: this.getLanguage(),
94 detect_language: "true",
95 })
96 .then(function (result: { words_result: Array<{ words: string }> }) {
97 const text = result.words_result
98 .map((item) => item["words"])
99 .join("\n");
100 logger.toast("OCR完成,正在翻译");
101 eventBus.at("dispatch", "translate", text);
102 })
103 .catch(function (err: any) {
104 // 如果发生网络错误Z
105 console.log(err);
106 logger.toast("OCR失败");
107 });
108 }
109}
110export const recognizer = new Recognizer();

Callers 2

getShortcutCaptureMethod · 0.95
setWatchMethod · 0.80

Calls 2

getLanguageMethod · 0.95
toastMethod · 0.80

Tested by

no test coverage detected