docs: Add Kotlin & Swift FP plugins examples (#1902)

* chore(docs): add Kotlin FP example

* chore(docs): add Swift FP plugin
This commit is contained in:
Mateusz Mędrek
2023-10-03 11:33:48 +02:00
committed by GitHub
parent b24b1c808f
commit 62e786ad04
14 changed files with 220 additions and 19 deletions

View File

@@ -18,7 +18,7 @@
@implementation ExampleFrameProcessorPlugin
- (id)callback:(Frame *)frame withArguments:(NSArray<id> *)arguments {
- (id)callback:(Frame *)frame withArguments:(NSDictionary *)arguments {
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
NSLog(@"ExamplePlugin: %zu x %zu Image. Logging %lu parameters:", CVPixelBufferGetWidth(imageBuffer), CVPixelBufferGetHeight(imageBuffer), (unsigned long)arguments.count);
@@ -28,11 +28,11 @@
return @{
@"example_str": @"Test",
@"example_bool": @true,
@"example_bool": @(YES),
@"example_double": @5.3,
@"example_array": @[
@"Hello",
@true,
@(YES),
@17.38
]
};

View File

@@ -0,0 +1,31 @@
//
// ExampleSwiftFrameProcessor.m
// VisionCameraExample
//
// Created by Mateusz Medrek on 02/10/2023.
//
#if __has_include(<VisionCamera/FrameProcessorPlugin.h>)
#import <Foundation/Foundation.h>
#import <VisionCamera/FrameProcessorPlugin.h>
#import <VisionCamera/FrameProcessorPluginRegistry.h>
#import <VisionCamera/Frame.h>
#import "VisionCameraExample-Swift.h"
// Example for a Swift Frame Processor plugin automatic registration
@interface ExampleSwiftFrameProcessorPlugin (FrameProcessorPluginLoader)
@end
@implementation ExampleSwiftFrameProcessorPlugin (FrameProcessorPluginLoader)
+ (void)load
{
[FrameProcessorPluginRegistry addFrameProcessorPlugin:@"example_kotlin_swift_plugin" withInitializer:^FrameProcessorPlugin * _Nonnull(NSDictionary * _Nullable options) {
return [[ExampleSwiftFrameProcessorPlugin alloc] init];
}];
}
@end
#endif

View File

@@ -0,0 +1,42 @@
//
// ExampleSwiftFrameProcessor.swift
// VisionCameraExample
//
// Created by Mateusz Medrek on 02/10/2023.
//
#if VISION_CAMERA_ENABLE_FRAME_PROCESSORS
import VisionCamera
// Example for a Swift Frame Processor plugin
@objc(ExampleSwiftFrameProcessorPlugin)
public class ExampleSwiftFrameProcessorPlugin: FrameProcessorPlugin {
public override func callback(_ frame: Frame, withArguments arguments: [AnyHashable: Any]?) -> Any? {
let imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer)
if let arguments, let imageBuffer {
let width = CVPixelBufferGetWidth(imageBuffer)
let height = CVPixelBufferGetHeight(imageBuffer)
let count = arguments.count
print(
"ExampleSwiftPlugin: \(width) x \(height) Image. Logging \(count) parameters:"
)
for key in arguments.keys {
let value = arguments[key]
let valueString = String(describing: value)
let valueClassString = String(describing: value.self)
print("ExampleSwiftPlugin: -> \(valueString) (\(valueClassString))")
}
}
return [
"example_str": "SwiftTest",
"example_bool": false,
"example_double": 6.7,
"example_array": ["Good bye", false, 21.37]
]
}
}
#endif