简体   繁体   中英

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. Here are the lines of code where I am saving the photos taken within a for cycle

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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