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日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么