Main Virtual Tours SC2 Linux

Using USB API (MTP) with libghoto2 and Python bindings on MacOS, Raspberry Pi, Linux, ROS

Hello,

I had the same error with gphoto2 installed from apt. The fix is working but you need to modify and recompile libgphoto2.
It will be nice if you make a pull request. Before that if someone could check the VendorID on others Theta cameras in order to make the correction for all the theta models.

Hugues

3 Likes

Thank you for all your work and insight.

  1. I changed the title of the topic to reflect the actual discussion which evolved beyond MacOS
  2. I added a note to the very top post from the “moderator” to let people know that the topic changed

I’ll also try and help test this. There’s been a new surge in interest in the USB API, possibly driven by the increased demand for virtual surveillance.

BTW, if anyone with a good business opportunity is looking to partner with a company with experience in the USB API and streaming, please check out the article on FOX Sewer Rover and consider contacting Hugues with a great business opportunity. :slight_smile: Note the followup posts covering his modifications.

@Hugues is the VendorID, the same as the VendorExtensionID?

From the MTP Specification.

If so, I can run it against the cameras I have. I believe the extension ID is 0x00000006 on all of them, but I can check. In the libptp source code, this ID is assigned to Microsoft.

Z1

Camera information
==================
Model: RICOH THETA Z1
  manufacturer: Ricoh Company, Ltd.
  serial number: '10010104'
  device version: 1.50.1
  extension ID: 0x00000006
  extension description: (null)
  extension version: 0x006e

V

Camera information
==================
Model: RICOH THETA V
  manufacturer: Ricoh Company, Ltd.
  serial number: '00105377'
  device version: 3.40.1
  extension ID: 0x00000006
  extension description: (null)
  extension version: 0x006e

SC2 for business

This is the same as the SC2. The firmware number is different, but everything else should be the same for our purposes.

Camera information
==================
Model: RICOH THETA SC2
  manufacturer: Ricoh Company, Ltd.
  serial number: '40100146'
  device version: 06.12
  extension ID: 0x00000006
  extension description: (null)
  extension version: 0x006e

@NaokiSato102, I have not looked into the GitHub pull request. Please proceed with your testing and I can try and support your efforts. To do a pull request, you’ll need to fork the project first and do the modification, then test the modifications, then do the pull request.

My status:

  • I have compiled libghoto2 from source with no problems on Ubuntu 20.04 on x86
  • I have not installed or tested it as I think I need to first uninstall my existing libghoto2 and I am afraid my system will stop working
  • I have not applied the modifications

My plan:

  • I’ll attempt to compile it from source on a Raspberry Pi. If it’s possible, I’ll experiment with the modifications
  • if it takes too long due to the size of the project, I will try a different computer or a VM.
  • I will report back here
3 Likes

I couldn’t get it to work with the lib I installed with apt, either. (summarized)

Thank you @Hugues for checking the behavior.
I’m going to try the following on Raspberry Pi 3B+ before I try it in the production development environment.

  1. Try it with a lib you got with apt (it’s expected to not work properly. Continue with the test in 3)
  2. Try with a modified lib in a clean environment. (It is expected to work properly.)
  3. Uninstall the apt lib introduced in step 1, and try the modified lib. (Same as above.)

And if 2 and 3 go well, I’ll try it out in the production development environment.
I’ll make the transition between 1 and 2 by backing up the disk image.

Maybe the problem is that the lib that can be installed with apt is not updated to the latest version of git yet, and it works fine if you install it from the git source.
So I’m going to change the process to the following

  1. Try it with a lib you got with apt (it’s expected to not work properly. Continue with the test in 4)
  2. Try it with a lib you got with git (it’s expected to not work properly.)
  3. Try with a modified lib in a clean environment. (It is expected to work properly.)
  4. Uninstall the apt lib introduced in step 1, and try the modified lib. (Same as above.)

@mhenrie 's program on Ras-pi

What ?! Of course I installed libgphoto2 and PygPhoto2.

Traceback (most recent call last):
File “huga.py”, line 13, in
import gphoto2 as gp
ImportError: No module named gphoto2

Probably because of the lack of a path. I’m too sleepy to come up with a solution.

20/09/27 Added because the problem has been solved.

I installed gPhoto2 in pip, which is pip3 and works fine in Python3.
However, I didn’t install it in pip2, so it didn’t work in Python2.
The un-numbered Python in raspberry pi refers to 2, so that’s why it didn’t work.

What a rudimentary error.

Also, after resolving this, I had the usual mount-related errors, and since this is a CUI environment and I couldn’t use the sequential unmounting method by gvfs-mount, which I often use in my environment, I solved it by removing gvfs-backends and got it running.

The conclusion is that the first experiment failed as expected.

According to this article, the reason why gvfs-mount is not available can be solved by apt install gvfs-dbg.

However, when I looked closely, I saw an error in a different area. The error occurred one step or line later than last time.

Traceback (most recent call last):
File “huga.py”, line 234, in
_unittest()
File “huga.py”, line 210, in _unittest
camera.init()
File “huga.py”, line 118, in init
fstop = self.other_config.get_child_by_name(F_NUMBER)
gphoto2.GPhoto2Error: [-2] Bad parameters

Thank you for all this great information.

  1. Do you have the file huga.py available somewhere so that we can test the same file?
  2. Can you provide more information on how you’re using gvfs-dbg. I am not familiar with this and would like to solve the problems I’m having when I use gvfs automount and libptp2 at the same time. Did you uninstall gvfs-backends and then install gvfs-dbg?
  3. Did you completely remove the gvfs packages that can be installed with apt?
  4. Are you building gphoto2 on your Raspberry Pi 3? Does it take a long time?

My status

  • I didn’t try this on a Raspberry Pi as I was worried it was going to take too long to to compile and test gphoto2.

I decided to remove gphoto2 from my x86 i7 system and install things from source.

$ df |grep gphoto2
/dev/loop18        16512    16512         0 100% /snap/gphoto2/8
$ snap remove gphoto2
gphoto2 removed
$ sudo apt remove libgphoto2-dev

In the newest version of libphoto2 from github, modified the code per hugues post.

$ make
$ sudo make install

No problems.

I installed gphoto2 from source.

$ gphoto2 --version
gphoto2 2.5.23.1
...
This version of gphoto2 is using the following software versions and options:
gphoto2         2.5.23.1       gcc, popt(m), exif, no cdk, no aa, no jpeg, no readline
libgphoto2      2.5.25         standard camlibs (SKIPPING lumix), gcc, ltdl, EXIF
libgphoto2_port 0.12.0         iolibs: disk ptpip serial usb1 usbdiskdirect usbscsi, gcc, ltdl, EXIF, USB, serial without locking
$ which gphoto2
/usr/local/bin/gphoto2

Tests

$ gphoto2 --list-cameras |grep 'Ricoh Theta'
	"Ricoh Theta (WLAN)" (TESTING)
	"Ricoh Theta m15 (PTP mode)"
	"Ricoh Theta S (PTP mode)"
	"Ricoh Theta SC (PTP mode)"

$ gphoto2 --get-config shutterspeed
Label: Shutter Speed                                                           
Readonly: 0
Type: RADIO
Current: Auto
Choice: 0 Auto
END
$ gphoto2 --set-config=/main/other/500e=4 
Label: Shutter Speed                                                           
Readonly: 0
Type: RADIO
Current: 1/60
Choice: 0 1/25000
Choice: 1 1/20000
Choice: 2 1/16000
Choice: 3 1/12500
Choice: 4 1/10000
Choice: 5 1/8000
Choice: 6 1/6400
Choice: 7 1/5000
Choice: 8 1/4000
Choice: 9 1/3200
Choice: 10 1/2500
...
$ gphoto2 --set-config=/main/other/500e=2
$ gphoto2 --get-config shutterspeed                 
Label: Shutter Speed                                                           
Readonly: 0
Type: RADIO
Current: Auto
Choice: 0 Auto

Overall Status

  • At the moment, I still don’t have python-gphoto2 working properly.

I’m not sure how it pulls the vendor and product id.

$ python list_files.py 
WARNING: gphoto2: (gp_port_set_error [gphoto2-port.c:1190]) The supplied vendor or product id (0x0,0x0) is not valid.

