python - imshow 仅适用于外部范围
问题描述
我正在尝试显示代码每个阶段的输出,但 imshow 似乎不适用于内部函数
我用一个 imshow 行创建了一个空函数来测试它,它仍然没有显示给它的实际图像,而是显示一个充满 0 的小图像
另一个观察结果是,它在循环结束时将每个循环图像显示在一个名为“测试”和“原始图像”的单独窗口中,您有 n*2 个窗口(这两个名称重复),其中 n 是图像的数量
def test_(clr_img):
cv2.imshow("test image", clr_img)
def loop_folder(folder_path, save_path, debug=True):
"""Applies the label_chars function to every image in a folder and saves at the save_path
"""
json_name_list = []
for file_name in listdir(folder_path):
if file_name.endswith(".json"):
json_name_list.append(file_name)
for json_file_name in tqdm(json_name_list):
json_path = path.join(folder_path, json_file_name)
with open(json_path) as json_file_r:
json_data = json.load(json_file_r)
image_file_path = json_path.replace(".json", ".png")
image = cv2.imread(image_file_path)
if debug:
img = image.copy()
cv2.imshow("original image", image) # this one shows everytime
test_(image) # this one sometimes shows
cv2.waitKey(0)
cv2.destroyAllWindows()
我正在使用 opencv 4.3.0.36 和 python 3.7
解决方案
所以问题是opencv本身,它可以在其他PC上运行,所以我尝试重新安装opencv,现在它可以正常工作了
推荐阅读
- python - Tkinter 错误:_tkinter.TclError:未知选项“-menu”
- shell - 我的 cron 作业失败了,但是脚本执行得很好。有人可以帮忙吗?
- javascript - 如何从命令行或 javascript 打开 WhatsApp Mac
- r - 创建一个新的 var,其值应该是 r 中其他两个变量之间的平方差
- python - 从 2.7 升级到 3.6 时出现 python requests.post 错误
- ios - 在 Web 视图中从社交媒体下载视频
- python - 每次部署后强制重新安装 Python 包(Flask + Azure App Service)
- django - 应用程序无法读取 django 中的静态文件
- listview - 删除项目时列表不更新
- haskell - 如何在 Haskell 中导入 Math.X?