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

White screen on OpenCV3, but works on OpenCV2 #5404

Open
AndreMiras opened this issue Sep 25, 2017 · 10 comments
Open

White screen on OpenCV3, but works on OpenCV2 #5404

AndreMiras opened this issue Sep 25, 2017 · 10 comments

Comments

@AndreMiras
Copy link
Member

Versions

  • Python: v2.7.12
  • OS: Linux (Gentoo)
  • Kivy: 1.10.0
  • Kivy installation method: pip install kivy==1.10.0

Description

I want to use my camera in Kivy using the official example code from here:
https://github.com/kivy/kivy/blob/1.10.0/examples/camera/main.py
However I only get a white screen when using cv2.so from opencv-3.3.0|. If I compile opencv-2.4.13.3` it works.
It's interesting to note that in both cases the camera seems to get initialised (led turning on), but with opencv-2 the video shows, while the screen stays white with opencv-3.
I also tried with a more minimalist example below:

import kivy

from kivy.app import App
from kivy.uix.camera import Camera

class MainApp(App):
    def build(self):
        return Camera(play=True, resolution=(640, 480))

if __name__== "__main__":
    MainApp().run()

And I get the same result i.e. works with opencv-2.4.13.3 not with opencv-3.3.0.

I downloaded both version from https://github.com/opencv/opencv/releases.
And they were both compiled with default flags (simply cmake and then make -j4).
Also for both the pure OpenCV example below is working.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Display the resulting frame
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

So it really looks like a problem with its integration in Kivy.

@saeugetier
Copy link

I can confirm the problem

@yoelk
Copy link

yoelk commented Jan 26, 2018

I also have a white screen with opencv 3.
I debugged it and saw that incoming frames are not empty, but still they don't show well on screen

@yoelk
Copy link

yoelk commented Jan 26, 2018

Solved it. Look in the file .../lib/python3.6/site-packages/kivy/core/camera/camera_opencv.py
line 121:

        if self.fps <= 0:
            self.fps = 1 / 30.

When you get there in debug mode, you see that the fps value is actually 30 (and not 1/30).
This value is then used for the frame-update scheduling:

self._update_ev = Clock.schedule_interval(self._update, self.fps)

Changing this line to be:

self._update_ev = Clock.schedule_interval(self._update, 1/self.fps)

solves the problem. It's of course not a complete solution, and probably other places in the code should change as well.
Hope this works for you as well

@schoolsplay
Copy link
Contributor

schoolsplay commented Mar 23, 2018

None of the above 'solutions' work on Ubuntu 18.04 (Beta release) with python 2.7.14 and opencv 3.
Webcam is working with desktop apps like cheese.
We, braintrainerplus.nl, really need the webcam working and are prepared to put a bounty on this issue if anyone is interested.

@globophobe
Copy link

I wanted to preprocess the numpy array data returned by opencv, before displaying it. Unfortunately, kivy’s camera abstraction only offered texture binary data.

This gist was useful to access the camera directly:

https://gist.github.com/ExpandOcean/de261e66949009f44ad2

@schoolsplay
Copy link
Contributor

FYI: opencv 2.4.13 works with kivy 1.10 on Ubuntu 18.04.
(Not sure why my first attempt failed but after another compile it worked)

@proffalken
Copy link

Can confirm that @yoelk's "fix" works on Arch Linux using Python 3.6.5 and OpenCV 3.3.0 inside a Virtual Env.

@seanodonnell
Copy link
Contributor

This looks like the same issue as #5146

@CurtlyCritchlow
Copy link

CurtlyCritchlow commented Jan 18, 2019

@yoelk my line 121 is

if self.fps <= 0:
           self.fps = 1 / 30

And i'm getting the white screen. I'm not getting to download opencv2 either using pip or conda in my attempt to downgrade

@schoolsplay
Copy link
Contributor

I can confirm that the webcam, tested with build-in bison and usb logitech, are now working on stable kivy 1.10.1 with the fix from @yoelk .
System: Ubuntu 18.04/Mint 19, openvc 3.2.0 and kivy 1.10.1 from ppa:kivy-team/kivy.

I also have to comment out all the providers except the opencv in kivy/core/camera/init.py to force the use of opencv as the rest just fails and give all kinds of wierd errors.

@CurtlyCritchlow the fix is in line 152: self._update_ev = Clock.schedule_interval(self._update, 1/self.fps)

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

No branches or pull requests

8 participants