diff --git a/modules/videoio/include/opencv2/videoio/cap_ios.h b/modules/videoio/include/opencv2/videoio/cap_ios.h index 9075fe1c80..13bf4b987c 100644 --- a/modules/videoio/include/opencv2/videoio/cap_ios.h +++ b/modules/videoio/include/opencv2/videoio/cap_ios.h @@ -133,7 +133,7 @@ } -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; @property (nonatomic, assign) BOOL grayscaleMode; @property (nonatomic, assign) BOOL recordVideo; @@ -167,7 +167,7 @@ AVCaptureStillImageOutput *stillImageOutput; } -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; - (void)takePicture; diff --git a/modules/videoio/src/cap_ios_photo_camera.mm b/modules/videoio/src/cap_ios_photo_camera.mm index 8cf19226b6..9b44156efc 100644 --- a/modules/videoio/src/cap_ios_photo_camera.mm +++ b/modules/videoio/src/cap_ios_photo_camera.mm @@ -36,6 +36,9 @@ @interface CvPhotoCamera () +{ + id _delegate; +} @property (nonatomic, strong) AVCaptureStillImageOutput* stillImageOutput; @@ -53,8 +56,14 @@ #pragma mark Public @synthesize stillImageOutput; -@synthesize delegate; +- (void)setDelegate:(id)newDelegate { + _delegate = newDelegate; +} + +- (id)delegate { + return _delegate; +} #pragma mark - Public interface @@ -106,9 +115,7 @@ cameraAvailable = YES; NSLog(@"CvPhotoCamera captured image"); - if (self.delegate) { - [self.delegate photoCamera:self capturedImage:newImage]; - } + [self.delegate photoCamera:self capturedImage:newImage]; [self.captureSession startRunning]; }); diff --git a/modules/videoio/src/cap_ios_video_camera.mm b/modules/videoio/src/cap_ios_video_camera.mm index c1a0b4d774..c3704a1f44 100644 --- a/modules/videoio/src/cap_ios_video_camera.mm +++ b/modules/videoio/src/cap_ios_video_camera.mm @@ -61,11 +61,12 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} @implementation CvVideoCamera +{ + id _delegate; +} - -@synthesize delegate; @synthesize grayscaleMode; @synthesize customPreviewLayer; @@ -78,7 +79,13 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} @synthesize recordPixelBufferAdaptor; @synthesize recordAssetWriter; +- (void)setDelegate:(id)newDelegate { + _delegate = newDelegate; +} +- (id)delegate { + return _delegate; +} #pragma mark - Constructors @@ -450,7 +457,8 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} { (void)captureOutput; (void)connection; - if (self.delegate) { + auto strongDelegate = self.delegate; + if (strongDelegate) { // convert from Core Media to Core Video CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); @@ -492,8 +500,8 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} CGImage* dstImage; - if ([self.delegate respondsToSelector:@selector(processImage:)]) { - [self.delegate processImage:image]; + if ([strongDelegate respondsToSelector:@selector(processImage:)]) { + [strongDelegate processImage:image]; } // check if matrix data pointer or dimensions were changed by the delegate