This repository was archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Init Commit for iOS AICamera Demo #26
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
19b4423
Init Commit for iOS AICamera Demo
nickyfantasy 056bf8b
fall back to swift 3 and finish objective C wrapper
nickyfantasy d0dd12b
Integrate with latest C++ code with resize and pass in byte array
nickyfantasy ba62f76
successfully get results from infer() and draw bounding box
nickyfantasy 6bd3279
Integrate with rotate logic, finalized and clean up code
nickyfantasy 9c5ee0e
Add front camera and new model, add settings for different models, ac…
nickyfantasy 3bdcfd8
Fix issue where default is front camera
nickyfantasy f931ce9
fix iphone X layout issue
nickyfantasy 73402fa
format settings accuracy label
nickyfantasy bcd36e1
change app name to PDCamera
nickyfantasy da6123e
Add README, remove 2 models and update settings, rename to PDCamera
nickyfantasy f8c3400
clean up code, add image_utils.cpp, add screenshot and QR code, updat…
nickyfantasy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Demo/iOS/AICamera/AICamera.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// | ||
|
||
#import "ImageRecognizerPaddleWrapper.h" | ||
#import "SSDData.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// AppDelegate.swift | ||
// SSDDemo | ||
// | ||
// Created by Nicky Chan on 11/6/17. | ||
// Copyright © 2017 PaddlePaddle. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | ||
// Override point for customization after application launch. | ||
UIApplication.shared.isIdleTimerDisabled = true | ||
return true | ||
} | ||
|
||
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 invalidate graphics rendering callbacks. Games should use this method to pause the game. | ||
} | ||
|
||
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) { | ||
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
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) { | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
|
||
|
||
} | ||
|
68 changes: 68 additions & 0 deletions
68
Demo/iOS/AICamera/AICamera/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "29x29", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "40x40", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "76x76", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "76x76", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Demo/iOS/AICamera/AICamera/Base.lproj/LaunchScreen.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/> | ||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="tne-QT-ifu"> | ||
<objects> | ||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> | ||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> | ||
</objects> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// ImageRecognizer.swift | ||
// SSDDemo | ||
// | ||
// Created by Nicky Chan on 11/7/17. | ||
// Copyright © 2017 PaddlePaddle. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ImageRecognizerDelegate { | ||
func imageRecognizedSuccess(_ result: SSDData) | ||
func imageRecognizedError() | ||
} | ||
|
||
class ImageRecognizer { | ||
|
||
var imageRecognizer: ImageRecognizerPaddleWrapper? | ||
|
||
init() { | ||
imageRecognizer = ImageRecognizerPaddleWrapper() | ||
} | ||
|
||
func inference(imageBuffer: UnsafeMutablePointer<UInt8>!, width: Int32, height: Int32) -> NSMutableArray! { | ||
|
||
return imageRecognizer?.inference(imageBuffer, withHeight: height, withWidth: width) | ||
} | ||
|
||
func release() { | ||
imageRecognizer?.destroy() | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ImageRecognizerPaddleWrapper.h | ||
// AICamera | ||
// | ||
// Created by Nicky Chan on 11/9/17. | ||
// Copyright © 2017 PaddlePaddle. All rights reserved. | ||
// | ||
|
||
#ifndef ImageRecognizerPaddleWrapper_h | ||
#define ImageRecognizerPaddleWrapper_h | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface ImageRecognizerPaddleWrapper : NSObject | ||
|
||
- (NSMutableArray*)inference:(unsigned char *)pixels withHeight:(int)height withWidth:(int)width; | ||
- (void)destroy; | ||
|
||
@end | ||
|
||
#endif /* ImageRecognizerPaddleWrapper_h */ |
85 changes: 85 additions & 0 deletions
85
Demo/iOS/AICamera/AICamera/ImageRecognizerPaddleWrapper.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// ImageRecognizerPaddleWrapper.m | ||
// SSDDemo | ||
// | ||
// Created by Nicky Chan on 11/7/17. | ||
// Copyright © 2017 PaddlePaddle. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "ImageRecognizerPaddleWrapper.h" | ||
#include "paddle_image_recognizer.h" | ||
#include "SSDData.h" | ||
|
||
@interface ImageRecognizerPaddleWrapper () { | ||
ImageRecognizer recognizer; | ||
} | ||
@end | ||
|
||
@implementation ImageRecognizerPaddleWrapper | ||
|
||
static NSString * kLabels [21] = { | ||
@"background", @"aeroplane", @"bicycle", @"background", @"boat", | ||
@"bottle", @"bus", @"car", @"cat", @"chair", | ||
@"cow", @"diningtable", @"dog", @"horse", @"motorbike", | ||
@"person", @"pottedplant", @"sheep", @"sofa", @"train", | ||
@"tvmonitor" | ||
}; | ||
|
||
static float kFilterScore = 0.3; | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) | ||
{ | ||
int normedHeight = 300; | ||
int normedWidth = 300; | ||
int channel = 3; | ||
const std::vector<float> means({104, 117, 124}); | ||
|
||
NSBundle* bundle = [NSBundle mainBundle]; | ||
NSString* resourceDirectoryPath = [bundle bundlePath]; | ||
NSString* path = [resourceDirectoryPath stringByAppendingString: @"/vgg_ssd_net.paddle"]; | ||
|
||
self->recognizer.init([path UTF8String], normedHeight, normedWidth, channel, means); | ||
|
||
} | ||
return self; | ||
} | ||
|
||
- (NSMutableArray*)inference:(unsigned char *)pixels withHeight:(int)height withWidth:(int)width { | ||
ImageRecognizer::Result result; | ||
int channel = 4; | ||
self->recognizer.infer(pixels, height, width, channel, result); | ||
|
||
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:result.height]; | ||
int w = result.width; | ||
|
||
NSLog(@"result height = %d", result.height); | ||
|
||
for (int i = 0; i < result.height; i++) { | ||
float score = result.data[i * w + 2]; | ||
if (score < kFilterScore) continue; | ||
|
||
SSDData *ssdData = [[SSDData alloc] init]; | ||
ssdData.label = kLabels[(int) result.data[i * w + 1]]; | ||
ssdData.accuracy = score; | ||
ssdData.xmin = result.data[i * w + 3]; | ||
ssdData.ymin = result.data[i * w + 4]; | ||
ssdData.xmax = result.data[i * w + 5]; | ||
ssdData.ymax = result.data[i * w + 6]; | ||
|
||
// NSLog(@"label = %@, acc = %f, xmin = %f, xmax = %f, ymin = %f, ymax = %f", ssdData.label, ssdData.accuracy, ssdData.xmin, ssdData.xmax, ssdData.ymin, ssdData.ymax); | ||
|
||
[array addObject:ssdData]; | ||
} | ||
|
||
return array; | ||
} | ||
|
||
- (void)destroy { | ||
self->recognizer.release(); | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>AICamera</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>NSCameraUsageDescription</key> | ||
<string>Requires camera access</string> | ||
<key>UILaunchStoryboardName</key> | ||
<string>LaunchScreen</string> | ||
<key>UIMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UIRequiresFullScreen</key> | ||
<true/> | ||
<key>UIStatusBarHidden</key> | ||
<true/> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these blank lines.