| 114 | | |
|---|
| | 166 | |
|---|
| | 167 | private function checkNullMarker():void |
|---|
| | 168 | { |
|---|
| | 169 | this._detectFlag = 0; |
|---|
| | 170 | if (this._marker == null) return; |
|---|
| | 171 | this._detectFlag &= this._marker.top == null ? 0 : DETECT_FLAGS[CubeMarkerDirection.TOP]; |
|---|
| | 172 | this._detectFlag &= this._marker.bottom == null ? 0 : DETECT_FLAGS[CubeMarkerDirection.BOTTOM]; |
|---|
| | 173 | this._detectFlag &= this._marker.front == null ? 0 : DETECT_FLAGS[CubeMarkerDirection.FRONT]; |
|---|
| | 174 | this._detectFlag &= this._marker.back == null ? 0 : DETECT_FLAGS[CubeMarkerDirection.BACK]; |
|---|
| | 175 | this._detectFlag &= this._marker.left == null ? 0 : DETECT_FLAGS[CubeMarkerDirection.LEFT]; |
|---|
| | 176 | this._detectFlag &= this._marker.right == null ? 0 : DETECT_FLAGS[CubeMarkerDirection.RIGHT]; |
|---|
| | 177 | } |
|---|
| | 178 | |
|---|
| | 179 | /** |
|---|
| | 180 | * 終了閾値を設定する。 |
|---|
| | 181 | * @param immidate |
|---|
| | 182 | * @param end |
|---|
| | 183 | */ |
|---|
| | 184 | private function setEndConfidences(immidate:Number, end:Number):void |
|---|
| | 185 | { |
|---|
| | 186 | if (immidate < end) { |
|---|
| | 187 | throw new ArgumentError("即時終了条件" + immidate + "は、終了条件" + end + "以上である必要があります。"); |
|---|
| | 188 | } |
|---|
| | 189 | this._immidiateEndConfidence = immidate; |
|---|
| | 190 | this._endConfidence = end; |
|---|
| | 191 | } |
|---|
| 194 | | //まずはTOPから |
|---|
| 195 | | _match_patt.evaluate(this._marker.top); |
|---|
| 196 | | confidence = _match_patt.getConfidence(); |
|---|
| 197 | | direction = _match_patt.getDirection(); |
|---|
| 198 | | trace("top_confidence:", confidence); |
|---|
| 199 | | if (confidence > 0.9) { |
|---|
| 200 | | //終了条件1に一致 |
|---|
| | 302 | //3.次はBACK |
|---|
| | 303 | if (detectFlagTemp & DETECT_FLAGS[CubeMarkerDirection.BACK]) { |
|---|
| | 304 | _match_patt.evaluate(this._marker.back); |
|---|
| | 305 | result.backConf = _match_patt.getConfidence(); |
|---|
| | 306 | result.backDir = _match_patt.getDirection(); |
|---|
| | 307 | result.backSq = square; |
|---|
| | 308 | if (result.backConf > this._immidiateEndConfidence) { |
|---|
| | 309 | //即時終了条件1に一致 |
|---|
| | 310 | return this.createDetectedResult |
|---|
| | 311 | (result.backConf, result.backDir, square, CubeMarkerDirection.BACK); |
|---|
| | 312 | } |
|---|
| | 313 | } |
|---|
| | 314 | |
|---|
| | 315 | //4.次はLEFT |
|---|
| | 316 | if (detectFlagTemp & DETECT_FLAGS[CubeMarkerDirection.LEFT]) { |
|---|
| | 317 | _match_patt.evaluate(this._marker.left); |
|---|
| | 318 | result.leftConf = _match_patt.getConfidence(); |
|---|
| | 319 | result.leftDir = _match_patt.getDirection(); |
|---|
| | 320 | result.leftSq = square; |
|---|
| | 321 | if (result.leftConf > this._immidiateEndConfidence) { |
|---|
| | 322 | //即時終了条件1に一致 |
|---|
| | 323 | return this.createDetectedResult |
|---|
| | 324 | (result.leftConf, result.leftDir, square, CubeMarkerDirection.LEFT); |
|---|
| | 325 | } |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | //5.次はRIGHT |
|---|
| | 329 | if (detectFlagTemp & DETECT_FLAGS[CubeMarkerDirection.RIGHT]) { |
|---|
| | 330 | _match_patt.evaluate(this._marker.right); |
|---|
| | 331 | result.rightConf = _match_patt.getConfidence(); |
|---|
| | 332 | result.rightDir = _match_patt.getDirection(); |
|---|
| | 333 | result.rightSq = square; |
|---|
| | 334 | if (result.rightConf > this._immidiateEndConfidence) { |
|---|
| | 335 | //即時終了条件1に一致 |
|---|
| | 336 | return this.createDetectedResult |
|---|
| | 337 | (result.rightConf, result.rightDir, square, CubeMarkerDirection.RIGHT); |
|---|
| | 338 | } |
|---|
| | 339 | } |
|---|
| | 340 | |
|---|
| | 341 | //6.最後はBOTTOM |
|---|
| | 342 | if (detectFlagTemp & DETECT_FLAGS[CubeMarkerDirection.BOTTOM]) { |
|---|
| | 343 | _match_patt.evaluate(this._marker.bottom); |
|---|
| | 344 | result.bottomConf = _match_patt.getConfidence(); |
|---|
| | 345 | result.bottomDir = _match_patt.getDirection(); |
|---|
| | 346 | result.bottomSq = square; |
|---|
| | 347 | if (result.bottomConf > this._immidiateEndConfidence) { |
|---|
| | 348 | //即時終了条件1に一致 |
|---|
| | 349 | return this.createDetectedResult |
|---|
| | 350 | (result.bottomConf, result.bottomDir, square, CubeMarkerDirection.BOTTOM); |
|---|
| | 351 | } |
|---|
| | 352 | } |
|---|
| | 353 | |
|---|
| | 354 | //一番一致度の高かった面を調査 |
|---|
| | 355 | result.checkMaxConfidenceDirection(); |
|---|
| | 356 | //最高一致度が終了条件に達しているかを調査 |
|---|
| | 357 | if (result.currentMaxConfidence > this._endConfidence) { |
|---|
| | 358 | //終了条件1に合致したため、終了 |
|---|
| | 359 | return this.createDetectedResult(result.currentMaxConfidence, |
|---|
| | 360 | result.currentMaxConfidenceDirection, |
|---|
| | 361 | square, |
|---|
| | 362 | result.currentMaxConfidenceMarkerDirection); |
|---|
| | 363 | } else if (detectFlagTemp & DETECT_FLAGS[result.currentMaxConfidenceMarkerDirection]) { |
|---|
| | 364 | //最高一致したマーカは、次は評価しない |
|---|
| | 365 | detectFlagTemp ^= DETECT_FLAGS[result.currentMaxConfidenceMarkerDirection]; |
|---|
| | 366 | } |
|---|
| | 367 | |
|---|
| | 368 | } |
|---|
| | 369 | return this.createDetectedResult(result.currentMaxConfidence, |
|---|
| | 370 | result.currentMaxConfidenceDirection, |
|---|
| | 371 | square, |
|---|
| | 372 | result.currentMaxConfidenceMarkerDirection); |
|---|
| | 373 | //return number_of_square; |
|---|
| | 374 | } |
|---|
| | 375 | |
|---|
| | 376 | private function createDetectedResult(confidence:Number,direction:int square:FLARSquare,markerDirection:String):Object |
|---|
| | 377 | { |
|---|
| 207 | | } |
|---|
| 208 | | for (i2 = 1; i2 < this._number_of_code; i2++) { |
|---|
| 209 | | if (this._codeResult[i2]) continue; |
|---|
| 210 | | // コードと比較する |
|---|
| 211 | | _match_patt.evaluate(_codes[i2]); |
|---|
| 212 | | c2 = _match_patt.getConfidence(); |
|---|
| 213 | | trace(i, i2, c2,"(",square.label.area,")"); |
|---|
| 214 | | if (confidence > c2) { |
|---|
| 215 | | continue; |
|---|
| 216 | | } |
|---|
| 217 | | // より一致するARCodeの情報を保存 |
|---|
| 218 | | code_index = i2; |
|---|
| 219 | | direction = _match_patt.getDirection(); |
|---|
| 220 | | confidence = c2; |
|---|
| 221 | | } |
|---|
| 222 | | //if (confidence > 0.8) trace("GREAT!!",i, code_index, confidence); |
|---|
| 223 | | // i番目のパターン情報を保存する。 |
|---|
| 224 | | var result:FLARMultiMarkerDetectorResult = this._result_holder.result_array[i]; |
|---|
| 225 | | result._codeId = code_index; |
|---|
| 226 | | result._confidence = confidence; |
|---|
| 227 | | result._direction = direction; |
|---|
| 228 | | result._square = square; |
|---|
| 229 | | this._codeResult[code_index] = true; |
|---|
| 230 | | if (confidence > 0.8) return result; |
|---|
| 231 | | } |
|---|
| 232 | | return null; |
|---|
| 233 | | //return number_of_square; |
|---|
| 234 | | } |
|---|
| 235 | | |
|---|
| | 384 | } |
|---|
| | 465 | import org.libspark.flartoolkit.core.FLARSquare; |
|---|
| | 466 | /** |
|---|
| | 467 | * キューブ型マーカの探索結果を一時的にためておくホルダ |
|---|
| | 468 | */ |
|---|
| | 469 | class CubeMarkerMatchResultTemporaryHolder { |
|---|
| | 470 | |
|---|
| | 471 | public var topConf:Number; |
|---|
| | 472 | public var bottomConf:Number; |
|---|
| | 473 | public var frontConf:Number; |
|---|
| | 474 | public var backConf:Number; |
|---|
| | 475 | public var leftConf:Number; |
|---|
| | 476 | public var rightConf:Number; |
|---|
| | 477 | |
|---|
| | 478 | public var topDir:int; |
|---|
| | 479 | public var bottomDir:int; |
|---|
| | 480 | public var frontDir:int; |
|---|
| | 481 | public var backDir:int; |
|---|
| | 482 | public var leftDir:int; |
|---|
| | 483 | public var rightDir:int; |
|---|
| | 484 | |
|---|
| | 485 | public var topSq:FLARSquare; |
|---|
| | 486 | public var bottomSq:FLARSquare; |
|---|
| | 487 | public var frontSq:FLARSquare; |
|---|
| | 488 | public var backSq:FLARSquare; |
|---|
| | 489 | public var leftSq:FLARSquare; |
|---|
| | 490 | public var rightSq:FLARSquare; |
|---|
| | 491 | |
|---|
| | 492 | private var _currentMaxConfidenceMarkerDirection:String; |
|---|
| | 493 | private var _currentMaxConfidence:Number; |
|---|
| | 494 | private var _currentMaxConfidenceDirection:int; |
|---|
| | 495 | private var _currentMaxConfidenceSquare:FLARSquare; |
|---|
| | 496 | |
|---|
| | 497 | /** |
|---|
| | 498 | * 現在保持している一致度の中で、最も一致度が高い面を返す |
|---|
| | 499 | * @return |
|---|
| | 500 | */ |
|---|
| | 501 | public function checkMaxConfidenceDirection():Object |
|---|
| | 502 | { |
|---|
| | 503 | _currentMaxConfidenceMarkerDirection = CubeMarkerDirection.TOP; |
|---|
| | 504 | _currentMaxConfidence = topConf; |
|---|
| | 505 | _currentMaxConfidenceDirection = topDir; |
|---|
| | 506 | _currentMaxConfidenceSquare = topSq; |
|---|
| | 507 | |
|---|
| | 508 | if (bottomConf > maxConf) { |
|---|
| | 509 | _currentMaxConfidenceMarkerDirection = CubeMarkerDirection.BOTTOM; |
|---|
| | 510 | _currentMaxConfidence = bottomConf; |
|---|
| | 511 | _currentMaxConfidenceDirection = bottomDir; |
|---|
| | 512 | _currentMaxConfidenceSquare = bottomSq; |
|---|
| | 513 | } |
|---|
| | 514 | if (frontConf > maxConf) { |
|---|
| | 515 | _currentMaxConfidenceMarkerDirection = CubeMarkerDirection.FRONT; |
|---|
| | 516 | _currentMaxConfidence = frontConf; |
|---|
| | 517 | _currentMaxConfidenceDirection = frontDir; |
|---|
| | 518 | _currentMaxConfidenceSquare = frontSq; |
|---|
| | 519 | } |
|---|
| | 520 | if (backConf > maxConf) { |
|---|
| | 521 | _currentMaxConfidenceMarkerDirection = CubeMarkerDirection.BACK; |
|---|
| | 522 | _currentMaxConfidence = backConf; |
|---|
| | 523 | _currentMaxConfidenceDirection = backDir; |
|---|
| | 524 | _currentMaxConfidenceSquare = backSq; |
|---|
| | 525 | } |
|---|
| | 526 | if (leftConf > maxConf) { |
|---|
| | 527 | _currentMaxConfidenceMarkerDirection = CubeMarkerDirection.LEFT; |
|---|
| | 528 | _currentMaxConfidence = leftConf; |
|---|
| | 529 | _currentMaxConfidenceDirection = leftDir; |
|---|
| | 530 | _currentMaxConfidenceSquare = leftSq; |
|---|
| | 531 | } |
|---|
| | 532 | if (rightConf > maxConf) { |
|---|
| | 533 | _currentMaxConfidenceMarkerDirection = CubeMarkerDirection.RIGHT; |
|---|
| | 534 | _currentMaxConfidence = rightConf; |
|---|
| | 535 | _currentMaxConfidenceDirection = rightDir; |
|---|
| | 536 | _currentMaxConfidenceSquare = rightSq; |
|---|
| | 537 | } |
|---|
| | 538 | } |
|---|
| | 539 | |
|---|
| | 540 | /** |
|---|
| | 541 | * 保持している情報を全て消去する。 |
|---|
| | 542 | */ |
|---|
| | 543 | public function reset():void |
|---|
| | 544 | { |
|---|
| | 545 | topConf = 0; |
|---|
| | 546 | bottomConf = 0; |
|---|
| | 547 | frontConf = 0; |
|---|
| | 548 | backConf = 0; |
|---|
| | 549 | leftConf = 0; |
|---|
| | 550 | rightConf = 0; |
|---|
| | 551 | |
|---|
| | 552 | topDir = 0; |
|---|
| | 553 | bottomDir = 0; |
|---|
| | 554 | frontDir = 0; |
|---|
| | 555 | backDir = 0; |
|---|
| | 556 | leftDir = 0; |
|---|
| | 557 | rightDir = 0; |
|---|
| | 558 | } |
|---|
| | 559 | /** |
|---|
| | 560 | * 現在、最も一致度の高いマーカの面 |
|---|
| | 561 | */ |
|---|
| | 562 | public function get currentMaxConfidenceMarkerDirection():String { return _currentMaxConfidenceMarkerDirection; } |
|---|
| | 563 | |
|---|
| | 564 | public function get currentMaxConfidence():Number { return _currentMaxConfidence; } |
|---|
| | 565 | |
|---|
| | 566 | public function get currentMaxConfidence():Number { return _currentMaxConfidence; } |
|---|
| | 567 | |
|---|
| | 568 | public function get currentMaxConfidenceDirection():int { return _currentMaxConfidenceDirection; } |
|---|
| | 569 | |
|---|
| | 570 | public function get currentMaxConfidenceSquare():FLARSquare { return _currentMaxConfidenceSquare; } |
|---|
| | 571 | } |
|---|