Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Capturing Photos without the iOS screen
-
Anybody?
-
@omz I'm attempting to use your example to make a qr code reader. I'm hung up on how to make the dispatch queue work with the AVCaptureMetadataOutputObjectsDelegate. Any help would be greatly appreciated.
-
@wrenoud Have you seen this sample code I posted a while ago? https://forum.omz-software.com/topic/2779/barcode-qr-code-camera-scanner-demo-objc_util
-
@omz I hadn't! Exactly what I was looking for. I'm interested in trying to use QR codes for indoor navigation and I thought pythonista would be a great platform for demonstrating this. I'll come back and share when I have some results.
-
@omz This code is very helpful for me. From the apple developer website (https://developer.apple.com/documentation/avfoundation/avcapturestillimageoutput), the AVCaptureStillImageOutput class is going to be instead with AVCapturePhotoOutput class. Could you give a similar example with the new AVCapturePhotoOutput class? Thank you very much!
-
Is there any way to return the image directly rather than save to a file?
-
Could you give a similar example with the new AVCapturePhotoOutput class?
I made an example script. You can check the script via following URL. Explanation is written in Japanese, but you can get a code example.
http://www.hirax.net/diaryweb/2018/04/22.html#11012 -
@hirax i tried running your script but i am getting a syntax error on line 13.
-
@ihf remove the line break at begin of line 14,
Then idem at new line 19
Then idem at new line 27
Etc...The code seems to be splitted in long lines
-
# coding: utf-8 from objc_util import * import time AVCaptureSession = ObjCClass('AVCaptureSession') AVCaptureDevice = ObjCClass('AVCaptureDevice') AVCaptureDeviceInput = ObjCClass('AVCaptureDeviceInput') AVCapturePhotoOutput = ObjCClass('AVCapturePhotoOutput') def manualCapture(device, output, focusDistance, fileName): def captureOutput_didFinishProcessingPhotoSampleBuffer_previewPhotoSampleBuffer_resolvedSettings_bracketSettings_error_( _self, _cmd, _output, _photoBuffer, _previewBuffer, _resolveSettings, bracketSettings, _error ): photoBuffer = ObjCInstance(_photoBuffer) jpegPhotoData = ObjCClass('AVCapturePhotoOutput' ).JPEGPhotoDataRepresentationForJPEGSampleBuffer_previewPhotoSampleBuffer_( photoBuffer, _previewBuffer) jpegPhotoData.writeToFile_atomically_(fileName, True ) # delegate CameraManualPhotoCaptureDelegate = create_objc_class( 'CameraManualPhotoCaptureDelegate', methods=[ captureOutput_didFinishProcessingPhotoSampleBuffer_previewPhotoSampleBuffer_resolvedSettings_bracketSettings_error_ ], protocols=[ 'AVCapturePhotoCaptureDelegate' ]) device.lockForConfiguration_(None) device.setFocusModeLockedWithLensPosition_completionHandler_( focusDistance, None) device.unlockForConfiguration() time.sleep(1) delegate = CameraManualPhotoCaptureDelegate.new() settings = ObjCClass('AVCapturePhotoSettings' ).photoSettings() settings.AVCaptureFocusMode = 0 output.capturePhotoWithSettings_delegate_( settings, delegate ) time.sleep(1) delegate.release() @on_main_thread def main(): session = AVCaptureSession.alloc().init() device =AVCaptureDevice.defaultDeviceWithMediaType_('vide') _input =AVCaptureDeviceInput.deviceInputWithDevice_error_( device, None) if _input: session.addInput_(_input) else: return session.startRunning() output = AVCapturePhotoOutput.alloc().init() session.addOutput_(output) time.sleep(1) manualCapture(device, output, 0.0, 'sample.jpg') time.sleep(1) session.stopRunning() session.release() output.release() if __name__ == '__main__': main()
-
@cvp said:
The code seems to be splitted in long lines
Yes. In the example in the URL, we have aditttional lines.
I noticed that the above example doesn't work when manualCapture is called more than one times. In the cases, we will get only one image(saved) file.
-
To make it work in multiple-calls, we need to call "manualCapture" from threading. If we modify the above code in the way, then, it works even in multiple shots.
-
To make it work in multiple-calls, we need to call "manualCapture" from threading.
It's mistake. The result might be caused from inappropriate handling of delegate disposal. In instant way, removing delegate.release() will be solve the problem. But, fundamentally, we should request to remove a reference to the delegate.
-
This post is deleted!