I can get the port and device from gphoto2 --autodetect

$ gphoto2 --auto-detect
Model                          Port                                            
----------------------------------------------------------
USB PTP Class Camera           usb:005,003     

However, the python library is showing 0x0, 0x0

$ gphoto2 --summary
Camera summary:                                                                
Manufacturer: Ricoh Company, Ltd.
Model: RICOH THETA Z1
  Version: 1.50.1
  Serial Number: 10010104
Vendor Extension ID: 0x6 (1.10)
  1. I left out the explanation, but huga.py is @mhenrie 's program.

  2. I was just wondering if installing gvfs-dbg would save me from having to uninstall gvfs-backs, but I haven’t tried that in this raspberry-pi environment.
    “gvfs-dbg was not installed in the production development environment where gvfs-mount -u {path}” was available.
    Instead, gvfs, gvfs-bin, gvfs-daemon, gvfs-fuse, and gvfs-lib(:arm64) were installed.
    Any of these have “gvfs-mount -u {path}” available, and that’s what’s important.
    You can unmount them by looking up bus,dev in Theta and typing
    gvfs-mount -u /run/user/1000/gvfs/mtp:host=%5B{bus}%2C{dev}%5D.
    Note that the string after “host=” means the URL encoded string of [{bus}:{dev}].
    Just for reference.
    I don’t know which gvfs* can do this, but I think you should include them all for now.
    (That’s an irresponsible statement.)

  3. gvfs-backends Just uninstalling it was enough.

  4. If you have a fast enough internet connection and a working environment that doesn’t put too much strain on your raspberry-pi, you’ll be set up in no time. Because all you have to do is sudo apt install libgphoto2 and pip install gphoto2.
    I just uninstall gvfs-backends if needed.
    I haven’t tried building from git sources yet. Because I haven’t been able to find a reason for the current event that the point at which the error occurs has changed.
    If I can ignore it, I’ll move on to the second experiment.

I’m not sure about Vendor IDs or Product IDs yet, but list-files.py does work with the error. Doesn’t theta there shoot anything? Or did you just omit the display and it showed up correctly?
Examples of my results

WARNING: gphoto2: (foreach_func [gphoto2-port-info-list.c:237]) Error during assembling of port list: 'Unspecified error' (-1).
WARNING: gphoto2: (gp_port_set_error [gphoto2-port.c:1186]) The supplied vendor or product id (0x0,0x0) is not valid.
File list
=========
/store_00020001/DCIM/100RICOH/R0010132.MP4
/store_00020001/DCIM/100RICOH/R0010133.MP4
/store_00020001/DCIM/100RICOH/R0010134.MP4
/store_00020001/DCIM/100RICOH/R0010135.MP4
/store_00020001/DCIM/100RICOH/R0010136.JPG
/store_00020001/DCIM/100RICOH/R0010137.MP4
/store_00020001/DCIM/100RICOH/R0010138.MP4
...
/store_00020001/DCIM/100RICOH/R0010132.MP4
/store_00020001/DCIM/100RICOH/R0010133.MP4
/store_00020001/DCIM/100RICOH/R0010134.MP4
/store_00020001/DCIM/100RICOH/R0010135.MP4
/store_00020001/DCIM/100RICOH/R0010136.JPG
/store_00020001/DCIM/100RICOH/R0010137.MP4
/store_00020001/DCIM/100RICOH/R0010138.MP4
File info
=========
image dimensions: 1920 960
image type: video/mp4
file mtime: 2020-09-02 19:55:11
1 Like

If you have time, I’d appreciate it if you could reply to me.

Hi, sorry for the delay. I was trying to get more progress before I updated the group here. Unfortunately, I still don’t have libgphoto2 working properly with Python bindings.

Currently, list-files.py does work for me, but I get the same WARNING at the top as you. I would like to eliminate the warning. The output does work, but it is not satisfying.

When I used mhenrie’s program, I have a different error. I get the ‘Unable to copy DNG’ error raised by this section.

        gp_dng_path = wait_for_event(self.camera, timeout=TIMEOUT_CAPTURE_DNG, event_type=gp.GP_EVENT_FILE_ADDED)
        if not gp_dng_path:
            raise RuntimeError('Unable to copy DNG')

Thus, the command line program gphoto2 works for me, but the Python bindings in libgphoto2 do not work.

At the moment, I am using ptpcam from libptp2 inside of programs by running running a shell process inside of my program. As the API commands are not time sensitive, this seems to work, but is not satisfying.

The C functions inside of libptp are not that friendly to use, so I would like to use libghoto2, but I’m not sure if the full library of API commands work with the THETA.

I believe the best path forward is to use mhenrie’s program and modify the _unittest to test less features first, then apply a debugger and see what is happening to the variable dng_path

I just thought that maybe you hadn’t noticed. I’m sorry if I rushed you.

I have been wondering for a long time if it is possible to fix the error at the time of video shooting by modifying the source code of libgPhoto2.
@Hugues has suggested the possibility of resolving the error by modifying the source.
Could it be possible to fix the problem as well, so that gphoto2 --set-config movie=0 does not stop video recording?
I think I can do it.
But I can’t write it because I don’t know what the source code is, but it’s too big for me.
I should be able to figure it out by myself sooner or later.
Is it naive to wait for someone to solve the problem?

Aside from that, I had a similar error when using @mhenrie’s program.
When I saw that error, I took a peek at the shutter speed and exposure time settings that weren’t working properly and made them work.

We have many options.

  • Keep trying the libgPhoto2 system

    • We will continue to use the python-gphoto2 system, which converts C code by SWIG, with analysis and improvement.

    • Use gphoto2-cffi, which is converted by cffi
      I believe operational testing is not yet available on this forum. git, pypi

    • Another use of piggyphoto to convert with another ctype
      ‘This is a very rough proof of concept. feel free to play with it and add improvements.’
      so you might not expect it to work very well. git

  • Try the Python binding in linptp2
    I can’t find anything useful here, according to my research.
    I found a hit on git, but it’s not available on Linux because they don’t know how to compile it as a shared library.
    Does anyone know how to use it?

By the way, I’m going to move on to the next phase of operational testing.

1 Like

I have the same problem with libgphoto2. It is a big project. I have a difficult time understanding it.

I do not think anyone else will solve the problem. It may be up to you if you want the challenge. :slight_smile:

John Thomas was looking at https://github.com/Parrot-Developers/sequoia-ptpy

The last I checked, he did not have it working around 3 weeks ago. Maybe it is working now?

I understand that it is better to have working Python bindings when using ROS on Linux. However, I think that people can run shell process if they need to as a workaround.

In the discussion of that GitHub issue, you may notice a reference to a RICOH USB SDK. Note that SDK is not the SDK for the RICOH THETA. It is for other RICOH cameras.

1 Like

I don’t know if it will be usefull for you but to stop the video recording I’m using the command
gphoto2 --set-config=/main/actions/opcode=0x1018,0xFFFFFFFF

Hugues

2 Likes

I’m surprised there’s such a solution! But unfortunately, it didn’t work in my environment.
My environment is as below.

  • Ubuntu 16.04LTS
  • ThetaV 3.40.1
  • gphoto2 2.5.9
  • libgphoto2 2.5.9
  • libgphoto2_port 0.12.0

※gPhoto2 related items are all unmodified

gphoto2 --set-config=/main/actions/opcode=0x1018,0xFFFFFFFF

*** Error ***
The /main/actions/opcode widget is not configurable.
*** Error (-2: ‘Bad parameters’) ***

For debugging messages, please use the --debug option.
Debugging messages may help finding a solution to your problem.
If you intend to send any error or debug messages to the gphoto
developer mailing list gphoto-devel@lists.sourceforge.net, please run
gphoto2 as follows:

env LANG=C gphoto2 --debug --debug-logfile=my-logfile.txt --set-config=/main/actions/opcode=0x1018,0xFFFFFFFF

Please make sure there is sufficient quoting around the arguments.

First, thanks to @Hugues for providing this fix. Amazing that you could figure it out! I can’t even find the documentation for --set-config=/main/actions/opcode=

Second, for @NaokiSato102, the solution works for me. I believe that maybe you are not starting the video or your THETA is mounted as a file system?

Here is my complete test

unmount camera

If the camera is mounted, the commands may not work.

image

set to video mode

Using the API reference, we can see that video mode is hex 0x8002 or 32770 in base 10.

$ gphoto2 --set-config=5013=32770

start video

$ gphoto2 --set-config movie=1

stop video

$ gphoto2 --set-config=/main/actions/opcode=0x1018,0xFFFFFFFF

start video and stop after specified time

$ gphoto2 --set-config movie=1 --wait-event=2s --set-config movie=0 
Behavior with Audio Beep

There is a beep after each command and no errors on the console.

image

checking media

If you mount the camera again, you can see the media.

image

In my test, I have intentionally disabled internal stitching.

I suspect that your camera may be auto-mounting. Please check it and report back.

I have added this test to the USB API documentation on the Linux streaming documentation I am building. I’m providing attribution to Hugues by linking to his profile on this site along with his ID on this site.

(Missed stringing the replies together.)

I have firmly unmounted Theta and started recording and then tried it.

I would appreciate it if you all could tell me the results of your tests with information on your experimental environment.

Is it interference from other applications etc.? I do not know the reason.
I’m going to try it in the raspberry-pi environment as well.

The fact that the stop command works with --set-config suggests that it can work with the corresponding code in Python-gPhoto2. I can’t think of any code at the moment, but I think I can convert @mhenrie’s code to suit.

Also, was “gphoto2 --set-config movie=1 --wait-event=2s --set-config movie=0” able to exit after the shooting started successfully in @craig’s environment? This should have been inoperative in my perception, i.e. it was not possible to stop shooting.

RICOH THETA Z1 with firmware 1.50.1

craig@cube:~$ lsb_release -a
LSB Version:	core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal
craig@cube:~$ 

craig@cube:~$ cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Pentium(R) CPU G3258 @ 3.20GHz

craig@cube:~$ gphoto2 --version
gphoto2 2.5.23

This version of gphoto2 is using the following software versions and options:
gphoto2         2.5.23         gcc, popt(m), exif, cdk, aa, jpeg, readline
libgphoto2      2.5.25         standard camlibs (SKIPPING lumix), gcc, ltdl, EXIF
libgphoto2_port 0.12.0         iolibs: disk ptpip serial usb1 usbdiskdirect usbscsi, gcc, ltdl, EXIF, USB, serial without locking

It worked in my test. The correct video was saved to file. Note that the camera was in video mode at the start of the sequence.

Test 2 Using RICOH THETA V

Equipment

Host system is the same as described above.

Camera is

$ gphoto2 --summary
Camera summary:                                                                
Manufacturer: Ricoh Company, Ltd.
Model: RICOH THETA V
  Version: 3.40.1
  Serial Number: 00105377
Vendor Extension ID: 0x6 (1.10)

Test 2.1 - manually starting and stopping video

craig@cube:~$ gphoto2 --set-config movie=1
craig@cube:~$ gphoto2 --set-config=/main/actions/opcode=0x1018,0xFFFFFFFF
craig@cube:~$    

Result: successful


Test 2.2 - automatically stopping video

craig@cube:~$ gphoto2 --set-config movie=1 --wait-event=2s --set-config movie=0 

Result: successful

It’s interesting that there are different versions of gphoto2. It may be derived from that.

I CAN NOT get gphoto2 2.5.23 by apt install.
What should I do?

When I installed gPhoto2 using gPhoto2-updater after removing an existing apt-derived gPhoto2 with reference to this article, I was able to execute the commands which @craig presented and the configuration of gPhoto2 became the same.
It seems to be better to use gPhoto2-updater than to install it with apt.
But I wonder why gPhoto2-updater has not been updated. I wonder why we have to separate gPhoto2-updater and apt.

add 20/10/04

As usual, “gphoto2 --set-config-index shutterspeed=10” did not work properly, but the error message changed.

Previously.

*** Error (-110: 'I/O in progress') ***

Present.

*** Error ***              
Shutterspeed not found in configuration tree.
*** Error (-1: 'Unspecified error') ***

[quote=“NaokiSato102, post:39, topic:4521, full:true”]
I CAN NOT get gphoto2 2.5.23 by apt ins[/quote]