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.NyARCode;
\r
36 import jp.nyatla.nyartoolkit.core.NyARColorPatt;
\r
39 * AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITH_PCAと同等のルールで
\r
43 public class NyARMatchPatt_Color_WITH_PCA implements ARMatchPatt{
\r
44 private final int EVEC_MAX=10;//#define EVEC_MAX 10
\r
45 private int evec_dim;//static int evec_dim;
\r
46 private int[][][] input;
\r
47 private double[][][][] evec;//static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
48 private double[][] epat=new double[4][EVEC_MAX];//static double epat[AR_PATT_NUM_MAX][4][EVEC_MAX];
\r
50 private double datapow;
\r
54 private double cf=0;
\r
55 private int dir=0;//向きか!
\r
56 public double getConfidence(){
\r
59 public int getDirection(){
\r
62 public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
64 width=i_target_patt.getWidth();
\r
65 height=i_target_patt.getHeight();
\r
66 int[][][] data=i_target_patt.getPatArray();
\r
68 input=new int[height][width][3];
\r
69 evec=new double[EVEC_MAX][height][width][3];//static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
73 for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
74 for(int i2=0;i2<width;i2++) {//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){
\r
75 ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);
\r
78 ave /= (height*width*3);
\r
80 for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
81 for(int i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){
\r
82 for(int i3=0;i3<3;i3++){
\r
83 input[i][i2][i3] = (255-data[i][i2][i3]) - ave;
\r
84 sum += input[i][i2][i3]*input[i][i2][i3];
\r
88 datapow = Math.sqrt( (double)sum );
\r
90 return false;//throw new NyARException();
\r
91 // dir.set(0);//*dir = 0;
\r
92 // cf.set(-1.0);//*cf = -1.0;
\r
98 * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)
\r
101 public void evaluate(NyARCode i_code)
\r
103 int[][][][] pat=i_code.getPat();
\r
104 double[] patpow=i_code.getPatPow();
\r
105 double[] invec=new double[EVEC_MAX];
\r
107 double max = 0.0; // fix VC7 compiler warning: uninitialized variable
\r
109 for(int i = 0; i < evec_dim; i++ ) {
\r
111 for(int j = 0; j <height; j++ ){//for(int j = 0; j <Config.AR_PATT_SIZE_Y; j++ ){
\r
112 for(int j2 = 0; j2 <width; j2++ ){
\r
113 for(int j3 = 0; j3 <3; j3++ ){
\r
114 invec[i] += evec[i][j][j2][j3] * input[j][j2][j3];//invec[i] += evec[i][j] * input[j];
\r
118 invec[i] /= datapow;
\r
121 double min = 10000.0;
\r
123 for(int j = 0; j < 4; j++ ) {
\r
125 for(int i = 0; i < evec_dim; i++ ) {
\r
126 sum2 += (invec[i] - epat[j][i]) * (invec[i] - epat[j][i]);
\r
131 // res2 = k;//kは常にインスタンスを刺すから、省略可能
\r
136 for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
137 for(int i2=0;i2<width;i2++){//for(int i2=0;i<Config.AR_PATT_SIZE_X;i2++){
\r
138 for(int i3=0;i3<3;i3++){
\r
139 sum += input[i][i2][i3]*pat[res][i][i2][i3];//sum += input[i][i2][i3]*pat[res2][res][i][i2][i3];
\r
143 max = sum / patpow[res] / datapow;
\r