image processing - swift avfoundation AVCapturePhotoCaptureDelegate capture method -


hello relatively new swift , avfoundation framework. trying implement custom toy camera app uses image processing. problem trying process each frame or each x frames automatically using image processing algorithm apply layer preview, , allow user capture preview image plus using ibaction ui button outputs image screen. image processing step capture lower res images not outputted screen, while ibaction capture should capture standard jpeg , output screen.

my question best way implement this?

i have noticed logic go avcapturephotocapturedelegate method capture(_ captureoutput: avcapturephotooutput, ...) there 2 different avcapturephotooutput() objects calling capturephoto(with: photosettings, delegate: self) calls capture(_ captureoutput: avcapturephotooutput, ...), understand. check in capture(_ captureoutput: avcapturephotooutput, ...) method captureoutput object sent capturephoto(with: photosettings, delegate: self) method called different avcapturephotooutput() objects?

where full method signature of capture(_ captureoutput: avcapturephotooutput, ...)

capture(_ captureoutput: avcapturephotooutput,                  didfinishprocessingphotosamplebuffer photosamplebuffer: cmsamplebuffer?,previewphotosamplebuffer: cmsamplebuffer?,                  resolvedsettings: avcaptureresolvedphotosettings,                  bracketsettings: avcapturebracketedstillimagesettings?,                  error: error?) 

or these 2 different capture functions done on 2 different threads?

to further elaborate, have 2 working camera apps 2 different functionality. 1 image processing , layer implementation , preview capture , output ui view. respective avcapturephotocapturedelegate capture methods follows:

image processing camera:

  public func capture(_ captureoutput: avcapturephotooutput,                       didfinishprocessingphotosamplebuffer photosamplebuffer: cmsamplebuffer?,                       previewphotosamplebuffer: cmsamplebuffer?,                       resolvedsettings: avcaptureresolvedphotosettings,                       bracketsettings: avcapturebracketedstillimagesettings?,                       error: error?) {      var imagetexture: mtltexture?     var previewimage: uiimage?     if error == nil {       imagetexture = converttomtltexture(samplebuffer: photosamplebuffer)       previewimage = converttouiimage(samplebuffer: previewphotosamplebuffer)     }     delegate?.videocapture(self, didcapturephototexture: imagetexture, previewimage: previewimage)   } 

capture image ui camera:

func capture(_ captureoutput: avcapturephotooutput,              didfinishprocessingphotosamplebuffer photosamplebuffer: cmsamplebuffer?,previewphotosamplebuffer: cmsamplebuffer?,              resolvedsettings: avcaptureresolvedphotosettings,              bracketsettings: avcapturebracketedstillimagesettings?,              error: error?) {      if let error = error {         print("error capturing photo: \(error)")     } else {         if let samplebuffer = photosamplebuffer,            let previewbuffer = previewphotosamplebuffer,         let dataimage = avcapturephotooutput.jpegphotodatarepresentation(forjpegsamplebuffer: samplebuffer, previewphotosamplebuffer: previewbuffer) {              if let image = uiimage(data: dataimage) {                 self.capturedimage.image = image             }         }     }  } 

where capturedimage @iboutlet weak var capturedimage: uiimageview! , convert methods functions within custom class. how go getting functionality of both of capture(...) methods 1 app?

i think apple's document avcapturephotooutput clear. should take look.

i don't know 2 different capture functions done on 2 different threads or not. since avfoundation kit not open source know.

i don't think matters.

as apple's document, register delegate capturephoto(with:delegate:) , , picture callback apple implemented default photooutput(_:didfinishprocessingphoto:error:)

by way , method photooutput(_:didfinishprocessingphoto:previewphoto:resolvedsettings:bracketsettings:error:) deprecated. check this page


Comments