2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.core.match;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.*;
\r
38 * AR_TEMPLATE_MATCHING_BWと同等のルールで
\r
42 public class NyARMatchPatt_BlackWhite implements ARMatchPatt{
\r
43 private double datapow;
\r
46 private double cf=0;
\r
49 private int[][][] input=new int[height][width][3];
\r
50 public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
52 width=i_target_patt.getWidth();
\r
53 height=i_target_patt.getHeight();
\r
54 short[][][] data=i_target_patt.getPatArray();
\r
55 input=new int[height][width][3];
\r
58 for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
59 for(int i2=0;i2<width;i2++) {//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){
\r
60 ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);
\r
63 ave /= (height*width*3);
\r
65 for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
66 for(int i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){
\r
67 input[i][i2][0] = ((255-data[i][i2][0]) + (255-data[i][i2][1]) + (255-data[i][i2][2]))/3 - ave;
\r
68 sum += input[i][i2][0]*input[i][i2][0];
\r
72 datapow = Math.sqrt( (double)sum );
\r
73 if( datapow == 0.0 ){
\r
74 return false;// throw new NyARException();
\r
75 // dir.set(0);//*dir = 0;
\r
76 // cf.set(-1.0);//*cf = -1.0;
\r
81 public double getConfidence()
\r
85 public int getDirection()
\r
89 public void evaluate(NyARCode i_code)
\r
91 short[][][] patBW=i_code.getPatBW();//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
92 double[] patpowBW=i_code.getPatPowBW();//static double patpowBW[AR_PATT_NUM_MAX][4];
\r
96 //本家が飛ぶ。試験データで0.77767376888がが出ればOKってことで
\r
97 for(int j = 0; j < 4; j++ ) {
\r
99 for(int i=0;i<height;i++){
\r
100 for(int i2=0;i2<width;i2++){
\r
101 sum += input[i][i2][0]*patBW[j][i][i2];
\r
104 double sum2 = sum / patpowBW[j] / datapow;
\r