Traceback (most recent call last): File "i:\18Breakageratecalculation\SVM run\color.PY", line 19, in <module> img = cv2.resize(original_img,None,fx=0.6,fy=0.6,interpolation = cv2.INTER_CUBIC) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:4062: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
时间: 2023-09-11 19:11:19 浏览: 109
这个错误提示是由于使用 OpenCV 库中的 resize 函数时,传入的参数为空或者大小为 0 导致的。你需要检查你的代码中是否正确传入了参数,比如你的 original_img 是否已经被成功读取。同时,你也可以尝试使用其他的插值方法,如 cv2.INTER_LINEAR 或者 cv2.INTER_NEAREST 等。如果问题仍然存在,可以提供更多的代码信息以便进行排查。
相关问题
>>> import numpy as np >>> import cv2 >>> import matplotlib as plt >>> import os >>> import time >>> def save_imginfo_to_txt(filepath, txtpath): ... files = os.listdir(filepath) ... res = [] ... for file in files: ... filename = filepath + "I:\\18Breakageratecalculation\\SVM run\\pos" + file ... img = cv2.imread(filename) ... res.append([filename, 1, 0, 0, img.shape[0], img.shape[1]]) ... save_txt = txtpath + "I:\\18Breakageratecalculation\\SVM run\\pos" + "file_name.txt" ... file = open(save_txt, 'a') ... for i in res: ... file.write(' '.join([str(j) for j in i])) ... file.write("\n") ... file.close() ... >>> filepath = r"I:\18Breakageratecalculation\SVM run\pos\" File "<stdin>", line 1 filepath = r"I:\18Breakageratecalculation\SVM run\pos\" ^ SyntaxError: unterminated string literal (detected at line 1) >>> filepath = r"I:\18Breakageratecalculation\SVM run\pos" >>> txtpath = r"I:\18Breakageratecalculation\SVM run" >>> save_imginfo_to_txt(filepath, txtpath) [ WARN:0@385.483] imread_('I:\18Breakageratecalculation\SVM run\posI:\18Breakageratecalculation\SVM run\pos1.png'): can't open/read file: check file path/integrity Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 7, in save_imginfo_to_txt AttributeError: 'NoneType' object has no attribute 'shape'
在你的代码中,有几个错误需要修正。
首先,在定义 `filepath` 时,你使用了反斜杠 `\` 来转义字符,但是最后一个反斜杠没有被转义,因此需要在字符串前加上 `r` 来表示 raw string,或者在最后一个反斜杠后面再加上一个反斜杠。
其次,在调用 `cv2.imread` 时,你传递的文件名是 `filename`,但是其中包含了 `filepath`,因此实际上会读取到 `filepath + filename`,导致文件路径错误。你需要将 `filename` 中的 `filepath` 去掉,只保留文件名。
最后,在处理图片时,如果读取失败,`cv2.imread` 会返回 `None`,因此需要加上判断。如果读取成功,才能获取其形状。
下面是修改后的代码:
```
import numpy as np
import cv2
import matplotlib as plt
import os
import time
def save_imginfo_to_txt(filepath, txtpath):
files = os.listdir(filepath)
res = []
for file in files:
filename = filepath + "\\" + file
img = cv2.imread(filename)
if img is not None:
res.append([filename, 1, 0, 0, img.shape[0], img.shape[1]])
save_txt = txtpath + "\\" + "file_name.txt"
file = open(save_txt, 'a')
for i in res:
file.write(' '.join([str(j) for j in i]))
file.write("\n")
file.close()
filepath = r"I:\18Breakageratecalculation\SVM run\pos"
txtpath = r"I:\18Breakageratecalculation\SVM run"
save_imginfo_to_txt(filepath, txtpath)
```
请注意,这里的代码只是修正了语法错误,并不能保证程序的正确性,你需要根据你的需求进一步修改。
Traceback (most recent call last): File "paddle\fluid\ir.py", line 24, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module> ModuleNotFoundError: No module named 'framework_pb2' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "main.py", line 1, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "index.py", line 7, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "leis\jietuwj.py", line 8, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddleocr\__init__.py", line 14, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddleocr\paddleocr.py", line 21, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\__init__.py", line 62, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\__init__.py", line 15, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\spawn.py", line 24, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\utils\launch_utils.py", line 27, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\fleet\__init__.py", line 31, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\fleet\fleet.py", line 33, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\fluid\ir.py", line 28, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module> ModuleNotFoundError: No module named 'framework_pb2' [15508] Failed to execute script 'main' due to unhandled exception!
这是一个 Python 的错误,看起来是在使用 PaddlePaddle 框架时出现了问题。可能是因为缺少某个依赖项或环境配置不正确导致的。你可以尝试更新 PaddlePaddle 和相关的依赖项,或者检查你的环境配置是否正确。如果问题仍然存在,请查看错误信息中的文件和行号,以便更好地定位和解决问题。
阅读全文