Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved pre-processing step to Core ML class #25

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lobe_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
9B7B03DE2475DBF300D34020 = {
isa = PBXGroup;
children = (
B5B2D938260A4D5B00BABFAB /* LobeModel.mlmodel */,
9B7B03E92475DBF300D34020 /* Lobe_iOS */,
B5B2D938260A4D5B00BABFAB /* LobeModel.mlmodel */,
B513D84325809D62009D91E2 /* LobeTests */,
9B7B03E82475DBF300D34020 /* Products */,
B5A9B5252557373E00FD595B /* Frameworks */,
Expand Down
14 changes: 1 addition & 13 deletions Lobe_iOS/Models/CaptureSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,7 @@ extension UIImage {
var isLandscape: Bool { size.width > size.height }
var breadth: CGFloat { min(size.width, size.height) }
var breadthSize: CGSize { .init(width: breadth, height: breadth) }

func squared(isOpaque: Bool = false) -> UIImage? {
guard let cgImage = cgImage?
.cropping(to: .init(origin: .init(x: isLandscape ? ((size.width-size.height)/2).rounded(.down) : 0,
y: isPortrait ? ((size.height-size.width)/2).rounded(.down) : 0),
size: breadthSize)) else { return nil }
let format = imageRendererFormat
format.opaque = isOpaque
return UIGraphicsImageRenderer(size: breadthSize, format: format).image { _ in
UIImage(cgImage: cgImage, scale: 1, orientation: imageOrientation)
.draw(in: .init(origin: .zero, size: breadthSize))
}
}

public convenience init?(pixelBuffer: CVPixelBuffer) {
var cgImage: CGImage?
VTCreateCGImageFromCVPixelBuffer(pixelBuffer, options: nil, imageOut: &cgImage)
Expand Down
5 changes: 5 additions & 0 deletions Lobe_iOS/Models/PredictionLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class PredictionLayer: NSObject {
}
onComplete(request)
})

/// Set center cropping for the expected image size.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbeissinger comment code here for your review.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep looks good

/// NOTE: Although center cropping is currently expected with Lobe's model version,
/// please be mindful of future changes which may affect the expected preprocessing steps.
request.imageCropAndScaleOption = .centerCrop
return request
}
}
6 changes: 1 addition & 5 deletions Lobe_iOS/PlayViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ class PlayViewModel: ObservableObject {
.compactMap { $0 } // remove non-nill values
.receive(on: DispatchQueue.global(qos: .userInitiated))
.sink(receiveValue: { [weak self] image in
guard let squaredImage = image.squared() else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That little bugger 😛

print("Could not create squared image in PlayViewModel.")
return
}
self?.imagePredicter.getPrediction(forImage: squaredImage)
self?.imagePredicter.getPrediction(forImage: image)
})
.store(in: &disposables)

Expand Down