@@ -33,7 +33,7 @@ class OpenPosePoseEstimator: PoseEstimator {
3333 inputWidth: Input . width,
3434 inputHeight: Input . height,
3535 isGrayScale: Input . isGrayScale,
36- isNormalized : Input . isNormalized
36+ normalization : Input . normalization
3737 )
3838 let imageInterpreter = TFLiteImageInterpreter ( options: options)
3939 return imageInterpreter
@@ -88,7 +88,7 @@ private extension OpenPosePoseEstimator {
8888 static let width = 432
8989 static let height = 368
9090 static let isGrayScale = false
91- static let isNormalized = false
91+ static let normalization = TFLiteImageInterpreter . NormalizationOptions . none
9292 }
9393 struct Output {
9494 struct ConfidenceMap { // similar to Heatmap
@@ -233,18 +233,18 @@ private extension PoseEstimationOutput {
233233 let human = parseSinglePerson ( outputs,
234234 partIndex: postprocessOptions. bodyPart,
235235 partThreshold: postprocessOptions. partThreshold)
236- humans = [ human]
236+ humans = [ . human2d ( human: human ) ]
237237 case . multiPerson( let pairThreshold, let nmsFilterSize, let maxHumanNumber) :
238238 humans = parseMultiHuman ( outputs,
239239 partIndex: postprocessOptions. bodyPart,
240240 partThreshold: postprocessOptions. partThreshold,
241241 pairThreshold: pairThreshold,
242242 nmsFilterSize: nmsFilterSize,
243- maxHumanNumber: maxHumanNumber)
243+ maxHumanNumber: maxHumanNumber) . map { . human2d ( human : $0 ) }
244244 }
245245 }
246246
247- func parseSinglePerson( _ outputs: [ TFLiteFlatArray < Float32 > ] , partIndex: Int ? , partThreshold: Float ? ) -> Human {
247+ func parseSinglePerson( _ outputs: [ TFLiteFlatArray < Float32 > ] , partIndex: Int ? , partThreshold: Float ? ) -> Human2D {
248248 // openpose_ildoonet.tflite only use the first output
249249 let output = outputs [ 0 ]
250250
@@ -263,28 +263,28 @@ private extension PoseEstimationOutput {
263263 return ( point: CGPoint ( x: x, y: y) , score: score)
264264 }
265265
266- let keypoints : [ Keypoint ? ] = keypointInfos
267- . map { keypointInfo -> Keypoint ? in Keypoint ( position: keypointInfo. point, score: keypointInfo. score) }
268- . map { keypointInfo -> Keypoint ? in
266+ let keypoints : [ Keypoint2D ? ] = keypointInfos
267+ . map { keypointInfo -> Keypoint2D ? in Keypoint2D ( position: keypointInfo. point, score: keypointInfo. score) }
268+ . map { keypointInfo -> Keypoint2D ? in
269269 guard let score = keypointInfo? . score, let partThreshold = partThreshold else { return keypointInfo }
270270 return ( score > partThreshold) ? keypointInfo : nil
271271 }
272272
273273 // lines
274- var keypointWithBodyPart : [ OpenPosePoseEstimator . Output . BodyPart : Keypoint ] = [ : ]
274+ var keypointWithBodyPart : [ OpenPosePoseEstimator . Output . BodyPart : Keypoint2D ] = [ : ]
275275 OpenPosePoseEstimator . Output. BodyPart. allCases. enumerated ( ) . forEach { ( index, bodyPart) in
276276 keypointWithBodyPart [ bodyPart] = keypoints [ index]
277277 }
278- let lines : [ Human . Line ] = OpenPosePoseEstimator . Output. BodyPart. lines. compactMap { line in
278+ let lines : [ Human2D . Line2D ] = OpenPosePoseEstimator . Output. BodyPart. lines. compactMap { line in
279279 guard let fromKeypoint = keypointWithBodyPart [ line. from] ,
280280 let toKeypoint = keypointWithBodyPart [ line. to] else { return nil }
281281 return ( from: fromKeypoint, to: toKeypoint)
282282 }
283283
284- return Human ( keypoints: keypoints, lines: lines)
284+ return Human2D ( keypoints: keypoints, lines: lines)
285285 }
286286
287- func parseMultiHuman( _ outputs: [ TFLiteFlatArray < Float32 > ] , partIndex: Int ? , partThreshold: Float ? , pairThreshold: Float ? , nmsFilterSize: Int , maxHumanNumber: Int ? ) -> [ Human ] {
287+ func parseMultiHuman( _ outputs: [ TFLiteFlatArray < Float32 > ] , partIndex: Int ? , partThreshold: Float ? , pairThreshold: Float ? , nmsFilterSize: Int , maxHumanNumber: Int ? ) -> [ Human2D ] {
288288 // openpose_ildoonet.tflite only use the first output
289289 let output = outputs [ 0 ]
290290
@@ -303,15 +303,15 @@ private extension PoseEstimationOutput {
303303 }
304304 }
305305
306- func parseSinglePartOnMultiHuman( _ output: TFLiteFlatArray < Float32 > , partIndex: Int , partThreshold: Float ? , nmsFilterSize: Int = 3 ) -> [ Human ] {
306+ func parseSinglePartOnMultiHuman( _ output: TFLiteFlatArray < Float32 > , partIndex: Int , partThreshold: Float ? , nmsFilterSize: Int = 3 ) -> [ Human2D ] {
307307 // process NMS
308308 let keypointIndexes = output. keypoints ( partIndex: partIndex,
309309 filterSize: nmsFilterSize,
310310 threshold: partThreshold)
311311
312312 // convert col,row to Keypoint
313- let kps : [ Keypoint ] = keypointIndexes. map { keypointInfo in
314- return Keypoint ( column: keypointInfo. col,
313+ let kps : [ Keypoint2D ] = keypointIndexes. map { keypointInfo in
314+ return Keypoint2D ( column: keypointInfo. col,
315315 row: keypointInfo. row,
316316 width: OpenPosePoseEstimator . Output. ConfidenceMap. width,
317317 height: OpenPosePoseEstimator . Output. ConfidenceMap. height,
@@ -320,14 +320,14 @@ private extension PoseEstimationOutput {
320320
321321 // Make [Human]
322322 return kps. map { keypoint in
323- let keypoints : [ Keypoint ? ] = OpenPosePoseEstimator . Output. BodyPart. allCases. enumerated ( ) . map { offset, _ in
323+ let keypoints : [ Keypoint2D ? ] = OpenPosePoseEstimator . Output. BodyPart. allCases. enumerated ( ) . map { offset, _ in
324324 return ( offset == partIndex) ? keypoint : nil
325325 }
326- return Human ( keypoints: keypoints, lines: [ ] )
326+ return Human2D ( keypoints: keypoints, lines: [ ] )
327327 }
328328 }
329329
330- func parseAllPartOnMultiHuman( _ output: TFLiteFlatArray < Float32 > , partIndex: Int ? , partThreshold: Float ? , pairThreshold: Float ? , nmsFilterSize: Int , maxHumanNumber: Int ? ) -> [ Human ] {
330+ func parseAllPartOnMultiHuman( _ output: TFLiteFlatArray < Float32 > , partIndex: Int ? , partThreshold: Float ? , pairThreshold: Float ? , nmsFilterSize: Int , maxHumanNumber: Int ? ) -> [ Human2D ] {
331331
332332 let parts = OpenPosePoseEstimator . Output. BodyPart. allCases
333333 var verticesForEachPart : [ [ KeypointElement ] ? ] = parts. map { _ in nil }
@@ -447,21 +447,21 @@ private extension PoseEstimationOutput {
447447 }
448448 }
449449
450- let humans : [ Human ] = tmpHumans. map { tmpHuman in
451- let keypoints : [ Keypoint ? ] = tmpHuman. enumerated ( ) . map { ( offset, locationInfo) in
450+ let humans : [ Human2D ] = tmpHumans. map { tmpHuman in
451+ let keypoints : [ Keypoint2D ? ] = tmpHuman. enumerated ( ) . map { ( offset, locationInfo) in
452452 guard let locationInfo = locationInfo else { return nil }
453- return Keypoint ( column: locationInfo. col,
453+ return Keypoint2D ( column: locationInfo. col,
454454 row: locationInfo. row,
455455 width: colSize,
456456 height: rowSize,
457457 value: locationInfo. val)
458458 }
459- let lines : [ ( from: Keypoint , to: Keypoint ) ] = pairs. compactMap { pair in
459+ let lines : [ ( from: Keypoint2D , to: Keypoint2D ) ] = pairs. compactMap { pair in
460460 guard let startingKeypoint = keypoints [ pair. from. offsetValue ( ) ] ,
461461 let endingKeypoint = keypoints [ pair. to. offsetValue ( ) ] else { return nil }
462462 return ( from: startingKeypoint, to: endingKeypoint)
463463 }
464- return Human ( keypoints: keypoints, lines: lines)
464+ return Human2D ( keypoints: keypoints, lines: lines)
465465 }
466466 return humans
467467 }
@@ -499,7 +499,7 @@ private extension TFLiteFlatArray where Element == Float32 {
499499 }
500500}
501501
502- private extension Keypoint {
502+ private extension Keypoint2D {
503503 init ( column: Int , row: Int , width: Int , height: Int , value: Float32 ) {
504504 let x = ( CGFloat ( column) + 0.5 ) / CGFloat( width)
505505 let y = ( CGFloat ( row) + 0.5 ) / CGFloat( height)
0 commit comments