Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Add property to show when border is detected (updated example App) #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion SobrCameraView-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,17 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Software Brauerei AG";
TargetAttributes = {
9458EB621B30A48D0000DA1F = {
CreatedOnToolsVersion = 6.3.2;
DevelopmentTeam = M5QETZED9L;
LastSwiftMigration = 0800;
};
9458EB771B30A48D0000DA1F = {
CreatedOnToolsVersion = 6.3.2;
LastSwiftMigration = 0800;
TestTargetID = 9458EB621B30A48D0000DA1F;
};
};
Expand Down Expand Up @@ -289,8 +292,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -334,8 +339,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -354,6 +361,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -362,21 +370,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = M5QETZED9L;
INFOPLIST_FILE = "SobrCameraView-Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.sobr.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
9458EB841B30A48D0000DA1F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = M5QETZED9L;
INFOPLIST_FILE = "SobrCameraView-Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.sobr.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -396,6 +410,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.sobr.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SobrCameraView-Example.app/SobrCameraView-Example";
};
name = Debug;
Expand All @@ -412,6 +427,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.sobr.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SobrCameraView-Example.app/SobrCameraView-Example";
};
name = Release;
Expand Down
12 changes: 6 additions & 6 deletions SobrCameraView-Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
8 changes: 4 additions & 4 deletions SobrCameraView-Example/ImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class ImageViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.sourceImageView.contentMode = .ScaleAspectFit
self.sourceImageView.contentMode = .scaleAspectFit
}

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.sourceImageView.image = self.sourceImage
}


@IBAction func back(sender: UIButton) {
self.navigationController?.popViewControllerAnimated(true)
@IBAction func back(_ sender: UIButton) {
_ = self.navigationController?.popViewController(animated: true)
}
}
38 changes: 28 additions & 10 deletions SobrCameraView-Example/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,61 @@ class MainViewController: UIViewController {
//MARK: Outlets
@IBOutlet weak var cameraView: SobrCameraView!

private var _image: UIImage?
private var _feature: CIRectangleFeature?
fileprivate var _image: UIImage?
fileprivate var _feature: CIRectangleFeature?

override func viewDidLoad() {

super.viewDidLoad()
self.cameraView.setupCameraView()
self.cameraView.borderDetectionEnabled = true
self.cameraView.borderDetectionFrameColor = UIColor(red:0.2, green:0.6, blue:0.86, alpha:0.5)

Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(MainViewController.updateIfBorderIsDetected), userInfo: nil, repeats: true)
}

override func viewWillAppear(animated: Bool) {

func updateIfBorderIsDetected() {

if self.cameraView.isBorderDetected {

print("border detected")

} else {

print("nothing")

}
}


override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true
self.navigationController?.isNavigationBarHidden = true
self.cameraView.start()
}

override func viewWillDisappear(animated: Bool) {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.cameraView.stop()
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showImage" {
(segue.destinationViewController as! ImageViewController).sourceImage = self._image
(segue.destination as! ImageViewController).sourceImage = self._image
}
}

//MARK: Actions
@IBAction func captureImage(sender: AnyObject?) {
@IBAction func captureImage(_ sender: AnyObject?) {
self.cameraView.captureImage { (image, feature) -> Void in
self._image = image
self._feature = feature
self.performSegueWithIdentifier("showImage", sender: nil)
self.performSegue(withIdentifier: "showImage", sender: nil)
}
}

@IBAction func toggleTorch(sender: AnyObject?) {
@IBAction func toggleTorch(_ sender: AnyObject?) {
self.cameraView.torchEnabled = !self.cameraView.torchEnabled
}

Expand Down
4 changes: 2 additions & 2 deletions SobrCameraView-Example/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

extension UIImageView {
func contentScale() -> CGFloat {
return CGFloat(fminf(Float(CGRectGetWidth(self.bounds)/self.image!.size.width), Float(CGRectGetHeight(self.bounds)/self.image!.size.height)))
return CGFloat(fminf(Float(self.bounds.width/self.image!.size.width), Float(self.bounds.height/self.image!.size.height)))
}

func contentSize() -> CGSize {
Expand All @@ -21,6 +21,6 @@ extension UIImageView {

func contentFrame() -> CGRect {
let scaledImageSize = self.contentSize()
return CGRect(x: 0.5*(CGRectGetWidth(self.bounds) - scaledImageSize.width), y: 0.5 * (CGRectGetHeight(self.bounds) - scaledImageSize.height), width: scaledImageSize.width, height: scaledImageSize.height)
return CGRect(x: 0.5*(self.bounds.width - scaledImageSize.width), y: 0.5 * (self.bounds.height - scaledImageSize.height), width: scaledImageSize.width, height: scaledImageSize.height)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SobrCameraView_ExampleTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
self.measure() {
// Put the code you want to measure the time of here.
}
}
Expand Down
Loading