fuill 2022-11-02 18:00 采纳率: 68.2%
浏览 97
已结题

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 18:03
    关注

    文件名称不要加括号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM