Chdkptp.py getframes - General Discussion and Assistance - CHDK Forum supplierdeeply

Chdkptp.py getframes

  • 4 Replies
  • 1764 Views
*

Offline dan86

  • *
  • 13
Chdkptp.py getframes
« on: 10 / January / 2020, 16:25:57 »
Advertisements
message translated by google from French to English
Hello,
I wrote in python a photo booth program that works very well with the raspberry's camera. But the quality is not there.
I am trying to adapt it for a canon ixus 240 hs.
I installed chdkptp.py. The photo-taking part works well. By cons I can not see how to use get_frames to recover a ppm file and do the preview.
I am interested in any help on the subject

*

Offline reyalp

  • ******
  • 14121
Re: Chdkptp.py getframes
« Reply #1 on: 10 / January / 2020, 21:29:15 »
Bienvenue :)

One example is https://chdk.setepontos.com/index.php?topic=13948.0 (on github https://github.com/emanuelelaface/Canon-M10)

It uses chdkptp functions directly, not using chdkptp.py get_frames. The M10 is Digic 6, so the format would be different from your camera, but you should be able to use similar code.

From https://github.com/5up3rD4n1/chdkptp.py/blob/master/chdkptp/device.py
get_frames returns a generator, so I think you should be able to use something like
frames = camera.get_frames()
and then, every time you want a frame
frame_ppm = next(frames)

How to use frame_ppm to make a preview depends on how you are going your GUI.

You could also just take the code from self._lua.eval inside get_frames to get the RGB data, without the ppm header if you don't need it.
Don't forget what the H stands for.

*

Offline dan86

  • *
  • 13
Re: Chdkptp.py getframes
« Reply #2 on: 11 / January / 2020, 02:01:40 »
Translated By google
Hello
thank you for your reply
I would just like to recover the ppm file on my raspberry as we do with:
lvdumpimg -pipebm = oneproc -count = 70 -vp = file.ppm '
Can we do it from get_frames? and how ?
Thank you in advance for your help

*

Offline reyalp

  • ******
  • 14121
Re: Chdkptp.py getframes
« Reply #3 on: 12 / January / 2020, 21:32:40 »
lvdumpimg -pipebm = oneproc -count = 70 -vp = file.ppm '
Maybe google translate broke something, this command does not make sense to me.

Quote
Can we do it from get_frames? and how ?
Thank you in advance for your help

I think get_frames is buggy, maybe a python3 issue. I did not write chdkptp.py and do not maintain it, but maybe you can contact the authors.
Code: [Select]
>>> frames=cam.get_frames()
>>> frame_ppm=next(frames)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/chdkptp_py/lib/python3.5/site-packages/chdkptp/device.py", line 392, in get_frames
    """)(scaled)
  File "lupa/_lupa.pyx", line 559, in lupa._lupa._LuaObject.__call__
  File "lupa/_lupa.pyx", line 1306, in lupa._lupa.call_lua
  File "lupa/_lupa.pyx", line 1328, in lupa._lupa.execute_lua_call
  File "lupa/_lupa.pyx", line 1350, in lupa._lupa.unpack_lua_results
  File "lupa/_lupa.pyx", line 1117, in lupa._lupa.py_from_lua
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 291: invalid continuation byte
I think it tries to return the ppm as a string, but the string is not valid unicode, because it's image data.
I think lupa lets you set the encoding, but this option is not exposed in chdkptp.py.


You could use the lvdumpimg command from chdkptp.py. This worked for me:
Code: [Select]
$ python
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chdkptp
>>> cam=chdkptp.ChdkDevice(chdkptp.list_devices()[0])
>>> cam._lua.execute('''
... errutil=require'errutil'
... ustime=require'ustime'
... cli=require'cli'
... ''')
>>> cam._lua.execute('cli:execute("lvdumpimg -vp=${frame}.ppm -bm=${frame}.pam")')
Don't forget what the H stands for.


*

Offline dan86

  • *
  • 13
Re: Chdkptp.py getframes
« Reply #4 on: 15 / January / 2020, 01:16:19 »
translated by google
Hello
I was inspired by your following proposal to write my script :

$ python
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chdkptp
>>> cam=chdkptp.ChdkDevice(chdkptp.list_devices()[0])
>>> cam._lua.execute('''
... errutil=require'errutil'
... ustime=require'ustime'
... cli=require'cli'
... ''')
>>> cam._lua.execute('cli:execute("lvdumpimg -vp=${frame}.ppm -bm=${frame}.pam")')

I was able to recover the ppm file and set up a preview in my photo booth script
thanks a lot for your help

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal