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

modifying testing image protocol to return square and full-screen images #102

Merged
merged 12 commits into from
Dec 4, 2019

Conversation

jaimejiyepark
Copy link
Collaborator

[RFC]

  • set a imageFullScreen bool that can only be set by the TestingImageDataSource protocol implementer
  • captureOutputWork checks:
    • if testing image exists
      • if full screen image -> then get squared and full image.
      • if cropped -> send straight to ocr
    • if frames from camera
      • get squared and full image

@jaimejiyepark jaimejiyepark requested a review from kingst December 3, 2019 22:41
@jaimejiyepark
Copy link
Collaborator Author

Did not implement cropping the square in OCR to a credit card size yet since I want to get this portion done first.

@jaimejiyepark
Copy link
Collaborator Author

jaimejiyepark commented Dec 4, 2019

[RFC]

  • removed the objc attribute to use optionals
  • made an extension to scanBaseviewController that returns an optional CGImage array from the testingImageDataSource
  • added logic to captureOutputWork if testing images exist

Copy link
Collaborator

@kingst kingst left a comment

Choose a reason for hiding this comment

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

good start, left a few comments

@@ -18,7 +19,7 @@ import Vision
}


@objc public weak var testingImageDataSource: TestingImageDataSource?
public var testingImageDataSource: TestingImageDataSource?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to leave the weak in here to avoid a memory leak, but I'm not 100% sure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it wont let me put the weak in there :-/ . i get the errors 'weak' must not be applied to non-class-bound 'TestingImageDataSource'.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should understand this more clearly. the "safe" thing to do here is to add the @objc and weak back and be done with it, but if you want to make a change it's going to require some deeper analysis

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

im going to see if theres a workaround in the next commit to just add the @objc back. it's all because of that optional return

CardScan/Classes/ScanBaseViewController.swift Outdated Show resolved Hide resolved
CardScan/Classes/ScanBaseViewController.swift Outdated Show resolved Hide resolved
CardScan/Classes/ScanBaseViewController.swift Outdated Show resolved Hide resolved
CardScan/Classes/TestingImageExtension.swift Outdated Show resolved Hide resolved
CardScan/Classes/TestingImageExtension.swift Outdated Show resolved Hide resolved
Example/CardScan/ViewController.swift Outdated Show resolved Hide resolved
@jaimejiyepark
Copy link
Collaborator Author

I'll get on the end-end test once we approve the protocol design

Copy link
Collaborator

@kingst kingst left a comment

Choose a reason for hiding this comment

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

More comments, looking better

@@ -18,7 +19,7 @@ import Vision
}


@objc public weak var testingImageDataSource: TestingImageDataSource?
public var testingImageDataSource: TestingImageDataSource?
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should understand this more clearly. the "safe" thing to do here is to add the @objc and weak back and be done with it, but if you want to make a change it's going to require some deeper analysis

CardScan/Classes/ScanBaseViewController.swift Outdated Show resolved Hide resolved
Example/CardScan/ViewController.swift Outdated Show resolved Hide resolved
Copy link
Collaborator

@kingst kingst left a comment

Choose a reason for hiding this comment

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

More comments

Example/CardScan/ViewController.swift Outdated Show resolved Hide resolved
@jaimejiyepark
Copy link
Collaborator Author

AnyObject allows the protocol to only be conformed by class-types which allows us to put in that weak for the delegate.

https://developer.apple.com/documentation/swift/anyobject

Copy link
Collaborator

@kingst kingst left a comment

Choose a reason for hiding this comment

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

More comments, getting closer. My last hesitation is around having a protocol that inherits from something -- it seems hacky.


if #available(iOS 11.2, *) {
if self.scanQrCode {
self.blockingQrModel(pixelBuffer: pixelBuffer)
} else {
self.blockingOcrModel(squareCardImage: squareCardImage, fullCardImage: fullCardImage)
self.blockingOcrModel(squareCardImage: squareAndFullCardImage.0, fullCardImage: squareAndFullCardImage.1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

naming individual tuple elements here doesn't seem great people would need to know that .0 is square and .1 is full. For squareAndFullCardImage why not have variables directly, something like let (square, full) = self.testingImageDataSource...

@@ -521,7 +496,6 @@ import Vision
let rect = CGRect(x: cx - width / 2.0, y: cy - height / 2.0, width: width, height: height)

self.currentImageRect = rect

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remove whitespace changes from here and the few other places that they show up?

@jaimejiyepark
Copy link
Collaborator Author

I would argue that its actually not hacky.
https://docs.swift.org/swift-book/LanguageGuide/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID267
The first portion of the delegate section shows an example of a protocol inheriting AnyObject

Copy link
Collaborator

@kingst kingst left a comment

Choose a reason for hiding this comment

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

I stand corrected on protocols inheriting from AnyObject, looks good. #shipit

@jaimejiyepark jaimejiyepark merged commit f1815dc into master Dec 4, 2019
@jaimejiyepark jaimejiyepark deleted the squared_full_images branch December 4, 2019 23:35
@jaimejiyepark jaimejiyepark changed the title mod testing image protocol/ add squared image modifying testing image protocol to return square and full-screen images Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants