Forum Archive

Video preview inside ui.view [beta]

JonB

Got live video preview working using objc_utils. LiveCameraView lets you embed the camera's output in realtime (either front or back camera,set device=0 or 1) inside other ui.Views.

It should be possible to then get snapshots, or access to the raw images for realtime image processing /effects ( have not tried it yet). i plan on experimenting with the Accelerate framework next.

ywangd

Awesome work @JonB !

Can't wait to see some real-time image processing / face recognition with Pythonista!!
Is it possible to do the similar thing but with audio? I do remember there were some disucssion about accessing microphone. But not sure whether they are about live feeds?

JonB

there was code a while back with audio. i made a simple audio wave displaye, but that grabbed a chunk of audio at a time, as a wave. it worked, but choppily, since it had to record then write then read. with objc now, i think we can access audio samples in the fly.

interestingly, the capture device claims it supports facedetection, but i cant seem to find any documentation on how to use this feature, and faceRectange always returns 0's.

ywangd

@JonB said:

interestingly, the capture device claims it supports facedetection, but i cant seem to find any documentation on how to use this feature, and faceRectange always returns 0's.

The iOS camera does seem to have some builtin face detection functions as it tries to focus on faces when taking pictures. Not sure if this is an open API.

NoBetterName

This program only shows the portrait orientation, how can we switch it to landscape?

david

Hi, a doubt...
you can put (overlap) buttons and or lines on top or the camera view?
for example, draw a "transparent" grid...

JonB

you should be able to, since it is just a ui.View.

Phuket2

Really nice. Works great on my iPad Pro.

cvp

@JonB I don't understand how to take a snapshot of this ui.View
I've tried a button with

def snap_button_action(self,sender):
        with ui.ImageContext(self.width, self.height) as ctx:
            self.draw_snapshot()
            img = ctx.get_image()
            photos.save_image(

But I get a blank photo

JonB

it would require objc, since the underlying previewlayer is implemented as opengl.

Stackoverflow has some posts about capturing from a AVCaptureVideoPreviewLayer -- i have not digested it all, but mainly it seems like there is a delegate that you have to implement that gets the raw data, and can same that dirsctly to an image.

looking back in my archives, it looks like i once implemented most of a working solution (including face and maybe rectange detection), but it doesnt look quite finished. i will have to post what I've got

cvp

@JonB Thanks for your time and knowledge