@@ -10,51 +10,51 @@ import UIKit
1010
1111class SSDDrawLayer : CAShapeLayer {
1212 var labelLayer = CATextLayer ( )
13-
13+
1414 required override init ( ) {
1515 super. init ( )
1616 }
17-
17+
1818 required init ? ( coder aDecoder: NSCoder ) {
1919 fatalError ( " init(coder:) has not been implemented " )
2020 }
21-
21+
2222 func render( _ data: SSDData , model: SSDModel , isBackCamera: Bool ) {
23-
23+
2424 let screenWidth = UIScreen . main. bounds. size. width
2525 let screenHeight = UIScreen . main. bounds. size. height
26-
26+
2727 let x = CGFloat ( isBackCamera ? data. xmin : 1 - data. xmax) * screenWidth
2828 let y = CGFloat ( data. ymin) * screenHeight
2929 let width = CGFloat ( data. xmax - data. xmin) * screenWidth
3030 let height = CGFloat ( data. ymax - data. ymin) * screenHeight
31-
31+
3232 if ( model == SSDModel . FaceMobileNet160 && data. label != " aeroplane " ) {
3333 return ;
3434 }
35-
35+
3636 //draw box
3737 self . path = UIBezierPath ( roundedRect: CGRect ( x: x, y: y, width: width, height: height) , cornerRadius: 10 ) . cgPath
3838 self . strokeColor = UIColor . cyan. cgColor
3939 self . lineWidth = 4.0
4040 self . fillColor = nil
4141 self . lineJoin = kCALineJoinBevel
42-
42+
4343 if ( model == SSDModel . FaceMobileNet160) {
4444 //do not draw label for face
4545 return ;
4646 }
47-
47+
4848 let text = String . init ( format: " %@: %.02f " , data. label, data. accuracy)
4949 var displayString = NSAttributedString ( string: text, attributes: [
5050 NSStrokeColorAttributeName : UIColor . black,
5151 NSForegroundColorAttributeName : UIColor . white,
5252 NSStrokeWidthAttributeName : NSNumber ( value: - 6.0 ) ,
5353 NSFontAttributeName : UIFont . systemFont ( ofSize: 20 , weight: 3 )
5454 ] )
55-
55+
5656 //draw label
57-
57+
5858 labelLayer. string = displayString
5959 labelLayer. frame = CGRect . init ( x: x + 4 , y: y + height - 22 , width: 1000 , height: 30 )
6060 addSublayer ( labelLayer)
0 commit comments