Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyvips.Image.new_from_file(imagefilepath) - keep loading the old file even if the image has changed #54

Closed
strangerism opened this issue Jul 2, 2018 · 2 comments

Comments

@strangerism
Copy link

Hello,

I have a question related to an issue I am having while using libvips, bear with me I find out about this library just yesterday so I am quite a beginner.

I am using libvips only for image resizing because is superfast.

in my test case I am loading an image from a filepath inside a loop, the image that point to that path can change so every loop I am expecting to load a different image evethough the filepath is the same. for instance

test.py

while True:
    jobs = disque-client.get_job(['ses-faced.in'])
    for queue_name, job_id, job in jobs:
         img = pyvips.Image.new_from_file("/test/camera-capture.jpg", shrink=2)
         ..... do some image processing stuff with opencv....
         cv2.write("output", img)

/test/camera-capture.jpg is updated with a new camera sample by another process which then create a job that triggers the code above.

The problem I am experiencing is that even though the /test/camera-capture.jpg file changes on the filesystem, the call to pyvips.Image.new_from_file("/test/camera-capture.jpg", shrink=2) always return the first image loaded at the first iteration of the loop, so basically at the first run.

so this is what happens:

start this program (test.py)
first job arrives
load image from "/test/camera-capture.jpg"
do stuff
wait for next job
next job arrives (the camera process has ovewritten the camera-capture.jpg with a new image)
load image from "/test/camera-capture.jpg" ---> but the image loaded is the same as the previous job as if a cache, that points to that filename loaded during the first job, is used instead.

Is this the case, are the images loaded with this method eventually cached?
Is there any way one can close the pyvips.Image and start fresh at each loop iteration?

Many thanks,

Massimo

@jcupitt
Copy link
Member

jcupitt commented Jul 2, 2018

Hello @strangerism,

Yes, libvips keeps a cache of recent operations and returns old results if you repeat a call. This is usually a good thing, but in your case it's obviously not what you want.

You have a couple of choices:

  1. Disable the cache. You can use pyvips.cache_set_max() to set the number of cached operations. Set it to zero to disable the caching system.
  2. Use access="sequential". You could ask for the image to be streamed. You won't be able to reuse pixels, but the image won't be cached.

@strangerism
Copy link
Author

@jcupitt Thank you for the quick reply. Indeed, I have used access options and it works as I need it now.

I am closing this issue.

best wishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants