jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
360 stars 59 forks source link

issues in examples #104

Closed KrystofVydra closed 3 years ago

KrystofVydra commented 4 years ago

This page is for reporting problems with the Python interface to libgphoto2. If your question is about using libgphoto2 you should ask on the gphoto2 mailing list.

Your system What version of Python are you using?

What version of libgphoto2 have you installed?

How have you installed (or attempted to install) python-gphoto2?

Your problem Please describe what you are trying to do and what goes wrong. A short Python script that shows the problem may be useful.

Ubuntu 20.04 gphoto2 2.5.23 libgphoto2 2.5.24 libgphoto2_port 0.12.0 python3 3.8.2

I have installed python-gphoto2 with sudo pip3 install gphoto2

python3 camera-summary.py outputs this:

Summary
=======
Manufacturer: Sony Corporation
Model: ILCE-6300
  Version: 2.0
  Serial Number: 00000000000000003282817005080044
Vendor Extension ID: 0x11 (1.0)
Vendor Extension Description: Sony PTP Extensions

Capture Formats: 
Display Formats: JPEG, Unknown(b301), ARW

Device Capabilities:
    File Download, No File Deletion, No File Upload
    No Image Capture, No Open Capture, Sony Capture

Storage Devices Summary:

Device Property Summary:
Compression Setting(0x5004):(readwrite) (type=0x2) Enumeration [2,3,4,16,19] value: 19
White Balance(0x5005):(readwrite) (type=0x4) Enumeration [2,4,32785,32784,6,32769,32770,32771,32772,7,32816,32786,32800,32801,32802] value: Color Temperature (32786)
F-Number(0x5007):(readwrite) (type=0x4) Range [0 - 65535, step 1] value: f/3.5 (350)
Focus Mode(0x500a):(readwrite) (type=0x4) Enumeration [1,2,32772,32773,32774] value: Manual Focus (1)
Exposure Metering Mode(0x500b):(readwrite) (type=0x4) Enumeration [4,1,32770] value: Center Weighted Average (2)
Flash Mode(0x500c):(readwrite) (type=0x4) Enumeration [2,1,4,3,5,32769,32771,32772,32817,32818] value: 32771
Exposure Program Mode(0x500e):(readwrite) (type=0x4) Enumeration [32768,32769,2,3,4,1,32848,32849,32850,32851,32852,32896,32897,32898,32853,32854,32855,32856,32899,32833,7,32785,32789,32788,32786,32787,32790,32791,32792] value: M (1)
Exposure Bias Compensation(0x5010):(readwrite) (type=0x3) Enumeration [0,5000,4700,4500,4300,4000,3700,3500,3300,3000,2700,2500,2300,2000,1700,1500,1300,1000,700,500,300,-300,-500,-700,-1000,-1300,-1500,-1700,-2000,-2300,-2500,-2700,-3000,-3300,-3500,-3700,-4000,-4300,-4500,-4700,-5000] value: 0.0 stops (0)
Still Capture Mode(0x5013):(readwrite) (type=0x4) Enumeration [1,32784,2,32789,32786,32773,32771,32772,32776,32777,32780,32781,32782,32783,33591,34103,35127,33623,34135,35159,33655,34167,35191,33553,34065,35089,33569,34081,33585,34097,33590,34102,35126,33622,34134,35158,33654,34166,35190,33552,34064,35088,33568,34080,33584,34096,32792,32808,32793,32809] value: Single Shot (1)
DOC Compensation(0xd200):(readwrite) (type=0x3) Enumeration [0,3000,2700,2500,2300,2000,1700,1500,1300,1000,700,500,300,-300,-500,-700,-1000,-1300,-1500,-1700,-2000,-2300,-2500,-2700,-3000] value: 0
DRangeOptimize(0xd201):(readwrite) (type=0x2) Enumeration [1,31,17,18,19,20,21] value: 1
Image size(0xd203):(readwrite) (type=0x2) Enumeration [1,2,3] value: 1
Shutter speed(0xd20d):(readwrite) (type=0x6) Range [0 - 4294967295, step 1] value: 65586
Property 0xd20e:(readwrite) (type=0x2) Enumeration [1,2,3,11,8,9,10,4,12,5,13,6,14,7,15] value: 12
Color temperature(0xd20f):(readwrite) (type=0x4) Range [2500 - 9900, step 100] value: 5500
Aspect Ratio(0xd211):(readwrite) (type=0x2) Enumeration [1,2] value: 1
Focus status(0xd213):(readwrite) (type=0x2) Enumeration [1,2,3,5,6,7] value: 1
ISO(0xd21e):(readwrite) (type=0x6) Enumeration [16777215,25,50,64,80,100,125,160,200,250,320,400,500,640,800,1000,1250,1600,2000,2500,3200,4000,5000,6400,8000,10000,12800,16000,20000,25600,32000,40000,51200,64000,80000,102400,128000,160000,204800,256000,320000,409600,33554431,16777241,16777266,16777280,16777296,16777316,16777341,16777376,16777416,16777466,16777536,16777616,16777716,16777856,16778016,16778216,16778466,16778816,16779216,16779716,16780416,16781216,16782216,16783616,16785216,16787216,16790016,16793216,16802816,16828416,16879616,16982016,17186816,50331647,33554532,33554632,33554832,33555232,33556032,33557632,33560832,33567232,33580032,33605632] value: 1250
Picture Effect(0xd21b):(readwrite) (type=0x4) Enumeration [32768] value: 32768
Property 0xd21d:(readwrite) (type=0x2) Range [0 - 2, step 1] value: 0
Property 0xd21f:(readwrite) (type=0x2) Enumeration [2,1] value: 1
Property 0xd217:(readwrite) (type=0x2) Enumeration [2,1] value: 1
Battery Level(0xd218):(readwrite) (type=0x1) Range [-1 - 100, step 1] value: 5
Sensor Crop(0xd219):(readwrite) (type=0x2) Enumeration [2,1] value: 2
Property 0xd212:(readwrite) (type=0x2) Range [0 - 15, step 1] value: 0
CC Filter(0xd210):(readwrite) (type=0x2) Range [164 - 220, step 1] value: 192
AB Filter(0xd21c):(readwrite) (type=0x2) Range [164 - 220, step 2] value: 192
Property 0xd221:(readwrite) (type=0x2) Enumeration [0,1,2] value: 1
Property 0xd214:(readwrite) (type=0x6) Range [0 - 4294967295, step 1] value: 33911808
Objects in memory(0xd215):(readwrite) (type=0x4) Range [0 - 65535, step 1] value: 0
Property 0xd220: error 2002 on query.
Autofocus(0xd2c1):(readwrite) (type=0x4) Enumeration [1,2] value: 1
Capture(0xd2c2):(readwrite) (type=0x4) Enumeration [1,2] value: 1
Property 0xd2c3:(readwrite) (type=0x4) Enumeration [1,2] value: 1
Property 0xd2c9:(readwrite) (type=0x4) Enumeration [1,2] value: 1
Movie(0xd2c8):(readwrite) (type=0x4) Enumeration [1,2] value: 1
Property 0xd2c5:(readwrite) (type=0x4) Enumeration [1,2] value: 1
Still Image(0xd2c7):(readwrite) (type=0x4) Enumeration [1,2] value: 1

So that works well, even the capture-image.py works perfect, choose-camera.py etc...

but I have issues with set-capture-target.py, get-capture-target.py and get-camera-clock.py none of them works.

python3 get-capture-target.py outputs this:

WARNING: gphoto2: (_get_config [config.c:8820]) Type of property 'Bulb Mode' expected: 0x0000 got: 0x0004
Traceback (most recent call last):
  File "get-capture-target.py", line 52, in <module>
    sys.exit(main())
  File "get-capture-target.py", line 38, in main
    capture_target = gp.check_result(
  File "/usr/local/lib/python3.8/dist-packages/gphoto2/result.py", line 157, in check_result
    raise gphoto2.GPhoto2Error(error)
gphoto2.GPhoto2Error: [-2] Bad parameters

python3 set-capture-target.py outputs the same

python3 get-camera-clock.py outputs:

WARNING: gphoto2: (_get_config [config.c:8820]) Type of property 'Bulb Mode' expected: 0x0000 got: 0x0004
Unknown date/time config item

Do you have any ideas what could go wrong? I just want to be able to change camera configs, that's my goal. (I got it working only in gphoto2 cli tool, and then tried a lot with libgphoto2 in c, in cpp, in python but no luck, so looks like I will probably end up using the gphoto2 cli in my script. I just want to avoid that, cuz it is pretty dirty solution.)

jim-easterbrook commented 4 years ago

You will probably need to adapt the examples to suit your camera(s). Different cameras have different names for config items, and different value ranges. The camera-config-gui.py example should display all your camera's config items and allow you to experiment with setting them.

KrystofVydra commented 4 years ago

camera-config-gui.py won't even launch. this is what I get:

ubuntu@ubuntu:/usr/local/share/python-gphoto2/examples$ python3 camera-config-gui.py 
Traceback (most recent call last):
  File "camera-config-gui.py", line 28, in <module>
    from PyQt5 import QtCore, QtWidgets
ModuleNotFoundError: No module named 'PyQt5'

I have no idea what I am doing wrong, I tried reinstalling everything updatin everything, even tried on my laptop but nothing (this is in virtual machine). I am kinda newbie to this, I usually program cpp.

KrystofVydra commented 4 years ago

Ok, I did also some googling and find out about installing PyQt5, so I did that and now I get another weird behavior.

I run python3 camera-config-gui.py and get:

WARNING: gphoto2: (_get_config [config.c:8820]) Type of property 'Bulb Mode' expected: 0x0000 got: 0x0004
Traceback (most recent call last):
  File "camera-config-gui.py", line 69, in event
    self.initialise()
  File "camera-config-gui.py", line 80, in initialise
    top_widget = SectionWidget(self.config_changed, self.camera_config)
  File "camera-config-gui.py", line 110, in __init__
    tabs.addTab(SectionWidget(config_changed, child), label)
  File "camera-config-gui.py", line 114, in __init__
    self.layout().addRow(label, RangeWidget(config_changed, child))
  File "camera-config-gui.py", line 163, in __init__
    self.setRange(int(lo * self.inc), int(hi * self.inc))
OverflowError: argument 2 overflowed: value must be in the range -2147483648 to 2147483647

And the GUI window is blank (white) and "apply change" button is greyed out. My camera is connected.

jim-easterbrook commented 4 years ago

Edit the camera-config-gui.py program, find the setRange command and then comment out that line and the one after (insert ## at the start of the line to comment it out). Go from this:

        lo, hi, self.inc = self.config.get_range()
        value = self.config.get_value()
        self.setRange(int(lo * self.inc), int(hi * self.inc))
        self.setValue(int(value * self.inc))
        self.sliderReleased.connect(self.new_value)

to this:

        lo, hi, self.inc = self.config.get_range()
        value = self.config.get_value()
##        self.setRange(int(lo * self.inc), int(hi * self.inc))
##        self.setValue(int(value * self.inc))
        self.sliderReleased.connect(self.new_value)

Then try again.

jim-easterbrook commented 4 years ago

PS I'd like to know what's causing the problem. If you get a chance, can you add a print statement and let me know what output you get:

        lo, hi, self.inc = self.config.get_range()
        value = self.config.get_value()
        print(lo, hi, self.inc, value)
##        self.setRange(int(lo * self.inc), int(hi * self.inc))
##        self.setValue(int(value * self.inc))
        self.sliderReleased.connect(self.new_value)
KrystofVydra commented 4 years ago

It is working now! even changing configs! I even managed to get the get-capture-target.py and set-capture-target.py to work (I replaced the config name with "iso" config just to try it)!

I added the print function (print(lo, hi, self.inc, value)) to the python3 camera-config-gui.py and this is the output:

I run $ python3 camera-config-gui.py and I get (everything works fine):

WARNING: gphoto2: (_get_config [config.c:8820]) Type of property 'Bulb Mode' expected: 0x0000 got: 0x0004
0.0 4294.96728515625 1.0 33.911808013916016
0.0 655.3499755859375 0.009999999776482582 3.5
0.0 65535.0 1.0 350.0
0.0 4294967296.0 1.0 65586.0
2500.0 9900.0 100.0 4500.0
164.0 220.0 2.0 192.0
0.0 4294967296.0 1.0 33911808.0
0.0 65535.0 1.0 0.0
jim-easterbrook commented 4 years ago

I guess 4294967296.0 is the culprit. I'll do some further investigation tomorrow.

Thanks for your help.

jim-easterbrook commented 4 years ago

The Qt QSlider widget doesn't accept values outside the 32 bit integer range, which is why the setRange call fails.

Some of these "slider" range and increment values look rather strange. Increments of 1 or 2 are sensible, but 0.009999999776482582? And the first has an increment of 1.0 but a current value of 33.911808013916016. However, this looks rather like Property 0xd214:(readwrite) (type=0x6) Range [0 - 4294967295, step 1] value: 33911808 listed above, so I've no idea what the values are supposed to be.

I've modified the example program to limit the range in commit 6615e7a.