Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Correct the format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xreki committed Dec 14, 2017
1 parent 60a2aaf commit 817730e
Show file tree
Hide file tree
Showing 30 changed files with 1,240 additions and 1,109 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
- id: detect-private-key
files: (?!.*tar.gz)^.*$
- id: end-of-file-fixer
files: \.md$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: trailing-whitespace
files: \.md$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
sha: v1.0.1
hooks:
- id: forbid-crlf
files: \.(md|c|cc|cxx|cpp|cu|h|hpp|hxx)$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: remove-crlf
files: \.(md|c|cc|cxx|cpp|cu|h|hpp|hxx)$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: forbid-tabs
files: \.(md|c|cc|cxx|cpp|cu|h|hpp|hxx)$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: remove-tabs
files: \.(md|c|cc|cxx|cpp|cu|h|hpp|hxx)$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- repo: local
hooks:
- id: clang-format-with-version-check
Expand Down
3 changes: 2 additions & 1 deletion Demo/iOS/AICamera/AICamera/AICamera-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
// Use this file to import your target's public headers that you would like to
// expose to Swift.
//

#import "ImageRecognizerPaddleWrapper.h"
Expand Down
1 change: 0 additions & 1 deletion Demo/iOS/AICamera/AICamera/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


}

14 changes: 7 additions & 7 deletions Demo/iOS/AICamera/AICamera/ImageRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ protocol ImageRecognizerDelegate {
}

class ImageRecognizer {

var imageRecognizer: ImageRecognizerPaddleWrapper?

init(model: SSDModel) {
imageRecognizer = ImageRecognizerPaddleWrapper(model: model.rawValue, withNormHeight: model.normDimension().0, withNormWidth: model.normDimension().1)
}

func inference(imageBuffer: UnsafeMutablePointer<UInt8>!, width: Int32, height: Int32, score: Float) -> NSMutableArray! {

return imageRecognizer?.inference(imageBuffer, withHeight: height, withWidth: width, withFilterScore: score)
}

func release() {
imageRecognizer?.destroy()
}
}

}
9 changes: 7 additions & 2 deletions Demo/iOS/AICamera/AICamera/ImageRecognizerPaddleWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

@interface ImageRecognizerPaddleWrapper : NSObject

- (instancetype)initWithModel:(NSString*)modelFileName withNormHeight:(int)height withNormWidth:(int)width;
- (NSMutableArray*)inference:(unsigned char *)pixels withHeight:(int)height withWidth:(int)width withFilterScore:(float) filterScore;
- (instancetype)initWithModel:(NSString *)modelFileName
withNormHeight:(int)height
withNormWidth:(int)width;
- (NSMutableArray *)inference:(unsigned char *)pixels
withHeight:(int)height
withWidth:(int)width
withFilterScore:(float)filterScore;
- (void)destroy;

@end
Expand Down
16 changes: 8 additions & 8 deletions Demo/iOS/AICamera/AICamera/ImageRecognizerPaddleWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ - (instancetype)initWithModel:(NSString*)modelFileName withNormHeight:(int)heigh
{
int channel = 3;
const std::vector<float> means({104, 117, 124});

NSBundle* bundle = [NSBundle mainBundle];
NSString* resourceDirectoryPath = [bundle bundlePath];
NSString* path = [[resourceDirectoryPath stringByAppendingString:@"/"] stringByAppendingString:modelFileName];

self->recognizer.init([path UTF8String], height, width, channel, means);

}
return self;
}
Expand All @@ -48,25 +48,25 @@ - (NSMutableArray*)inference:(unsigned char *)pixels withHeight:(int)height with
int channel = 4;
image::Config config(image::kBGR, image::CLOCKWISE_R90);
self->recognizer.infer(pixels, height, width, channel, config, result);

NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:result.height];
int w = result.width;

for (int i = 0; i < result.height; i++) {
float score = result.data[i * w + 2];
if (score < filterScore) 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];

[array addObject:ssdData];
}

return array;
}

Expand Down
14 changes: 7 additions & 7 deletions Demo/iOS/AICamera/AICamera/SSDData.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

@interface SSDData : NSObject

@property (nonatomic) NSString *label;
@property (nonatomic) float accuracy;
@property (nonatomic) float xmin;
@property (nonatomic) float ymin;
@property (nonatomic) float xmax;
@property (nonatomic) float ymax;
@property(nonatomic) NSString *label;
@property(nonatomic) float accuracy;
@property(nonatomic) float xmin;
@property(nonatomic) float ymin;
@property(nonatomic) float xmax;
@property(nonatomic) float ymax;

@end
@end
22 changes: 11 additions & 11 deletions Demo/iOS/AICamera/AICamera/SSDDrawLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ import UIKit

class SSDDrawLayer: CAShapeLayer {
var labelLayer = CATextLayer()

required override init() {
super.init()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func render(_ data: SSDData, model:SSDModel, isBackCamera:Bool) {

let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height

let x = CGFloat(isBackCamera ? data.xmin : 1 - data.xmax) * screenWidth
let y = CGFloat(data.ymin) * screenHeight
let width = CGFloat(data.xmax - data.xmin) * screenWidth
let height = CGFloat(data.ymax - data.ymin) * screenHeight

if (model == SSDModel.FaceMobileNet160 && data.label != "aeroplane") {
return;
}

//draw box
self.path = UIBezierPath(roundedRect: CGRect(x: x, y: y, width: width, height: height), cornerRadius: 10).cgPath
self.strokeColor = UIColor.cyan.cgColor
self.lineWidth = 4.0
self.fillColor = nil
self.lineJoin = kCALineJoinBevel

if (model == SSDModel.FaceMobileNet160) {
//do not draw label for face
return;
}

let text = String.init(format: "%@: %.02f", data.label, data.accuracy)
var displayString = NSAttributedString(string: text, attributes: [
NSStrokeColorAttributeName : UIColor.black,
NSForegroundColorAttributeName : UIColor.white,
NSStrokeWidthAttributeName : NSNumber(value: -6.0),
NSFontAttributeName : UIFont.systemFont(ofSize: 20, weight: 3)
])

//draw label

labelLayer.string = displayString
labelLayer.frame = CGRect.init(x: x + 4, y: y + height - 22, width: 1000, height: 30)
addSublayer(labelLayer)
Expand Down
3 changes: 1 addition & 2 deletions Demo/iOS/AICamera/AICamera/SSDModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum SSDModel : String {
case PascalMobileNet300 = "pascal_mobilenet_300_66.paddle"
case FaceMobileNet160 = "face_mobilenet_160_91.paddle"
case PascalVGG300 = "vgg_ssd_net.paddle"

func normDimension() -> (Int32, Int32)
{
switch self
Expand All @@ -26,4 +26,3 @@ enum SSDModel : String {
}
}
}

6 changes: 3 additions & 3 deletions Demo/iOS/AICamera/AICamera/SSDMultiboxLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import UIKit

class SSDMultiboxLayer: CALayer {

func displayBoxs(with ssdDataList: NSMutableArray, model: SSDModel, isBackCamera: Bool){
self.sublayers?.forEach({ (layer) in
layer.removeFromSuperlayer()
})

for ssdData in ssdDataList {
let boxLayer = SSDDrawLayer.init()
boxLayer.render(ssdData as! SSDData, model: model, isBackCamera: isBackCamera)

self.addSublayer(boxLayer)
}
}
Expand Down
Loading

0 comments on commit 817730e

Please sign in to comment.