Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'float' object cannot be interpreted as an integer when calling read_frame on a CameraAndroid #8752

Closed
ewen-lbh opened this issue Jun 10, 2024 · 0 comments · Fixed by #8754
Closed

Comments

@ewen-lbh
Copy link
Contributor

Software Versions

  • Python: 3.11
  • OS: Android 14
  • Kivy: 2.3.0
  • Kivy installation method: pip (through Poetry)

Describe the bug
Calling camera.read_frame() from on_tex's camera argument in a subclass of kivy.uix.camera.Camera throws with:

'float' object cannot be interpreted as an integer

Expected behavior
camera.read_frame() returns a numpy array to use with OpenCV

To Reproduce
A short, runnable example that reproduces the issue with latest kivy master.

Note: I did not try reproducing with master because building the wheel from master (3eadfd9) fails

# coding:utf-8
from android.permissions import Permission, request_permissions
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.camera import Camera

Builder.load_string("""
#:kivy 2.3.0
<RootLayout>
    orientation: 'vertical'
    size: root.width, root.height

    Cam:
        index: 0
        # resolution: self.camera_resolution
        allow_stretch: True
        play: True
""")

class Cam(Camera):
    def on_tex(self, camera):
        frame = camera.read_frame()
        return super().on_tex(camera)


class RootLayout(BoxLayout):
    pass


class MyApp(App):
    def build(self):
        return RootLayout()

if __name__ == "__main__":
    request_permissions([Permission.CAMERA])
    MyApp().run()

Code and Logs and screenshots

# coding:utf-8
from android.permissions import Permission, request_permissions
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.camera import Camera
from rich import print

Builder.load_string("""
#:kivy 2.3.0
<RootLayout>
    orientation: 'vertical'
    size: root.width, root.height

    Cam:
        # index: 0
        # resolution: self.camera_resolution
        # allow_stretch: True
        # play: True
""")

class Cam(Camera):
    def on_tex(self, camera):
        print(f"on_texture: {camera}")
        try:
            frame = camera.read_frame()
            print(f"frame @ {frame.shape}")
        except Exception as e:
            print(e)
            pass
        return super().on_tex(camera)


class RootLayout(BoxLayout):
    pass


class AudioseekApp(App):
    def build(self):
        return RootLayout()


if __name__ == "__main__":
    request_permissions([Permission.CAMERA])
    AudioseekApp().run()

Logcat:

06-10 17:10:03.910 20603 20730 I python  : 'float' object cannot be interpreted as an integer
06-10 17:10:03.941 20603 20730 I python  : on_texture: <kivy.core.camera.camera_android.CameraAndroid object at 
06-10 17:10:03.941 20603 20730 I python  : 0x76e27f3000>

Additional context

The stacktrace points to decode_frame, see

arr = np.fromstring(buf, 'uint8').reshape((h + h / 2, w))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant