Kivy Camera Class with Grayscale Filter

211 views
Skip to first unread message

ShibaInu

unread,
Nov 27, 2021, 12:46:20 PM11/27/21
to Kivy users support
Hello,

is it possible to use the Kivy camera class and apply a filter on it with opencv? 

like this:



KVString:"""
    
GrayscaleCam:
   
"""

class GrayscaleCam(Camera):

gray = cv.cvtColor( KIVYCAMFRAME , cv.COLOR_BGR2GRAY)

Elliot Garbus

unread,
Nov 27, 2021, 1:01:21 PM11/27/21
to kivy-...@googlegroups.com

Here is an example that used Image to display a filtered OpenCV stream on an image.

 

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.graphics.texture import Texture

import cv2 as cv


class CamApp(App):

   
def build(self):
       
self.img1 = Image()
        layout = BoxLayout()
        layout.add_widget(
self.img1)
       
self.capture = cv.VideoCapture(0)
        Clock.schedule_interval(
self.update, 1.0 / 33.0)
       
return layout


   
def update(self, dt):
       
# display image from cam in opencv window
       
ret, frame = self.capture.read()
        gray= cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
       
# convert it to texture
       
adaptive_thresh = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 11, 3)

        buf = cv.flip(adaptive_thresh,
0).tobytes()
        texture1 = Texture.create(
size=(adaptive_thresh.shape[1], adaptive_thresh.shape[0]), colorfmt='luminance')
        texture1.blit_buffer(buf,
colorfmt='luminance', bufferfmt='ubyte')#replacing texture
        # display image from the texture
       
self.img1.texture = texture1


if __name__ == '__main__':
    CamApp().run()
    cv.destroyAllWindows()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d134f2a6-2675-4c8f-888a-4ebbc22867e3n%40googlegroups.com.

 

ShibaInu

unread,
Nov 27, 2021, 1:48:44 PM11/27/21
to Kivy users support
can you get the camera input without cv.VideoCapture(0)?

 My app cant access the Android cam with this metod. On PC everything is fine, but when build with buildozer => ret is false.


 I gave permission and evrything...  I dont think you can build an App with cv.VideoCapture

Elliot Garbus

unread,
Nov 27, 2021, 5:00:11 PM11/27/21
to kivy-...@googlegroups.com

I have not done any Android development.  You may find this helpful:  https://github.com/Android-for-Python/Android-for-Python-Users#camera

Robert

unread,
Nov 27, 2021, 7:40:59 PM11/27/21
to Kivy users support
OpenCV camera on Android after NDK17 is either difficult or impossible, not certain which, I have heard rumors...
Don't even think about backpedaling the NDK version.
Starting from scratch Xcamera is generally the best chance.

I've been working on a opencv image processing example that uses the Android's CameraX, it works great.
I'm absolutely not suggesting trying CameraX, it is major work to figure out how to make it play with Kivy.
Hope to package that up and share by the end of the year, but there is no schedule as it became part of a larger project....

ShibaInu

unread,
Nov 27, 2021, 9:26:14 PM11/27/21
to kivy-...@googlegroups.com
Thats very intresting. Thank you all for your suggestions. 


@Robert could you show one example of CameraX with opencv? 


Ill look forward to get my App work with your guys ideas

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/_1EP1z-Oe_Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e39a6429-72fd-4eaf-98ec-8aac3fb47861n%40googlegroups.com.

Robert

unread,
Nov 27, 2021, 9:54:58 PM11/27/21
to Kivy users support
As I said I'm not ready to share at this time.

ShibaInu

unread,
Nov 28, 2021, 7:29:37 AM11/28/21
to Kivy users support
Okay, still thank you.
Reply all
Reply to author
Forward
0 new messages