fuill 2022-11-02 10:00 采纳率: 66.7%
浏览 101
已结题

python代码报错

import cv2

import os
import numpy as np

import matplotlib.pyplot as plt

import cv2 as cv

from PIL import Image

import pytesseract as tess

# 验证码识别

image_url = "D:\\python\\psc.jpg"  # 要识别的图片


img = cv2.imread(image_url)

img = cv2.blur(img, (3, 3))


# cv2.imshow('yzm',img)


gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


# cv2.imshow('gray',gray)


ret, binary = cv2.threshold(
    gray, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_TRIANGLE)


kernel1 = cv2.getStructuringElement(cv2.MORPH_RECT, (6, 6))


kernel2 = cv2.getStructuringElement(cv2.MORPH_RECT, (4, 4))


open1 = cv2.erode(binary, kernel=kernel1)


open2 = cv2.morphologyEx(open1, cv2.MORPH_OPEN, kernel=kernel2)
# cv2.imshow('detect',open2)

cv2.bitwise_not(open2, open2)


textimg = Image.fromarray(open2)


text = tess.image_to_string(gray)


print("验证码为:%s" % text)


cv2.waitKey()

报错信息

所在位置 行:1 字符: 93
+ ... l/Programs/Python/Python39/python.exe c:/Users/123/Desktop/print().py
+                                                                      ~
“(”后面应为表达式。
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedExpression

重新编译后

Traceback (most recent call last):
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 255, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    text = tess.image_to_string(gray)
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 423, in image_to_string
    return {
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 426, in <lambda>      
    Output.STRING: lambda: run_and_get_output(*args),
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 288, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 260, in run_tesseract 
    raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
PS C:\Users\123\Desktop\C> & C:/Users/123/AppData/Local/Programs/Python/Python39/python.exe "d:/python/import cv2.py"
Traceback (most recent call last):
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 255, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python\import cv2.py", line 24, in <module>
    text = tess.image_to_string(gray)
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 423, in image_to_string
    return {
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 426, in <lambda>      
    Output.STRING: lambda: run_and_get_output(*args),
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 288, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\123\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 260, in run_tesseract 
    raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.

展开全部

  • 写回答

3条回答 默认 最新

  • honestman_ 2022-11-02 10:03
    关注

    文件名称不要加括号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    fuill 2022-11-02 10:07

    改了文件名后还是报错,你看看

    回复
    honestman_ 回复 fuill 2022-11-02 15:26

    tesseract 没有安装

    回复
查看更多回答(2条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 11月10日
  • 已采纳回答 11月3日
  • 修改了问题 11月2日
  • 创建了问题 11月2日

悬赏问题

  • ¥50 数据库开发问题求解答
  • ¥15 安装anaconda时报错
  • ¥20 如何用Python处理单元格内连续出现的重复词语?
  • ¥15 小程序有个导出到插件方式,我是在分包下引入的插件,这个export的路径对吗,我看官方文档上写的是相对路径
  • ¥20 希望有人能帮我完成这个设计( *ˊᵕˋ)
  • ¥100 将Intptr传入SetHdevmode()将Intptr传入后转换为DEVMODE的值与外部代码不一致
  • ¥50 基于ERA5数据计算VPD
  • ¥15 寻找杂志《Tornatzky, L. G., & Fleischer, M. (1990). The Processes of Technological Innovation. 》
  • ¥15 前台多人编辑时怎么让每个人保存刷新都互不干扰
  • ¥20 如何用Python删除单元格内连续出现的重复词?
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部