I'm new here and hope for a little help and would be very happy about that.
I write a small program in python, kivy and opencv.
The problem is that I would like to integrate my webcam with opencv and not via the existing camera function from kivy.
I have already found a similar problem here Integrate OpenCV webcam into a Kivy user interface but this does not solve my problem.
In my OpenCV code, also runs a code for facial recognition (https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py). So it is therefore important that the command imshow()
is issued. How can I integrate the webcam version of imshow()
from Opencv into kivy or into a kv file?
Unfortunately, I don't know if something like that might work. Can one of you help me or has a idea. Thank you very much for your help.
Python file:
import cv2
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class MainScreen(Screen):
pass
class Manager(ScreenManager):
pass
kv = Builder.load_file("file.kv")
class Main(App):
def build(self):
return kv
if __name__ == '__main__':
Main().run()
OpenCV - Code:
import cv2
cam = cv2.VideoCapture(0)
while(True):
ret, frame = cam.read()
# ...
# more code
# ...
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
My Kivy file (minimal):
MainScreen:
MainScreen:
<MainScreen>:
name: "Test"
FloatLayout:
Label:
text: "Webcam from OpenCV?"
pos_hint: {"x":0.0, "y":0.8}
size_hint: 1.0, 0.2
Button:
text: 'Click me!!'
pos_hint: {"x":0.0, "y":0.0}
size_hint: 1.0, 0.2
font_size: 50