Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我获取到的群聊中用户发送的图片是这样的格式@f4aee0239ecca855c037e61d35a1883eb263b3cfc......我处理不了他 #2677

Open
aqpmzngldh opened this issue Apr 23, 2024 · 4 comments

Comments

@aqpmzngldh
Copy link

我想通过群聊中用户发送的图片然后通过ocr识别图片内容做出处理,但是我处理不了获取的图片编码,所以这样的图片该怎么处理,他又是怎么编码的@f4aee0239ecca855c037e61d35a1883eb263b3cfc......

@aqpmzngldh
Copy link
Author

拜托啦

Copy link

dosubot bot commented Apr 23, 2024

Hello @aqpmzngldh! 👋 I'm Dosu, a friendly bot here to assist with bugs, questions, and guiding you on your contributor journey while we wait for a human maintainer to join us. I'm here to help, so let's dive into your issue about image encoding in group chats and get that sorted. I'll have a full answer for you shortly!

@aqpmzngldh
Copy link
Author

Hello @aqpmzngldh! 👋 I'm Dosu, a friendly bot here to assist with bugs, questions, and guiding you on your contributor journey while we wait for a human maintainer to join us. I'm here to help, so let's dive into your issue about image encoding in group chats and get that sorted. I'll have a full answer for you shortly!

#2677 (comment)

Copy link

dosubot bot commented Apr 23, 2024

To handle the image encoding from group chats in Wechaty for OCR processing, you'll primarily work with the messageImage method, which can fetch images in different qualities: thumbnail, HD, and artwork. This method returns a Promise<FileBoxInterface>, which you can then convert to a buffer for OCR processing.

Here's a simplified approach to process these images:

  1. Use the appropriate method (thumbnail(), hd(), or artwork()) to request the image quality you need.
  2. Convert the returned FileBox object to a buffer using toBuffer().
  3. Pass this buffer to your OCR tool for processing.

Example code snippet:

async function processImageWithOCR(imageId: string) {
  const fileBox = await image.artwork(); // Adjust based on needed quality
  const buffer = await fileBox.toBuffer();
  const ocrResult = await ocrTool.processImage(buffer);
  return ocrResult;
}

This example assumes you have an OCR tool that can process images from a buffer. Adjust the image.artwork() call to image.thumbnail() or image.hd() depending on the image quality you require for OCR.

For the specific encoding format you mentioned (@f4aee0239ecca855c037e61d35a1883eb263b3cfc......), it's not directly addressed in the Wechaty documentation. The focus here is on how to retrieve and process the image for OCR, regardless of its initial encoding when received from the chat.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant