Android front camera setParameters failed
See original GitHub issueVersions
- Python: 3.6.9
- OS: Ubuntu 18.04
- Kivy: 1.11.1
- Kivy installation method: pip
Description
Camera Example at kivy/examples/camera/main.py crashes after deploying and running on my Android device. The only change I make to the script is adding index=1 to Camera parameters in order to use the front camera. The logs have the following line: JavaException: JVM exception occurred: setParameters failed.
The way I see it, the issue is associated to the following line in camera_android.py: params.setFocusMode(‘continuous-picture’).
The front camera focus mode is ‘fixed’, therefore, it cannot be set to ‘continuous-picture’. It would be great to add getFocusMode method to the module and a condition to set the proper focus mode.
Code and Logs
'''
Camera Example
==============
This example demonstrates a simple use of the camera. It shows a window with
a buttoned labelled 'play' to turn the camera on and off. Note that
not finding a camera, perhaps because gstreamer is not installed, will
throw an exception during the kv language processing.
'''
# Uncomment these lines to see all the messages
# from kivy.logger import Logger
# import logging
# Logger.setLevel(logging.TRACE)
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time
Builder.load_string('''
<CameraClick>:
orientation: 'vertical'
Camera:
index: 1
id: camera
resolution: (640, 480)
play: False
ToggleButton:
text: 'Play'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: 'Capture'
size_hint_y: None
height: '48dp'
on_press: root.capture()
''')
class CameraClick(BoxLayout):
def capture(self):
'''
Function to capture the images and give them the names
according to their captured time and date.
'''
camera = self.ids['camera']
timestr = time.strftime("%Y%m%d_%H%M%S")
camera.export_to_png("IMG_{}.png".format(timestr))
print("Captured")
class TestCamera(App):
def build(self):
return CameraClick()
TestCamera().run()
01-24 11:26:26.105 32090 32425 I python : kivy.lang.builder.BuilderException: Parser: File "<inline>", line 7:
01-24 11:26:26.106 32090 32425 I python : ...
01-24 11:26:26.111 32090 32425 I python : 5: index: 1
01-24 11:26:26.112 32090 32425 I python : 6: id: camera
01-24 11:26:26.113 32090 32425 I python : >> 7: resolution: (640, 480)
01-24 11:26:26.113 32090 32425 I python : 8: play: False
01-24 11:26:26.114 32090 32425 I python : 9: ToggleButton:
01-24 11:26:26.114 32090 32425 I python : ...
01-24 11:26:26.115 32090 32425 I python : JavaException: JVM exception occurred: setParameters failed
01-24 11:26:26.115 32090 32425 I python : File "/mnt/Data/KIVY/test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/superhero/kivy/lang/builder.py", line 700, in _apply_rule
01-24 11:26:26.116 32090 32425 I python : File "kivy/weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
01-24 11:26:26.116 32090 32425 I python : File "kivy/properties.pyx", line 497, in kivy.properties.Property.__set__
01-24 11:26:26.117 32090 32425 I python : File "kivy/properties.pyx", line 839, in kivy.properties.ListProperty.set
01-24 11:26:26.118 32090 32425 I python : File "kivy/properties.pyx", line 544, in kivy.properties.Property.set
01-24 11:26:26.118 32090 32425 I python : File "kivy/properties.pyx", line 599, in kivy.properties.Property.dispatch
01-24 11:26:26.118 32090 32425 I python : File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
01-24 11:26:26.119 32090 32425 I python : File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
01-24 11:26:26.119 32090 32425 I python : File "/mnt/Data/KIVY/test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/superhero/kivy/uix/camera.py", line 103, in _on_index
01-24 11:26:26.120 32090 32425 I python : File "/mnt/Data/KIVY/test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/superhero/kivy/core/camera/camera_android.py", line 42, in __init__
01-24 11:26:26.121 32090 32425 I python : File "/mnt/Data/KIVY/test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/superhero/kivy/core/camera/__init__.py", line 70, in __init__
01-24 11:26:26.121 32090 32425 I python : File "/mnt/Data/KIVY/test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/superhero/kivy/core/camera/camera_android.py", line 54, in init_camera
01-24 11:26:26.122 32090 32425 I python : File "jnius/jnius_export_class.pxi", line 766, in jnius.jnius.JavaMethod.__call__
01-24 11:26:26.157 32090 32425 I python : File "jnius/jnius_export_class.pxi", line 860, in jnius.jnius.JavaMethod.call_method
01-24 11:26:26.157 32090 32425 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception
01-24 11:26:26.158 32090 32425 I python :
01-24 11:26:26.158 32090 32425 I python : Python for android ended.```
Issue Analytics
- State:
- Created 4 years ago
- Comments:11
Top Results From Across the Web
camera.setParameters failed in android - Stack Overflow
It is failing because not all devices support arbitrary preview sizes. Apparently some do but you can't rely on it. In your surfaceChanged...
Read more >Android front camera setParameters failed - - Bountysource
Camera Example at kivy/examples/camera/main.py crashes after deploying and running on my Android device. The only change I make to the script is ...
Read more >How to use RTR Android data capture using front camera?
Is it possible to ebable front camera, instead of back in data capture ... RuntimeException: setParameters failed at android.hardware.Camera ...
Read more >Camera.Parameters | Android Developers
To make camera parameters take effect, applications have to call Camera#setParameters(Camera.Parameters) . For example, after Camera.
Read more >core/java/android/hardware/Camera.java - Google Git
If the top side of a front-facing camera sensor is aligned with ... @throws RuntimeException if opening the camera fails (for example, if...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did not find anything better than modify directly camera_android.py The path to the file in my project directory is the following: ./.buildozer/android/platform/build-armeabi-v7a/build/other_builds/kivy/armeabi-v7a__ndk_target_21/kivy/kivy/core/camera/camera_android.py Simply replace params.setFocusMode(‘continuous-picture’) with params.setFocusMode(‘fixed’). Works like a charm!
Any fix? Have just run into this problem myself