0

I am building an App which got several video filters. But the App is not working on Android cause => capture = cv.VideoCapture(0) doesnt get access to the android camera.

The Code below shows how i edit the Video footage of the App at the moment. On PC it works perfect. But after building it, it shows no video footage on android

Buidlozer Spec got permission btw..


capture = cv.VideoCapture(0)



class BinaryCam(Image):


    def on_kv_post(self, base_widget):
        #self.capture = cv.VideoCapture(0)
        # cv.namedWindow("CV2 Image")
        Clock.schedule_interval(self.update, 1.0 / 33.0)

    def update(self, dt):
        # display image from cam in opencv window
        ret, frame = capture.read()

        if ret==True:

            # cv.imshow("CV2 Image", frame)
            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)

            buf1 = cv.flip(adaptive_thresh, 0)
            buf = buf1.tobytes()
            texture1 = Texture.create(size=(adaptive_thresh.shape[1], adaptive_thresh.shape[0]),
                                      colorfmt='luminance')  # in grayscale gibts kein bgr
            # if working on RASPBERRY PI, use colorfmt='rgba' here instead, but stick with "bgr" in blit_buffer.
            texture1.blit_buffer(buf, colorfmt='luminance', bufferfmt='ubyte')  # replacing texture
            # display image from the texture
            self.texture = texture1


Or maybe is there a way to get the Camera Frames from the Kivy Camera and edit them with OpenCV.

But i really would prefer this method i showed here with OpenCV.

Thank you

ShibaInu
  • 41
  • 9
  • this is python code no android. – FreddicMatters Nov 26 '21 at 15:45
  • @FreddicMatters Yeah, i later convert it with buildozer. On my WindowsLinuxSubsystem. I work with Kivy,KivyMD,Python and Buildozer – ShibaInu Nov 26 '21 at 15:54
  • Not sure if this is the problem, but you probably need to also use [runtime permissions](https://python-for-android.readthedocs.io/en/latest/apis/#runtime-permissions). – John Anderson Nov 26 '21 at 16:16
  • @JohnAnderson Thank you for the suggestion. Ill try it out after building my current apk. Ill post my result here – ShibaInu Nov 26 '21 at 16:19
  • @JohnAnderson Okay, i implemented it but the cam is still not showing up – ShibaInu Nov 26 '21 at 20:46
  • I found this post https://stackoverflow.com/questions/69157558/cannot-open-camera-using-cv2-videocapture0-in-android-phones from @Jananda. But its still open I guess. I got the same problem – ShibaInu Nov 26 '21 at 21:27
  • So this helped me to make opencv, python and android work together => https://github.com/4ndr3aR/kivy-opencv-demo – ShibaInu Nov 29 '21 at 15:31

0 Answers0