我已使用此代码从图像文件中读取文本。 Reading text from image
代码如下
from PIL import Image
from pytesseract import image_to_string
image = Image.open("image.jpg",'r')
myText = image_to_string(Image.open(open('maxresdefault.jpg')),config='-psm 10')
myText = image_to_string(Image.open(open('maxresdefault.jpg')))
print(myText)
错误:UnicodeDecodeError:'charmap'编解码器无法解码位置278中的字节0x81:字符映射到
尝试通过以下方式解决此错误:UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
然后得到错误:
UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0xff:无效的起始字节
答案 0 :(得分:0)
根据Image
文档(help(Image.open)
),必须以二进制模式打开图像文件:
open('maxresdefault.jpg', 'rb')
答案 1 :(得分:0)
以二进制格式加载图像。
更改以下代码为我解决了这个问题。
import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/material.dart';
import 'package:travelbrains/models/story.dart';
class AnimationPlayer extends StatefulWidget {
static const String id = 'AnimatedPlayer';
final Story story;
AnimationPlayer(this.story);
@override
_AnimationPlayerState createState() => _AnimationPlayerState();
}
class _AnimationPlayerState extends State<AnimationPlayer> {
String animPath;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Animation Test'),
),
body: FlareActor(
widget.story.animationRef.toString(),
// "assets/flare.flr",
alignment: Alignment.center,
fit: BoxFit.contain,
animation: 'myAnim',
),
);
}
}
希望有帮助!