简体   繁体   English

打开最近保存的图像并显示它们 python opencv

[英]Open recently saved images and display them python opencv

I am creating a program on Python and opencv that detects an object and when detecting it It takes a capture, the problem is that I need to use that photo just taken to apply other effects and I do not know how to do it, if you could help me it would be fantastic.我正在 Python 和 opencv 上创建一个程序来检测一个对象,当检测到它时它需要一个捕获,问题是我需要使用刚刚拍摄的照片来应用其他效果,我不知道该怎么做,如果你可以帮助我这将是太棒了。 Here are the lines of code where I am saving the photos taken within a for cycle这是我保存在 for 循环内拍摄的照片的代码行

archive = cv2.imwrite(folder + '/' + date_time + str(y) + '.jpg', object)

image = cv2.imread(archive)

I wanted to observe it on the screen first using this line but it returns me an error我想首先使用这一行在屏幕上观察它,但它返回一个错误

cv2.imshow('object', image)

maybe it's very obvious but I don't know how to do it please help也许这很明显,但我不知道该怎么做,请帮忙

Making sure the path to your image is correct.确保图像的路径正确。 Are you getting the latest image based on the current datetime.The time will not the same with the one you saved.您是否根据当前日期时间获取最新图像。时间将与您保存的时间不同。 You can consider to get the latest image path from directory from the code below.您可以考虑从下面的代码中获取目录中的最新图像路径。

#!/usr/bin/env python3
import argparse
import cv2
import numpy as np
from PIL import Image
import os
from PIL import Image, ImageDraw, ImageFilter
import glob



ap = argparse.ArgumentParser()
ap.add_argument("-p", "--path", required=True, help="Path to the image")
args = vars(ap.parse_args())


list_of_files = glob.glob(args["path"]+"/*")
latest_file = max(list_of_files, key=os.path.getctime)
print (latest_file)
img = cv2.imread(latest_file)


cv2.namedWindow('image')
while(1):
    cv2.imshow('image',img)

    k = cv2.waitKey(1) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM