Simultaneous capture with dual cameras and chdkptp.py - Script Writing - CHDK Forum supplierdeeply

Simultaneous capture with dual cameras and chdkptp.py

  • 7 Replies
  • 5084 Views
*

Offline AOh

  • *
  • 5
Simultaneous capture with dual cameras and chdkptp.py
« on: 22 / May / 2018, 14:27:50 »
Advertisements
I have a dual-camera book-scanning setup for which I've put together a simple chdkptp.py script to stream JPEGs directly from the cameras via the shoot() function. This was all pretty simple to set up, so thanks to any and all who were involved in chdkptp and chdkptp.py!

My question really is this: I am currently invoking shoot() first for one camera and then the other, which results in one camera shooting and saving to disk, followed by the other. Is there a way to have the cameras capture simultaneously? I could probably increase my speed by 5 seconds/scan if the cameras captured at the same time. Is this supported? If so, what's the best approach?

Using two Canon Powershot Elph 160s connected to an HP laptop running Ubuntu 16.04.
« Last Edit: 22 / May / 2018, 16:15:59 by AOh »

*

Offline reyalp

  • ******
  • 14118
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #1 on: 22 / May / 2018, 17:42:20 »
I have a dual-camera book-scanning setup for which I've put together a simple chdkptp.py script to stream JPEGs directly from the cameras via the shoot() function. This was all pretty simple to set up, so thanks to any and all who were involved in chdkptp and chdkptp.py!
You can shoot simultaneously, just execute the "shoot()" call without waiting.
I'm not sure how your script is invoking shoot, but in chdkptp this would be done using
con:exec() instead of con:execwait() in chdkptp, or '.' instead of '=' if you are using CLI commands.

You will then need to wait until the shoot calls are finished. You could poll con:script_status, or just use a hard coded delay.

If your are using remote capture to save directly over ptp without going to the SD card, you can't download simultaneously from multiple cameras using a single instance of chdkptp.
Don't forget what the H stands for.

*

Offline AOh

  • *
  • 5
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #2 on: 23 / May / 2018, 09:56:40 »
Thanks! It looks like I should just need to add the wait=False argument to the chdkptp.py shoot() method (https://chdkptppy.readthedocs.io/en/latest/#chdkptp.ChdkDevice.shoot), but this doesn't seem to have any effect.

script_status doesn't seem to be documented anywhere, and the attempts I made to call '!con:script_status()' using the chdkptp.py execute_lua() method produced errors. Not sure where to go with that.

I may just try shooting directly on the camera (i.e. not streaming) and then downloading the contents of the SD cards at the end. That would lose the image preview I get via streaming, but should increase speed.

*

Offline reyalp

  • ******
  • 14118
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #3 on: 23 / May / 2018, 13:42:03 »
Thanks! It looks like I should just need to add the wait=False argument to the chdkptp.py shoot() method (https://chdkptppy.readthedocs.io/en/latest/#chdkptp.ChdkDevice.shoot), but this doesn't seem to have any effect.
OK, I thought you were referring to the CHDK script shoot() function. The chdkptp.py function seems to be a much higher level function, more equivalent to chdkptp CLI shoot or remoteshoot.

Quote
I may just try shooting directly on the camera (i.e. not streaming) and then downloading the contents of the SD cards at the end. That would lose the image preview I get via streaming, but should increase speed.
Yes, as far as I understand the chdkptp.py doc, "stream" is what we call remote shoot. While you could in principle take the actual shots near-simultaneously, the downloads would be done sequentially if everything is running in one instance of chdkptp.

FWIWI, if your exposure and focus are fixed, you can speed up shooting significantly by holding half press down and clicking shoot full, so the camera doesn't go through the normal pre-shoot process every shot. Doing this for multiple cameras through chdkptp.py would be require some coding.

Quote
script_status doesn't seem to be documented anywhere, and the attempts I made to call '!con:script_status()' using the chdkptp.py execute_lua() method produced errors. Not sure where to go with that.
According to the doc, lua_execute (not execute_lua) runs camera side lua.

To execute chdkptp side lua, https://github.com/jbaiter/chdkptp.py/blob/master/chdkptp/lua.py suggests you'd use luaContext execute.

The ! is a chdkptp CLI command to execute local lua, so you'd only use that if interacting directly with the CLI or using cli:execute()
Don't forget what the H stands for.


*

Offline AOh

  • *
  • 5
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #4 on: 23 / May / 2018, 21:58:51 »
Thanks for the tips on luaContext. I'm going to try a few things out and see what sticks. I'll report back.

*

Offline AOh

  • *
  • 5
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #5 on: 24 / May / 2018, 20:56:46 »
On advice I got in another forum and solved this more easily using multithreading in Python. Thanks again for the tips!

*

Offline reyalp

  • ******
  • 14118
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #6 on: 24 / May / 2018, 22:00:13 »
On advice I got in another forum and solved this more easily using multithreading in Python. Thanks again for the tips!
I'm not sure how you are doing approaching this (and don't know much about python), but FWIW, chdkptp itself is not mult-threaded. You can run multiple independent instances of chdkptp if you are careful.
Don't forget what the H stands for.

*

Offline AOh

  • *
  • 5
Re: Simultaneous capture with dual cameras and chdkptp.py
« Reply #7 on: 24 / May / 2018, 22:06:10 »
Yeah, what it seems to be doing is sending capture events more or less simultaneously, but the "streaming" back of the data is sequential. So there is still a delay, but it is faster.


 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal