Daniel Reetz, the founder of the DIY Book Scanner community, has recently started making videos of prototyping and shop tips. If you are tinkering with a book scanner (or any other project) in your home shop, these tips will come in handy. https://www.youtube.com/channel/UCn0gq8 ... g_8K1nfInQ

Simultaneous capture with dual cameras and chdkptp.py?

Don't know where to start, or stuck on a certain problem? Drop by and tell us about it. Feel like helping others? Start here.
Post Reply
AOh
Posts: 4
Joined: 21 May 2018, 11:33
E-book readers owned: Kindle Paperwhite
Number of books owned: 1
Country: USA

Simultaneous capture with dual cameras and chdkptp.py?

Post by AOh » 22 May 2018, 16:19

I recently built David Landin's dual-camera book-scanning setup. It was a lot of fun, and I am getting perhaps 500-600 pages/hour, using a simple chdkptp.py script to stream JPEGs directly from the cameras and rename them in proper order.

However, I think I could save perhaps 5 seconds per scan if the cameras captured at the same time. My script invokes the shoot() function twice in succession, once for each camera, which results in one camera capturing and saving to disk, and once those operations finish, then the other. Is simultaneous capture supported? If so, what's the best approach? I'm new to both CHDK(PTP) and Python.

Using two Canon Powershot Elph 160s connected to an HP laptop running Ubuntu 16.04.

duerig
Posts: 368
Joined: 01 Jun 2014, 17:04
Number of books owned: 1000
Country: United States of America

Re: Simultaneous capture with dual cameras and chdkptp.py?

Post by duerig » 23 May 2018, 12:26

What you want here is a multi-process or multi-threaded program. This is how Pi Scan (which used chdkptp.py) does the simultaneous triggering.

Feel free to take a look at the code here which uses multithreading:

https://github.com/Tenrec-Builders/pi-scan

The easiest way might be to just use the Python subprocess module instead of threads. Then you could have two Python scripts. One script just uses shoot() and then uses a specified camera and saves to a file based on the command line. The other script uses subprocess to orchestrate and invoke the other script with the right arguments.

-Jonathon Duerig

AOh
Posts: 4
Joined: 21 May 2018, 11:33
E-book readers owned: Kindle Paperwhite
Number of books owned: 1
Country: USA

Re: Simultaneous capture with dual cameras and chdkptp.py?

Post by AOh » 23 May 2018, 22:11

Thanks, there's some great stuff to be found in the pi-scan source. (If I weren't trying to keep this really cheap, I'd probably just buy a Pi and use pi-scan!) I'm exploring how to handle the ptp calls with subprocesses now and will post again if I can't figure it out.

AOh
Posts: 4
Joined: 21 May 2018, 11:33
E-book readers owned: Kindle Paperwhite
Number of books owned: 1
Country: USA

Re: Simultaneous capture with dual cameras and chdkptp.py?

Post by AOh » 24 May 2018, 21:22

OK, I solved this using Python's threading package. It was pretty easy: spawn the capture for the left camera in a separate thread, then call the capture for the right camera in the main thread, then join(). Thank you for the help!

Just out of curiosity, what features are added to the IXUS 160 that necessitate a custom CHDK firmware image?

duerig
Posts: 368
Joined: 01 Jun 2014, 17:04
Number of books owned: 1000
Country: United States of America

Re: Simultaneous capture with dual cameras and chdkptp.py?

Post by duerig » 25 May 2018, 11:21

Great to see you've got it sorted.

There are two reasons why I host a custom CHDK image. First, it lets me automatically set up the configuration (enable the crosshairs overlay to let you see the center of the viewfinder more easily to perfectly align the camera with a mirror, and give permission to the computer using the camera to download crashlogs). So that is one less step when setting them up.

Second, the ELPH 160 is one of the rare cameras which has interchangeable CHDK images across its firmware versions. So unlike other cameras where you first have to find the firmware version and then pick a CHDK variant to download and use, here you can just write one image and ignore that process entirely. So it ends up being less complicated and doesn't require the download and running of extra custom software (like stick) which is necessary for the normal method of installing CHDK.

But given that you already understand the whole process to the point where you are writing your own controller, there is nothing that I have done with this image that should make you want to switch. Install CHDK normally, and then you can just change the configuration options yourself if you choose to.

-Jonathon Duerig

AOh
Posts: 4
Joined: 21 May 2018, 11:33
E-book readers owned: Kindle Paperwhite
Number of books owned: 1
Country: USA

Re: Simultaneous capture with dual cameras and chdkptp.py?

Post by AOh » 25 May 2018, 12:37

Thanks for the explanation. I wouldn't say I understand things all that well, but it was very helpful to see the pi-scan source: in addition to solving the threading issue, I was able to pull some of your code from pi-scan to add some time-saving things like auto-focus lock (which I didn't even know was a feature) and flash suppression. Next time I'm at my computer I'll also pull the ISO and preset. So thanks again for directing me that way.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests