Discussion:
[Gphoto-user] Full size image capture & autofocus with ctypes in python
derosiat2
2015-01-30 05:37:53 UTC
Permalink
I'm working on a raspberry pi photobooth application. I don't know how to get
the camera to focus at the beginning of the preview process though.

It can show a live preview (really choppy) then grab an image and email you
a copy of it with a watermark. Hopefully you can see it here:
https://github.com/derosiat2/dslr-photobooth

But! The image it grabs is only live view sized not the size I would get if
I did a >>gphoto2 --capture-image-and-download --filename "filename.jpg"

I don't want to go to the command line to capture the image because I think
I'll have to release the camera and then it'll have to reinitialize and
that'll be too slow. The code I'm using looks like this and honestly don't
know what fil and ctx are, I got them from another post in this forum:

#start gphoto specific calls
gp = ctypes.CDLL('libgphoto2.so')

GP_OK = fileNbr = 0
GP_VERSION_VERBOSE = 1

cam = ctypes.c_void_p()
gp.gp_camera_new(ctypes.byref(cam))
ctx = gp.gp_context_new()
fil = ctypes.c_void_p()
gp.gp_file_new(ctypes.byref(fil))
#end gphoto specific calls

#trying to capture full size image, but it only comes out as a preview sized
image
gp.gp_camera_capture(cam, fil, ctx)
cData = ctypes.c_void_p()
cLen = ctypes.c_ulong()
gp.gp_file_get_data_and_size(fil, ctypes.byref(cData), ctypes.byref(cLen))
full_string = ctypes.string_at(cData.value, cLen.value)
full_size = Image.open(StringIO.StringIO(full_string))
mark = Image.open('logo.png')
#This adds a watermark 70% over, 70% down and 30% the size of the image with
1.0 alpha
full_size = watermark.watermark(full_size, mark, (.70, .70), .3, 1.0)
full_size.save('%s.jpg' % email)



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Full-size-image-capture-autofocus-with-ctypes-in-python-tp15072.html
Sent from the gphoto-user mailing list archive at Nabble.com.
j***@gmail.com
2015-01-30 09:12:24 UTC
Permalink
Hi, I did a gphoto GUI in Python with ctypes, you can see the source here:

https://github.com/jcupitt/rtiacquire

You're welcome to borrow any ideas. It can do a live preview at 30fps
(on my modest laptop) and can grab a full-res image via gphoto without
shelling out. The camera controls are in camera.py:

https://github.com/jcupitt/rtiacquire/blob/master/rtiacquire/camera.py

That will make a dialog box for all the settings too.
Post by derosiat2
I'm working on a raspberry pi photobooth application. I don't know how to get
the camera to focus at the beginning of the preview process though.
In my experience this depends very strongly on the lens and camera.
You'll need to fiddle with the settings to get it working, and it'll
mysteriously stop working if you change anything.

John
derosiat2
2015-01-30 13:54:40 UTC
Permalink
Hello John,

Thanks for responding! I actually tried RTIAcquire first. I wasn't smart
enough to get it to work on my pi at the onset so I started going down my
own path.

But, good news! I finally worked up the courage to open your source files
and I just had to modify your frame_timeout in the preview.py file to 120
(100 didn't work) and IT WORKED. I still get much better performance than
with my program. Much much better. I do also get a constant stream of errors
running down the screen in the background and I'm not sure if your capture
is actually working. But your focus button does work for me.



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Full-size-image-capture-autofocus-with-ctypes-in-python-tp15072p15076.html
Sent from the gphoto-user mailing list archive at Nabble.com.
j***@gmail.com
2015-01-30 14:10:34 UTC
Permalink
Post by derosiat2
But, good news! I finally worked up the courage to open your source files
and I just had to modify your frame_timeout in the preview.py file to 120
(100 didn't work) and IT WORKED. I still get much better performance than
Hey, great!
Post by derosiat2
with my program. Much much better. I do also get a constant stream of errors
running down the screen in the background and I'm not sure if your capture
is actually working. But your focus button does work for me.
It should be possible to fix the errors. I have an r-pi but no camera
supported by gphoto, unfortunately, so I can't help.

John
derosiat2
2015-01-30 23:52:10 UTC
Permalink
Hey John,

I am getting an error when I try to capture an image while running the live
preview in RTIAcquire.

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rtiacquire/rtiacquire.py",
line 118, in photo_cb
self.light_hop_cb()
File "/usr/local/lib/python2.7/dist-packages/rtiacquire/rtiacquire.py",
line 138, in light_hop_cb
nlights = len(self.get_lights())
File "/usr/local/lib/python2.7/dist-packages/rtiacquire/rtiacquire.py",
line 132, in get_lights
index = self.dome_picker.get_active()
AttributeError: 'MainWindow' object has no attribute 'dome_picker'

I don't know what's going on here at all or what dome_picker is or what the
get_lights and light_hop_cb functions do.



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Full-size-image-capture-autofocus-with-ctypes-in-python-tp15072p15078.html
Sent from the gphoto-user mailing list archive at Nabble.com.
j***@gmail.com
2015-01-31 09:47:19 UTC
Permalink
Hi again,
Post by derosiat2
I am getting an error when I try to capture an image while running the live
preview in RTIAcquire.
Oh dear, sorry, I think I've fixed it with this patch, try again:

https://github.com/jcupitt/rtiacquire/commit/7a65b46a7da095aa1a46e43905b125e35eae5202

Background: the program was written for reflectance transform imaging.
You put the object under a dome, the inside of the dome has perhaps 80
LED lights, you take 80 photos, one with each light, then reconstruct
a pseudo-3D from the results.

http://www.ashmolean.org/departments/antiquities/research/research/rtisad/

You can view one of the images here (needs a webgl browser):

http://vcg.isti.cnr.it/rti/webviewer.php

RTIAcquire runs the process: it talks to the lighting dome and the
camera and will take the 80 photos for you automatically.

If it doesn't detect a dome on startup, it does not display the
lighting controls and you can use it as a simple gphoto GUI. The bug
you found was a line of code someone added to step the lights on
without checking that a dome was present.

John
derosiat2
2015-01-31 15:45:43 UTC
Permalink
John,

I have no idea why but your check appears to be giving me some performance
issues. I added the lines manually because I'm a Luddite I guess.
- self.light_hop_cb()
+ if self.dome_controls:
+ self.light_hop_cb()

If I just comment out self.light_hop_cb() everything works well. If I add
your if statement then preview stops working on my pi, except for one
instance when I took a picture, paused the live view and then started it
again it worked. Since I'm going never going to use a dome this is fine for
me, but I thought I'd give you a heads up.

The RTI pictures you guys produced are awesome though!



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Full-size-image-capture-autofocus-with-ctypes-in-python-tp15072p15081.html
Sent from the gphoto-user mailing list archive at Nabble.com.
j***@gmail.com
2015-01-31 16:47:50 UTC
Permalink
Post by derosiat2
I have no idea why but your check appears to be giving me some performance
issues. I added the lines manually because I'm a Luddite I guess.
How bizarre. Could it be a tab/space indenting problem?

I've added a note to test this next time I get a chance.

John
derosiat2
2015-02-01 16:52:37 UTC
Permalink
John,

It could have been a tab/spacing issue on my end. I broke your software so I
had to install it. I forgot it was as simple as "sudo python setup.py
install" from the directory I cloned the github files to. I'm glad I'm
keeping notes somewhere.

Anyway your update appears to work on my Raspberry Pi as long as I go back
in and change the frame_timeout back to 150 ms in the preview.py file. Thank
you for all your help.



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Full-size-image-capture-autofocus-with-ctypes-in-python-tp15072p15086.html
Sent from the gphoto-user mailing list archive at Nabble.com.
derosiat2
2015-02-26 19:00:43 UTC
Permalink
Hey John,

RTIAcquire comment/observation when used with a Raspberry Pi 2.

I got a Raspberry Pi 2 in the mail a few days ago and tried to get
RTIAcquire working on it. It has an issue where if you take a picture it
doesn't release the camera. Even after adding buttons to manually release
the camera it still doesn't work so the only way I could recover was to turn
the camera off and back on again. This could just be an issue with older
cameras like my Nikon D5100 used with "relatively fast computers" but I
managed to fix it by adding a "time.sleep(.05)" before the "self.release()"
command in the capture_to_file function.

I'm sure this is not the best way to handle this issue, but it seems to be
working consistently. I'm hoping you could suggest and/or implement a more
elegant solution.

The exact error I'm getting is:
ERROR:root:error - ptp_usb_getresp [usb.c:434]: PTP_OC 0x90c2
receiving resp failed: Change Camera Mode Failed (0xa003)
ERROR:root:error - gp_port_usb_close [libusb.c:322]: Invalid
parameters: 'port && port->pl->dh' is NULL/FALSE.

Actually even after adding the delay I still get the second error but it
doesn't appear to affect anything:
ERROR:root:error - gp_port_usb_close [libusb.c:322]: Invalid
parameters: 'port && port->pl->dh' is NULL/FALSE.


Kind regards,
James DeRosia



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Full-size-image-capture-autofocus-with-ctypes-in-python-tp15072p15157.html
Sent from the gphoto-user mailing list archive at Nabble.com.

Loading...