How to find most recent image? - Script Writing - CHDK Forum supplierdeeply

How to find most recent image?

  • 6 Replies
  • 3654 Views
*

Offline Davo

  • ***
  • 189
How to find most recent image?
« on: 25 / September / 2019, 04:56:43 »
Advertisements
I need to find the most recent .jpg file on my SD card. I could use the os io functions to step thru all the SD files and check their properties. Is there an easier way - like a getMostRecentImage() command?

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: How to find most recent image?
« Reply #1 on: 25 / September / 2019, 06:22:43 »
The script command get_exp_count returns the number of the last exposure. With this number you can build the file name of the most recent picture.

msl
CHDK-DE:  CHDK-DE links

*

Offline reyalp

  • ******
  • 14121
Re: How to find most recent image?
« Reply #2 on: 25 / September / 2019, 14:13:12 »
chdkptp uses

Code: [Select]
string.format('%s/IMG_%04d.JPG',get_image_dir(),get_exp_count())
in various places.  Note this may not be 100% reliable in all cases on all cameras.

Also note that CHDK raw may be in a different directory, depending on menu settings.  The chdkptp shoot command has examples of code which handles this.
Don't forget what the H stands for.

*

Offline Davo

  • ***
  • 189
Re: How to find most recent image?
« Reply #3 on: 25 / September / 2019, 16:37:36 »

Thanks msl and reyalp. That should solve my problem nicely. I can't believe I missed these commands from the reference page - getting old I guess. Good point about the raw directory as I had assumed that raws were saved with jpegs.


btw, I need this to finish off an update to my AstroKam software which is coming along nicely. Latest test run is here:


http://starrydave.com/?p=959


Who needs a telescope?


*

Offline Davo

  • ***
  • 189
Re: How to find most recent image?
« Reply #4 on: 29 / September / 2019, 08:58:30 »

Finally got this to work so thanks again for the help. Below is the code I used in C# for CHDKPTPRemote.NET in case it might help someone.

I got over the raw location issue by telling users to save raws with the jpegs.

BTW, I noticed that in my SX530HS and SX230HS the raw files are saved with .DNG extension regardless of the CHDK menu extension. Is this standard across all cameras? (my software needs to download the raw files)

Code: [Select]
                string lastJPG = (string)session.ExecuteScript("return get_image_dir()") + "/IMG_"
                   + session.ExecuteScript("return get_exp_count()") + ".JPG";

*

Offline reyalp

  • ******
  • 14121
Re: How to find most recent image?
« Reply #5 on: 29 / September / 2019, 14:16:43 »
BTW, I noticed that in my SX530HS and SX230HS the raw files are saved with .DNG extension regardless of the CHDK menu extension. Is this standard across all cameras? (my software needs to download the raw files)
This should be controlled by the "'DNG' extension" option in the DNG section of raw settings. The reasons it's a separate option are a bit complicated.

If you want to detect the location + extension of raw files, you can use get_config_value() to get the various settings, see camera side code around line 1275 in chdkptp rlibs.lua https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk/lua/rlibs.lua#ln1275 (that actually uses chdkptp 1.3 config IDs, but they are still compatible). The information returned in 'r' from that function is used in cli.lua to construct the filename, in the shoot command around line 2211 https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk/lua/cli.lua#ln2211
Don't forget what the H stands for.

*

Offline Davo

  • ***
  • 189
Re: How to find most recent image?
« Reply #6 on: 01 / October / 2019, 10:01:11 »
Many thanks for taking the time to explain this for me. I had already taken the easy option of telling my users to save raws with jpegs with a CRW prefix and .DNG extension. That makes it easy to construct the raw filename from the jpeg. However, I will use your method in a future release.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal