--- /dev/null
+package jp.nyatla.nyartoolkit.core.analyzer.histgram;\r
+\r
+import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
+\r
+public interface INyARHistgramAnalyzer_Threshold\r
+{\r
+ /**\r
+ * ヒストグラムから閾値探索をします。\r
+ * @param i_histgram\r
+ * ヒストグラム\r
+ * @return\r
+ */\r
+ public int getThreshold(NyARHistgram i_histgram);\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.analyzer.histgram;\r
+\r
+import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
+\r
+/**\r
+ * 判別法で閾値を求めます。\r
+ * 画素数が2048^2に満たない場合は、fixedint(24-8)で計算できます。\r
+ * @param i_histgram\r
+ * @param o_value\r
+ * @return\r
+ */\r
+public class NyARHistgramAnalyzer_DiscriminantThreshold implements INyARHistgramAnalyzer_Threshold\r
+{\r
+ private double _score;\r
+\r
+ public int getThreshold(NyARHistgram i_histgram)\r
+ {\r
+ int[] hist=i_histgram.data;\r
+ int n=i_histgram.length;\r
+ int da,sa,db,sb,dt,pt,st;\r
+ int i; \r
+ int th=0;\r
+ //後で使う\r
+ dt=pt=0;\r
+ for(i=0;i<n;i++){\r
+ int h=hist[i];\r
+ dt+=h*i;\r
+ pt+=h*i*i;//正規化の時に使う定数\r
+ }\r
+ st=i_histgram.total_of_data;\r
+ //Low側(0<=i<=n-2)\r
+ da=dt;\r
+ sa=st;\r
+ //High側(i=n-1)\r
+ db=sb=0; \r
+ \r
+ double max=-1;\r
+ double max_mt=0;\r
+ //各ヒストグラムの分離度を計算する(1<=i<=n-1の範囲で評価)\r
+ for(i=n-1;i>0;i--){\r
+ //次のヒストグラムを計算\r
+ int hist_count=hist[i];\r
+ int hist_val=hist_count*i;\r
+ da-=hist_val;\r
+ sa-=hist_count;\r
+ db+=hist_val;\r
+ sb+=hist_count;\r
+ \r
+ //クラス間分散を計算\r
+ double dv=(sa+sb);\r
+ double mt=(double)(da+db)/dv;\r
+ double ma=(sa!=0?((double)da/(double)sa):0)-mt;\r
+ double mb=(sb!=0?((double)db/(double)sb):0)-mt;\r
+ double kai=((double)(sa*(ma*ma)+sb*(mb*mb)))/dv;\r
+ if(max<kai){\r
+ max_mt=mt;\r
+ max=kai;\r
+ th=i;\r
+ }\r
+ //System.out.println(kai);\r
+ }\r
+ //max_mtを元に正規化\r
+ this._score=max/((double)(pt+max_mt*max_mt*st-2*max_mt*dt)/st);//129,0.8888888888888887\r
+ return th;\r
+ }\r
+ /**\r
+ * 最後に実行したgetThresholdのスコアを返します。\r
+ * スコアは正規化された分離度。1.0-0.0の範囲を取る。0.7以上なら概ね双峰的です。\r
+ * @return\r
+ */\r
+ public final double getLastScore()\r
+ {\r
+ return this._score;\r
+ }\r
+ /**\r
+ * Debug\r
+ */\r
+ public static void main(String[] args)\r
+ {\r
+ NyARHistgram data=new NyARHistgram(256);\r
+ for(int i=0;i<256;i++){\r
+ data.data[i]=128-i>0?128-i:i-128;\r
+ }\r
+ data.total_of_data=data.getTotal(0,255);\r
+ NyARHistgramAnalyzer_DiscriminantThreshold an=new NyARHistgramAnalyzer_DiscriminantThreshold();\r
+ int th=an.getThreshold(data);\r
+ System.out.print(th);\r
+ return;\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.analyzer.histgram;\r
+\r
+import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
+\r
+\r
+/**\r
+ * kittlerThresholdの方式で閾値を求めます。\r
+ * @param i_histgram\r
+ * @return\r
+ */\r
+public class NyARHistgramAnalyzer_KittlerThreshold implements INyARHistgramAnalyzer_Threshold\r
+{\r
+ public int getThreshold(NyARHistgram i_histgram)\r
+ {\r
+ int i; \r
+ double min=Double.MAX_VALUE;\r
+ int th=0;\r
+ int da,sa,db,sb,pa,pb;\r
+ double oa,ob;\r
+ \r
+ int[] hist=i_histgram.data;\r
+ int n=i_histgram.length;\r
+ //Low側\r
+ da=pa=0;\r
+ int h;\r
+ for(i=0;i<n;i++){\r
+ h=hist[i];\r
+ da+=h*i; //i*h[i]\r
+ pa+=h*i*i; //i*i*h[i]\r
+ }\r
+ sa=i_histgram.total_of_data;\r
+ //High側(i=n-1)\r
+ db=0;\r
+ sb=0;\r
+ pb=0;\r
+ \r
+ \r
+ for(i=n-1;i>0;i--){\r
+ //次のヒストグラムを計算\r
+ int hist_count=hist[i];//h[i]\r
+ int hist_val =hist_count*i; //h[i]*i\r
+ int hist_val2=hist_val*i; //h[i]*i*i\r
+ da-=hist_val;\r
+ sa-=hist_count;\r
+ pa-=hist_val2;\r
+ db+=hist_val;\r
+ sb+=hist_count; \r
+ pb+=hist_val2;\r
+\r
+ //初期化\r
+ double wa=(double)sa/(sa+sb);\r
+ double wb=(double)sb/(sa+sb);\r
+ if(wa==0 || wb==0){\r
+ continue;\r
+ }\r
+\r
+ oa=ob=0;\r
+ double ma=sa!=0?(double)da/sa:0;\r
+ //Σ(i-ma)^2*h[i]=Σ(i^2*h[i])+Σ(ma^2*h[i])-Σ(2*i*ma*h[i])\r
+ oa=((double)(pa+ma*ma*sa-2*ma*da))/sa;\r
+\r
+ double mb=sb!=0?(double)db/sb:0;\r
+ //Σ(i-mb)^2*h[i]=Σ(i^2*h[i])+Σ(mb^2*h[i])-Σ(2*i*mb*h[i])\r
+ ob=((double)(pb+mb*mb*sb-2*mb*db))/sb;\r
+\r
+ double kai=wa*Math.log(oa/wa)+wb*Math.log(ob/wb);\r
+ if(kai>0 && min>kai){\r
+ min=kai;\r
+ th=i;\r
+ }\r
+ //System.out.println(kai);\r
+\r
+ }\r
+ return th;//129//7.506713872738873\r
+ }\r
+ public static void main(String[] args)\r
+ {\r
+ NyARHistgram data=new NyARHistgram(256);\r
+ for(int i=0;i<256;i++){\r
+ data.data[i]=128-i>0?128-i:i-128;\r
+ }\r
+ data.total_of_data=data.getTotal(0,255);\r
+ NyARHistgramAnalyzer_KittlerThreshold an=new NyARHistgramAnalyzer_KittlerThreshold();\r
+ int th=an.getThreshold(data);\r
+ System.out.print(th);\r
+ return;\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.analyzer.histgram;\r
+\r
+import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
+\r
+\r
+\r
+/**\r
+ * 明点と暗点を双方向からPタイル法でカウントして、その中央値を閾値とする。\r
+ * \r
+ * \r
+ */\r
+public class NyARHistgramAnalyzer_SlidePTile\r
+{\r
+ private int _persentage;\r
+ public NyARHistgramAnalyzer_SlidePTile(int i_persentage)\r
+ {\r
+ assert (0 <= i_persentage && i_persentage <= 50);\r
+ //初期化\r
+ this._persentage=i_persentage;\r
+ } \r
+ public int getThreshold(NyARHistgram i_histgram)\r
+ {\r
+ //総ピクセル数を計算\r
+ int n=i_histgram.length;\r
+ int sum_of_pixel=i_histgram.total_of_data;\r
+ int[] hist=i_histgram.data;\r
+ // 閾値ピクセル数確定\r
+ final int th_pixcels = sum_of_pixel * this._persentage / 100;\r
+ int th_wk;\r
+ int th_w, th_b;\r
+\r
+ // 黒点基準\r
+ th_wk = th_pixcels;\r
+ for (th_b = 0; th_b < n-2; th_b++) {\r
+ th_wk -= hist[th_b];\r
+ if (th_wk <= 0) {\r
+ break;\r
+ }\r
+ }\r
+ // 白点基準\r
+ th_wk = th_pixcels;\r
+ for (th_w = n-1; th_w > 1; th_w--) {\r
+ th_wk -= hist[th_w];\r
+ if (th_wk <= 0) {\r
+ break;\r
+ }\r
+ }\r
+ // 閾値の保存\r
+ return (th_w + th_b) / 2;\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.analyzer.raster;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
+import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+import jp.nyatla.nyartoolkit.core.analyzer.histgram.*;\r
+/**\r
+ * 画像のヒストグラムを計算します。\r
+ * RGBの場合、(R+G+B)/3のヒストグラムを計算します。\r
+ * \r
+ * \r
+ */\r
+public class NyARRasterAnalyzer_Histgram\r
+{\r
+ private ICreateHistgramImpl _histImpl;\r
+ /**\r
+ * ヒストグラム解析の縦方向スキップ数。継承クラスはこのライン数づつ\r
+ * スキップしながらヒストグラム計算を行うこと。\r
+ */\r
+ protected int _vertical_skip;\r
+ \r
+ \r
+ public NyARRasterAnalyzer_Histgram(int i_raster_format,int i_vertical_interval) throws NyARException\r
+ {\r
+ switch (i_raster_format) {\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+ this._histImpl = new NyARRasterThresholdAnalyzer_Histgram_BYTE1D_RGB_24();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+ this._histImpl = new NyARRasterThresholdAnalyzer_Histgram_INT1D_GRAY_8();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
+ this._histImpl = new NyARRasterThresholdAnalyzer_Histgram_BYTE1D_B8G8R8X8_32();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:\r
+ this._histImpl = new NyARRasterThresholdAnalyzer_Histgram_BYTE1D_X8R8G8B8_32();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:\r
+ this._histImpl = new NyARRasterThresholdAnalyzer_Histgram_WORD1D_R5G6B5_16LE();\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ //初期化\r
+ this._vertical_skip=i_vertical_interval;\r
+ } \r
+ public void setVerticalInterval(int i_step)\r
+ {\r
+ this._vertical_skip=i_step;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * o_histgramにヒストグラムを出力します。\r
+ * @param i_input\r
+ * @param o_histgram\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public int analyzeRaster(INyARRaster i_input,NyARHistgram o_histgram) throws NyARException\r
+ {\r
+ \r
+ final NyARIntSize size=i_input.getSize();\r
+ //最大画像サイズの制限\r
+ assert size.w*size.h<0x40000000;\r
+ assert o_histgram.length==256;//現在は固定\r
+\r
+ int[] h=o_histgram.data;\r
+ //ヒストグラム初期化\r
+ for (int i = o_histgram.length-1; i >=0; i--){\r
+ h[i] = 0;\r
+ }\r
+ return this._histImpl.createHistgram(i_input.getBufferReader(), size,h,this._vertical_skip); \r
+ }\r
+ \r
+ interface ICreateHistgramImpl\r
+ {\r
+ public int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram,int i_skip);\r
+ }\r
+\r
+ class NyARRasterThresholdAnalyzer_Histgram_INT1D_GRAY_8 implements ICreateHistgramImpl\r
+ {\r
+ public int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram,int i_skip)\r
+ {\r
+ assert (i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ final int[] input=(int[]) i_reader.getBuffer();\r
+ for (int y = i_size.h-1; y >=0 ; y-=i_skip){\r
+ int pt=y*i_size.w;\r
+ for (int x = i_size.w-1; x >=0; x--) {\r
+ o_histgram[input[pt]]++;\r
+ pt++;\r
+ }\r
+ }\r
+ return i_size.w*i_size.h;\r
+ } \r
+ }\r
+\r
+ class NyARRasterThresholdAnalyzer_Histgram_BYTE1D_RGB_24 implements ICreateHistgramImpl\r
+ {\r
+ public int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram,int i_skip)\r
+ {\r
+ assert (\r
+ i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24)||\r
+ i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24));\r
+ final byte[] input=(byte[]) i_reader.getBuffer();\r
+ final int pix_count=i_size.w;\r
+ final int pix_mod_part=pix_count-(pix_count%8);\r
+ for (int y = i_size.h-1; y >=0 ; y-=i_skip) {\r
+ int pt=y*i_size.w*3;\r
+ int x,v;\r
+ for (x = pix_count-1; x >=pix_mod_part; x--) {\r
+ v=((input[pt+0]& 0xff)+(input[pt+1]& 0xff)+(input[pt+2]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ pt+=3;\r
+ }\r
+ //タイリング\r
+ for (;x>=0;x-=8){\r
+ v=((input[pt+ 0]& 0xff)+(input[pt+ 1]& 0xff)+(input[pt+ 2]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+ 3]& 0xff)+(input[pt+ 4]& 0xff)+(input[pt+ 5]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+ 6]& 0xff)+(input[pt+ 7]& 0xff)+(input[pt+ 8]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+ 9]& 0xff)+(input[pt+10]& 0xff)+(input[pt+11]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+12]& 0xff)+(input[pt+13]& 0xff)+(input[pt+14]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+15]& 0xff)+(input[pt+16]& 0xff)+(input[pt+17]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+18]& 0xff)+(input[pt+19]& 0xff)+(input[pt+20]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ v=((input[pt+21]& 0xff)+(input[pt+22]& 0xff)+(input[pt+23]& 0xff))/3;\r
+ o_histgram[v]++;\r
+ pt+=3*8;\r
+ }\r
+ }\r
+ return i_size.w*i_size.h;\r
+ }\r
+ }\r
+\r
+ class NyARRasterThresholdAnalyzer_Histgram_BYTE1D_B8G8R8X8_32 implements ICreateHistgramImpl\r
+ {\r
+ public int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram,int i_skip)\r
+ {\r
+ assert(i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32));\r
+ byte[] input = (byte[])i_reader.getBuffer();\r
+ int pix_count = i_size.w;\r
+ int pix_mod_part = pix_count - (pix_count % 8);\r
+ for (int y = i_size.h - 1; y >= 0; y -= i_skip)\r
+ {\r
+ int pt = y * i_size.w * 4;\r
+ int x, v;\r
+ for (x = pix_count - 1; x >= pix_mod_part; x--)\r
+ {\r
+ v = ((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ pt += 4;\r
+ }\r
+ //タイリング\r
+ for (; x >= 0; x -= 8)\r
+ {\r
+ v = ((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 4] & 0xff) + (input[pt + 5] & 0xff) + (input[pt + 6] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 8] & 0xff) + (input[pt + 9] & 0xff) + (input[pt + 10] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 12] & 0xff) + (input[pt + 13] & 0xff) + (input[pt + 14] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 16] & 0xff) + (input[pt + 17] & 0xff) + (input[pt + 18] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 20] & 0xff) + (input[pt + 21] & 0xff) + (input[pt + 22] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 24] & 0xff) + (input[pt + 25] & 0xff) + (input[pt + 26] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 28] & 0xff) + (input[pt + 29] & 0xff) + (input[pt + 30] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ pt += 4 * 8;\r
+ }\r
+ }\r
+ return i_size.w*i_size.h;\r
+ }\r
+ }\r
+\r
+ class NyARRasterThresholdAnalyzer_Histgram_BYTE1D_X8R8G8B8_32 implements ICreateHistgramImpl\r
+ {\r
+ public int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram,int i_skip)\r
+ {\r
+ assert(i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32));\r
+ byte[] input = (byte[])i_reader.getBuffer();\r
+ int pix_count = i_size.w;\r
+ int pix_mod_part = pix_count - (pix_count % 8);\r
+ for (int y = i_size.h - 1; y >= 0; y -=i_skip)\r
+ {\r
+ int pt = y * i_size.w * 4;\r
+ int x, v;\r
+ for (x = pix_count - 1; x >= pix_mod_part; x--)\r
+ {\r
+ v = ((input[pt + 1] & 0xff) + (input[pt + 2] & 0xff) + (input[pt + 3] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ pt += 4;\r
+ }\r
+ //タイリング\r
+ for (; x >= 0; x -= 8)\r
+ {\r
+ v = ((input[pt + 1] & 0xff) + (input[pt + 2] & 0xff) + (input[pt + 3] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 5] & 0xff) + (input[pt + 6] & 0xff) + (input[pt + 7] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 9] & 0xff) + (input[pt + 10] & 0xff) + (input[pt + 11] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 13] & 0xff) + (input[pt + 14] & 0xff) + (input[pt + 15] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 17] & 0xff) + (input[pt + 18] & 0xff) + (input[pt + 19] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 21] & 0xff) + (input[pt + 22] & 0xff) + (input[pt + 23] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 25] & 0xff) + (input[pt + 26] & 0xff) + (input[pt + 27] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ v = ((input[pt + 29] & 0xff) + (input[pt + 30] & 0xff) + (input[pt + 31] & 0xff)) / 3;\r
+ o_histgram[v]++;\r
+ pt += 4 * 8;\r
+ }\r
+ }\r
+ return i_size.w*i_size.h;\r
+ }\r
+ }\r
+\r
+ class NyARRasterThresholdAnalyzer_Histgram_WORD1D_R5G6B5_16LE implements ICreateHistgramImpl\r
+ {\r
+ public int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram,int i_skip)\r
+ {\r
+ assert(i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE));\r
+ short[] input = (short[])i_reader.getBuffer();\r
+ int pix_count = i_size.w;\r
+ int pix_mod_part = pix_count - (pix_count % 8);\r
+ for (int y = i_size.h - 1; y >= 0; y -= i_skip)\r
+ {\r
+ int pt = y * i_size.w;\r
+ int x, v;\r
+ for (x = pix_count - 1; x >= pix_mod_part; x--)\r
+ {\r
+ v =(int)input[pt];\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ pt++;\r
+ }\r
+ //タイリング\r
+ for (; x >= 0; x -= 8)\r
+ {\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ v =(int)input[pt];pt++;\r
+ v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
+ o_histgram[v]++;\r
+ }\r
+ }\r
+ return i_size.w*i_size.h;\r
+ }\r
+ }\r
+\r
+\r
+}
\ No newline at end of file
* <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
* \r
*/\r
-package jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold;\r
+package jp.nyatla.nyartoolkit.core.analyzer.raster.threshold;\r
\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
\r
public interface INyARRasterThresholdAnalyzer\r
{\r
- public void analyzeRaster(INyARRaster i_input) throws NyARException;\r
-\r
- public int getThreshold();\r
+ public int analyzeRaster(INyARRaster i_input) throws NyARException;\r
}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.analyzer.raster.threshold;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.analyzer.histgram.*;\r
+import jp.nyatla.nyartoolkit.core.analyzer.raster.*;\r
+import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
+import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
+/**\r
+ * 明点と暗点をPタイル法で検出して、その中央値を閾値とする。\r
+ * \r
+ * \r
+ */\r
+public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresholdAnalyzer\r
+{\r
+ private NyARRasterAnalyzer_Histgram _raster_analyzer;\r
+ private NyARHistgramAnalyzer_SlidePTile _sptile;\r
+ private NyARHistgram _histgram;\r
+ public void setVerticalInterval(int i_step)\r
+ {\r
+ this._raster_analyzer.setVerticalInterval(i_step);\r
+ return;\r
+ }\r
+ public NyARRasterThresholdAnalyzer_SlidePTile(int i_persentage,int i_raster_format,int i_vertical_interval) throws NyARException\r
+ {\r
+ assert (0 <= i_persentage && i_persentage <= 50);\r
+ //初期化\r
+ this._sptile=new NyARHistgramAnalyzer_SlidePTile(i_persentage);\r
+ this._histgram=new NyARHistgram(256);\r
+ this._raster_analyzer=new NyARRasterAnalyzer_Histgram(i_raster_format,i_vertical_interval);\r
+ }\r
+ \r
+ public int analyzeRaster(INyARRaster i_input) throws NyARException\r
+ {\r
+ this._raster_analyzer.analyzeRaster(i_input, this._histgram);\r
+ return this._sptile.getThreshold(this._histgram);\r
+ }\r
+}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core.rasterfilter;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-\r
-public interface INyARRasterFilter_GsToBin\r
-{\r
- public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException;\r
-}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.rasterfilter.gs2bin;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;\r
+\r
+public interface INyARRasterFilter_Gs2Bin\r
+{\r
+ public abstract void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException;\r
+\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.rasterfilter.gs2bin;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+public class NyARRasterFilter_ConstantThrshold implements INyARRasterFilter_Gs2Bin\r
+{\r
+ public int _threshold;\r
+ public NyARRasterFilter_ConstantThrshold(int i_initial_threshold) throws NyARException\r
+ {\r
+ //初期化\r
+ this._threshold=i_initial_threshold;\r
+ }\r
+\r
+ \r
+ public void setThreshold(int i_threshold)\r
+ {\r
+ this._threshold = i_threshold;\r
+ }\r
+ public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
+ {\r
+ INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
+ INyARBufferReader out_buffer_reader=i_output.getBufferReader();\r
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
+ int[] in_buf = (int[]) in_buffer_reader.getBuffer();\r
+ NyARIntSize s=i_input.getSize();\r
+ \r
+ final int th=this._threshold;\r
+ int bp =s.w*s.h-1;\r
+ final int pix_count =s.h*s.w;\r
+ final int pix_mod_part=pix_count-(pix_count%8);\r
+ for(bp=pix_count-1;bp>=pix_mod_part;bp--){\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ }\r
+ //タイリング\r
+ for (;bp>=0;) {\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;\r
+ bp--;\r
+ }\r
+ return; \r
+ }\r
+}\r
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+\r
\r
/**\r
* 定数閾値による2値化をする。\r
*/\r
public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_RgbToBin\r
{\r
+ private int _threshold;\r
+ private IdoThFilterImpl _do_threshold_impl;\r
+\r
+ public NyARRasterFilter_ARToolkitThreshold(int i_threshold,int i_input_raster_type) throws NyARException\r
+ {\r
+ this._threshold = i_threshold;\r
+ switch (i_input_raster_type) {\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_RGB_24();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_B8G8R8X8_32();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:\r
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_X8R8G8B8_32();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_INT1D_X8R8G8B8_32();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:\r
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_WORD1D_R5G6B5_16LE();\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+\r
+ \r
+ }\r
+ public void setThreshold(int i_threshold)\r
+ {\r
+ this._threshold = i_threshold;\r
+ }\r
+\r
+ public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output) throws NyARException\r
+ {\r
+ INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
+ INyARBufferReader out_buffer_reader=i_output.getBufferReader();\r
+\r
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+ this._do_threshold_impl.doThFilter(in_buffer_reader,out_buffer_reader,i_output.getSize(), this._threshold);\r
+ return;\r
+ }\r
+ /*\r
+ * ここから各ラスタ用のフィルタ実装\r
+ */\r
interface IdoThFilterImpl\r
{\r
public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold);\r
}\r
} \r
} \r
- \r
- \r
- \r
- \r
-\r
- \r
- \r
- \r
- \r
- private int _threshold;\r
- private IdoThFilterImpl _do_threshold_impl;\r
-\r
- public NyARRasterFilter_ARToolkitThreshold(int i_threshold,int i_input_raster_type) throws NyARException\r
- {\r
- this._threshold = i_threshold;\r
- switch (i_input_raster_type) {\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
- this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_RGB_24();\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
- this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_B8G8R8X8_32();\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:\r
- this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_X8R8G8B8_32();\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
- this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_INT1D_X8R8G8B8_32();\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:\r
- this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_WORD1D_R5G6B5_16LE();\r
- break;\r
- default:\r
- throw new NyARException();\r
- }\r
-\r
- \r
- }\r
- public void setThreshold(int i_threshold)\r
- {\r
- this._threshold = i_threshold;\r
- }\r
-\r
- public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output) throws NyARException\r
- {\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader();\r
-\r
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
- this._do_threshold_impl.doThFilter(in_buffer_reader,out_buffer_reader,i_output.getSize(), this._threshold);\r
- return;\r
- }\r
-\r
}\r
* <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
* \r
*/\r
-package jp.nyatla.nyartoolkit.core.rasterfilter;\r
+package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
* <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
* \r
*/\r
-package jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs;\r
+package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_RgbToGs;\r
import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
\r
-public class NyARRasterFilter_RgbAve implements INyARRasterFilter_RgbToGs\r
+/**\r
+ * RGBラスタをGrayScaleに変換するフィルタを作成します。\r
+ * このフィルタは、RGB値の平均値を、(R+G+B)/3で算出します。\r
+ *\r
+ */\r
+public class NyARRasterFilter_RgbAveAdd implements INyARRasterFilter_RgbToGs\r
{\r
- public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
+ IdoThFilterImpl _do_filter_impl;\r
+ public NyARRasterFilter_RgbAveAdd(int i_raster_type) throws NyARException\r
{\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
-\r
- int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
- byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();\r
-\r
- NyARIntSize size = i_output.getSize();\r
- switch (in_buffer_reader.getBufferType()) {\r
+ switch (i_raster_type) {\r
case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
- convert24BitRgb(in_buf, out_buf, size);\r
+ this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24();\r
break;\r
case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
- convert32BitRgbx(in_buf, out_buf, size);\r
+ this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8X8_32();\r
break;\r
default:\r
throw new NyARException();\r
}\r
+ }\r
+ public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
+ {\r
+ INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
+ INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+ this._do_filter_impl.doFilter(in_buffer_reader,out_buffer_reader,i_input.getSize());\r
return;\r
}\r
-\r
- private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)\r
+ \r
+ /*\r
+ * ここから各種ラスタ向けのフィルタ実装\r
+ *\r
+ */\r
+ interface IdoThFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size);\r
+ }\r
+ class doThFilterImpl_BYTE1D_B8G8R8_24 implements IdoThFilterImpl\r
{\r
- int bp = 0;\r
- for (int y = 0; y < i_size.h; y++) {\r
- for (int x = 0; x < i_size.w; x++) {\r
- i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;\r
- bp += 3;\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size)\r
+ {\r
+ int[] out_buf = (int[]) i_output.getBuffer();\r
+ byte[] in_buf = (byte[]) i_input.getBuffer();\r
+ \r
+ int bp = 0;\r
+ for (int y = 0; y < i_size.h; y++) {\r
+ for (int x = 0; x < i_size.w; x++) {\r
+ out_buf[y*i_size.w+x] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3;\r
+ bp += 3;\r
+ }\r
}\r
- }\r
- return;\r
+ return;\r
+ } \r
}\r
- private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size)\r
+ class doThFilterImpl_BYTE1D_B8G8R8X8_32 implements IdoThFilterImpl\r
{\r
- int bp = 0;\r
- for (int y = 0; y < i_size.h; y++) {\r
- for (int x = 0; x < i_size.w; x++) {\r
- i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;\r
- bp += 4;\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size)\r
+ {\r
+ int[] out_buf = (int[]) i_output.getBuffer();\r
+ byte[] in_buf = (byte[]) i_input.getBuffer();\r
+\r
+ int bp = 0;\r
+ for (int y = 0; y < i_size.h; y++) {\r
+ for (int x = 0; x < i_size.w; x++) {\r
+ out_buf[y*i_size.w+x] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3;\r
+ bp += 4;\r
+ }\r
}\r
}\r
- return;\r
- } \r
-}
\ No newline at end of file
+ }\r
+ \r
+ \r
+ \r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.types;\r
+\r
+/**\r
+ * 順データ型\r
+ */\r
+public class NyARHistgram\r
+{\r
+ /**\r
+ * サンプリング値の格納変数\r
+ */\r
+ public int[] data;\r
+ /**\r
+ * 有効なサンプリング値の範囲。[0-i_length-1]\r
+ */\r
+ public int length;\r
+ /**\r
+ * 有効なサンプルの総数 data[i]\r
+ */\r
+ public int total_of_data;\r
+ public NyARHistgram(int i_length)\r
+ {\r
+ this.data=new int[i_length];\r
+ this.length=i_length;\r
+ this.total_of_data=0;\r
+ }\r
+ /**\r
+ * 区間i_stからi_edまでの総データ数を返します。\r
+ * @param i_st\r
+ * @param i_ed\r
+ * @return\r
+ */\r
+ public int getTotal(int i_st,int i_ed)\r
+ {\r
+ assert(i_st<i_ed && i_ed<this.length);\r
+ int result=0;\r
+ int[] s=this.data;\r
+ for(int i=i_st;i<=i_ed;i++){\r
+ result+=s[i];\r
+ }\r
+ return result;\r
+ }\r
+}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasteranalyzer;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.types.stack.*;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
-\r
-/**\r
- * QRコードの4頂点候補を探そうとするクラス。\r
- * 未完成\r
- *\r
- */\r
-public class NyARRasterDetector_QrCodeEdge\r
-{\r
- private NyARIntRectStack _result;\r
-\r
- public NyARRasterDetector_QrCodeEdge(int i_result_max)\r
- {\r
- this._result = new NyARIntRectStack(i_result_max);\r
- return;\r
- }\r
-\r
- public NyARIntRectStack geResult()\r
- {\r
- return this._result;\r
- }\r
-\r
- private boolean check_w1(int i_w1)\r
- {\r
- return i_w1>=1; \r
- }\r
- private boolean check_b1(int i_b1)\r
- {\r
- return i_b1 >= 2; \r
- }\r
- private boolean check_w2(int i_b1,int i_w2)\r
- {\r
- int v=i_w2*100/i_b1;\r
- return (30<=v && v<=170);\r
- }\r
- private boolean check_b2(int i_b1,int i_b2)\r
- {\r
- int v=i_b2*100/i_b1;\r
- //条件:(b1)/2の2~4倍\r
- return (200<=v && v<=400);\r
- }\r
- private boolean check_w3(int i_w2,int i_w3)\r
- {\r
- int v=i_w3*100/i_w2;\r
- return (50<=v && v<=150);\r
- }\r
- private boolean check_b3(int i_b3,int i_b1)\r
- {\r
- int v=i_b3*100/i_b1;\r
- return (50<=v && v<=150);\r
- } \r
- public void analyzeRaster(INyARRaster i_input) throws NyARException\r
- {\r
- INyARBufferReader buffer_reader=i_input.getBufferReader();\r
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
-\r
- // 結果をクリア\r
- this._result.clear();\r
-\r
- NyARIntSize size = i_input.getSize();\r
- int x = 0;\r
- int w1, b1, w2, b2, w3, b3;\r
- w1 = b1 = w2 = b2 = w3 = b3 = 0;\r
-\r
- NyARIntRect item;\r
- int[] raster_buf=(int[])buffer_reader.getBuffer();\r
- int line_ptr;\r
- int s_pos, b2_spos,b3_spos;\r
- b2_spos=0;\r
- for (int y = size.h - 1-8; y >= 8; y--) {\r
- line_ptr = y*size.w;\r
- x = size.w - 1;\r
- s_pos=0;\r
- int token_id=0;\r
- while(x>=0){\r
- switch(token_id){\r
- case 0:\r
- // w1の特定\r
- w1 = 0;\r
- for (; x >= 0; x--) {\r
- if (raster_buf[line_ptr+x] == 0) {\r
- // 検出条件確認:w1は2以上欲しいな。\r
- if (!check_w1(w1)) {\r
- // 条件不十分\r
- continue;\r
- }else{\r
- // 検出→次段処理へ\r
- token_id=1;\r
- }\r
- break;\r
- }\r
- w1++;\r
- }\r
- break;\r
- case 1:\r
- // b1の特定\r
- b1 = 0;\r
- s_pos = x;\r
- for (; x >= 0; x--) {\r
- if (raster_buf[line_ptr+x] > 0) {\r
- // 検出条件確認:b1は1以上欲しいな。\r
- if (!check_b1(b1)){\r
- //条件不十分→白検出からやり直し\r
- token_id=0;\r
- }else{\r
- // 検出→次段処理へ\r
- token_id=2;\r
- }\r
- break;\r
- }\r
- b1++;\r
- }\r
- break;\r
- case 2:\r
- // w2の特定\r
- w2 = 0;\r
- for (; x >= 0; x--) {\r
- if (raster_buf[line_ptr+x] == 0) {\r
- // 検出条件確認:w2*10/b1は80-120以上欲しいな。\r
- if (!check_w2(b1,w2)) {\r
- //条件不十分→w2→w1として、b1を解析\r
- w1=w2;\r
- token_id=1;\r
- }else{\r
- // 検出→次段処理へ\r
-// w1=w2;\r
-// token_id=11;\r
- token_id=3;\r
- }\r
- break;\r
- }\r
- w2++;\r
- }\r
- break;\r
- case 3:\r
- // b2の特定\r
- b2 = 0;\r
- b2_spos=x;\r
- for (; x >= 0; x--) {\r
- if (raster_buf[line_ptr+x] > 0){\r
- //条件:(w1+b1)/2の2~4倍\r
-\r
- if (!check_b2(b1,b2)) {\r
- // b2->b1と仮定して解析しなおす。\r
- if(check_w1(w2) && check_b1(b2)){\r
- w1 = w2;\r
- b1 = b2;\r
- s_pos=b2_spos;\r
- token_id=2;\r
- }else{\r
- \r
- token_id=0;\r
- }\r
- }else{\r
- // 検出→次段処理へ\r
-// token_id=10;\r
- token_id=4;\r
- }\r
- break;\r
- }\r
- b2++;\r
- }\r
- break;\r
- case 4:\r
- // w3の特定\r
- w3 = 0;\r
- for (; x >= 0; x--) {\r
- if (raster_buf[line_ptr+x] == 0){\r
- if (!check_w3(w2,w3)) {\r
- //w2→w1,b2->b1として解析しなおす。\r
- if(check_w1(w2) && check_b1(b2)){\r
- w1 = w2;\r
- b1 = b2;\r
- s_pos=b2_spos;\r
- token_id=2;\r
- }else{\r
- token_id=0;\r
- }\r
- }else{\r
- // 検出→次段処理へ\r
-// w1=w3;\r
-// token_id=10;\r
- token_id=5;\r
- }\r
- break;\r
- }\r
- w3++;\r
- }\r
- break;\r
- case 5:\r
- // b3の特定\r
- b3 = 0;\r
- b3_spos=x;\r
- for (; x >= 0; x--) {\r
- if (raster_buf[line_ptr+x] > 0) {\r
- // 検出条件確認\r
- if (!check_b3(b3,b1)) {\r
- if(check_w1(w2) && check_b1(b2)){\r
- //条件不十分→b3->b1,w3->w1として再解析\r
- w1=w3;\r
- b1=b3;\r
- s_pos=b3_spos;\r
- token_id=2;\r
- }else{\r
- token_id=0;\r
- }\r
- }else{\r
- // 検出→次段処理へ\r
- token_id=10;\r
- }\r
- break;\r
- }\r
- b3++;\r
- }\r
- break;\r
- case 10:\r
- /* コード特定→保管 */\r
- item = this._result.prePush();\r
- item.x = x;\r
- item.y = y;\r
- item.w =s_pos-x;\r
- item.h=0;\r
- /* 最大個数? */\r
- /* 次のコードを探す */\r
- token_id=0;\r
- break;\r
- default:\r
- throw new NyARException();\r
- }\r
- }\r
- }\r
- return;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit(Extension)\r
- * --------------------------------------------------------------------------------\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
-/**\r
- * 微分ヒストグラム法による閾値検出\r
- * \r
- */\r
-public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThresholdAnalyzer\r
-{\r
- private int _threshold;\r
-\r
- public NyARRasterThresholdAnalyzer_DiffHistgram()\r
- {\r
- }\r
-\r
- private int createHistgram(int[] in_buf,NyARIntSize i_size, int[] o_histgram) throws NyARException\r
- {\r
- int[][] fil1={\r
- {-1,-2,-1},\r
- { 0, 0, 0},\r
- { 1, 2, 1}};\r
-\r
- // ヒストグラムを作成\r
- for (int i = 0; i < 256; i++) {\r
- o_histgram[i] = 0;\r
- }\r
- int sam;\r
- int sam1,sam2;\r
- for (int y = 1; y < i_size.h-1; y++) {\r
- for (int x = 1; x < i_size.w-1; x++) {\r
- int v = in_buf[y* i_size.w+x];\r
- sam1=sam2=0;\r
- for(int yy=0;yy<3;yy++){\r
- for(int xx=0;xx<3;xx++){\r
- int v2=in_buf[(y+yy-1)* i_size.w+(x+xx-1)];\r
- sam1+=v2*fil1[xx][yy];\r
- sam2+=v2*fil1[yy][xx];\r
- } \r
- }\r
- sam=sam1*sam1+sam2*sam2;\r
- o_histgram[v]+=sam;\r
- }\r
- }\r
- int th=0;\r
- int max=o_histgram[0];\r
- for(int i=1;i<256;i++){\r
- if(max<o_histgram[i]){\r
- th=i;\r
- max=o_histgram[i];\r
- }\r
- }\r
- return th;\r
- }\r
-\r
- public void analyzeRaster(INyARRaster i_input) throws NyARException\r
- {\r
- final INyARBufferReader buffer_reader=i_input.getBufferReader(); \r
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- int[] histgram = new int[256];\r
- this._threshold = createHistgram((int[])buffer_reader.getBuffer(),i_input.getSize(), histgram);\r
- }\r
-\r
- /**\r
- * デバック用の関数です。 ヒストグラムをラスタに書き出します。\r
- * \r
- * @param i_output\r
- * 書き出し先のラスタオブジェクト 256ピクセル以上の幅があること。\r
- */\r
- public void debugDrawHistgramMap(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
- {\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- NyARIntSize size = i_output.getSize();\r
-\r
- int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
- // 0で塗りつぶし\r
- for (int y = 0; y < size.h; y++) {\r
- for (int x = 0; x < size.w; x++) {\r
- out_buf[y* size.w+x] = 0;\r
- }\r
- }\r
- // ヒストグラムを計算\r
- int[] histgram = new int[256];\r
- int threshold = createHistgram((int[])in_buffer_reader.getBuffer(),i_input.getSize(), histgram);\r
-\r
- // ヒストグラムの最大値を出す\r
- int max_v = 0;\r
- for (int i = 0; i < 255; i++) {\r
- if (max_v < histgram[i]) {\r
- max_v = histgram[i];\r
- }\r
- }\r
- // 目盛り\r
- for (int i = 0; i < size.h; i++) {\r
- out_buf[i* size.w+0] = 128;\r
- out_buf[i* size.w+128] = 128;\r
- out_buf[i* size.w+255] = 128;\r
- }\r
- // スケーリングしながら描画\r
- for (int i = 0; i < 255; i++) {\r
- out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255;\r
- }\r
- // 値\r
- for (int i = 0; i < size.h; i++) {\r
- out_buf[i* size.w+threshold] = 255;\r
- }\r
- return;\r
- }\r
-\r
- public int getThreshold()\r
- {\r
- return this._threshold;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit(Extension)\r
- * --------------------------------------------------------------------------------\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
-/**\r
- * Pタイル法による閾値検出\r
- * \r
- */\r
-public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAnalyzer\r
-{\r
- private int _persentage;\r
-\r
- private int _threshold;\r
-\r
- /**\r
- * @param i_persentage\r
- * -100<=0<=100であること。 正の場合、黒点を基準にします。 負の場合、白点を基準にします。\r
- * (CMOSカメラの場合、基準点は白点の方が良い)\r
- */\r
- public NyARRasterThresholdAnalyzer_PTile(int i_persentage)\r
- {\r
- assert (-100 <= i_persentage && i_persentage <= 100);\r
- this._persentage = i_persentage;\r
- }\r
-\r
- private int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram) throws NyARException\r
- {\r
- int[] in_buf = (int[]) i_reader.getBuffer();\r
- int[] histgram = o_histgram;\r
-\r
- // ヒストグラムを作成\r
- for (int i = 0; i < 256; i++) {\r
- histgram[i] = 0;\r
- }\r
- int sum = 0;\r
- for (int y = 0; y < i_size.h; y++) {\r
- int sum2 = 0;\r
- for (int x = 0; x < i_size.w; x++) {\r
- int v = in_buf[y* i_size.w+x];\r
- histgram[v]++;\r
- sum2 += v;\r
- }\r
- sum = sum + sum2 / i_size.w;\r
- }\r
- // 閾値ピクセル数確定\r
- int th_pixcels = i_size.w * i_size.h * this._persentage / 100;\r
-\r
- // 閾値判定\r
- int i;\r
- if (th_pixcels > 0) {\r
- // 黒点基準\r
- for (i = 0; i < 254; i++) {\r
- th_pixcels -= histgram[i];\r
- if (th_pixcels <= 0) {\r
- break;\r
- }\r
- }\r
- } else {\r
- // 白点基準\r
- for (i = 255; i > 1; i--) {\r
- th_pixcels += histgram[i];\r
- if (th_pixcels >= 0) {\r
- break;\r
- }\r
- }\r
- }\r
- // 閾値の保存\r
- return i;\r
- }\r
-\r
- public void analyzeRaster(INyARRaster i_input) throws NyARException\r
- {\r
- final INyARBufferReader buffer_reader=i_input.getBufferReader(); \r
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- int[] histgram = new int[256];\r
- this._threshold = createHistgram(buffer_reader,i_input.getSize(), histgram);\r
- }\r
-\r
- /**\r
- * デバック用の関数です。 ヒストグラムをラスタに書き出します。\r
- * \r
- * @param i_output\r
- * 書き出し先のラスタオブジェクト 256ピクセル以上の幅があること。\r
- */\r
- public void debugDrawHistgramMap(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
- {\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- NyARIntSize size = i_output.getSize();\r
-\r
- int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
- // 0で塗りつぶし\r
- for (int y = 0; y < size.h; y++) {\r
- for (int x = 0; x < size.w; x++) {\r
- out_buf[y* size.w+x] = 0;\r
- }\r
- }\r
- // ヒストグラムを計算\r
- int[] histgram = new int[256];\r
- int threshold = createHistgram(in_buffer_reader,i_input.getSize(), histgram);\r
-\r
- // ヒストグラムの最大値を出す\r
- int max_v = 0;\r
- for (int i = 0; i < 255; i++) {\r
- if (max_v < histgram[i]) {\r
- max_v = histgram[i];\r
- }\r
- }\r
- // 目盛り\r
- for (int i = 0; i < size.h; i++) {\r
- out_buf[i* size.w+0] = 128;\r
- out_buf[i* size.w+128] = 128;\r
- out_buf[i* size.w+255] = 128;\r
- }\r
- // スケーリングしながら描画\r
- for (int i = 0; i < 255; i++) {\r
- out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255;\r
- }\r
- // 値\r
- for (int i = 0; i < size.h; i++) {\r
- out_buf[i* size.w+threshold] = 255;\r
- }\r
- return;\r
- }\r
-\r
- public int getThreshold()\r
- {\r
- return this._threshold;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit(Extension)\r
- * --------------------------------------------------------------------------------\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
-\r
-/**\r
- * 明点と暗点をPタイル法で検出して、その中央値を閾値とする。\r
- * \r
- * \r
- */\r
-public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresholdAnalyzer\r
-{\r
- interface ICreateHistgramImpl{\r
- public int createHistgramImpl(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram);\r
- }\r
- /**\r
- * Glayscale(MAX256)のヒストグラム計算クラス\r
- */\r
- final class CreateHistgramImpl_INT1D_GRAY_8 implements ICreateHistgramImpl\r
- {\r
- public int _v_interval;\r
- public CreateHistgramImpl_INT1D_GRAY_8(int i_v_interval)\r
- {\r
- this._v_interval=i_v_interval;\r
- return;\r
- }\r
- public int createHistgramImpl(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram)\r
- {\r
- assert (i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
-\r
- int sum=0;\r
- final int[] input=(int[]) i_reader.getBuffer();\r
- for (int y = i_size.h-1; y >=0 ; y-=this._v_interval){\r
- sum+=i_size.w;\r
- int pt=y*i_size.w;\r
- for (int x = i_size.w-1; x >=0; x--) {\r
- o_histgram[input[pt]]++;\r
- pt++;\r
- }\r
- }\r
- return sum;\r
- }\r
- }\r
- /**\r
- * RGB24bitのヒストグラム計算クラス\r
- *\r
- */\r
- final class CreateHistgramImpl_BYTE1D_RGB_24 implements ICreateHistgramImpl\r
- {\r
- private int _v_interval;\r
- public CreateHistgramImpl_BYTE1D_RGB_24(int i_v_interval)\r
- {\r
- this._v_interval=i_v_interval;\r
- return;\r
- }\r
- public int createHistgramImpl(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram)\r
- {\r
- assert (\r
- i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24)||\r
- i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24));\r
- \r
- final byte[] input=(byte[]) i_reader.getBuffer();\r
- final int pix_count=i_size.w;\r
- final int pix_mod_part=pix_count-(pix_count%8);\r
- int sum=0;\r
- for (int y = i_size.h-1; y >=0 ; y-=this._v_interval) {\r
- sum+=i_size.w;\r
- int pt=y*i_size.w*3;\r
- int x,v;\r
- for (x = pix_count-1; x >=pix_mod_part; x--) {\r
- v=((input[pt+0]& 0xff)+(input[pt+1]& 0xff)+(input[pt+2]& 0xff))/3;\r
- o_histgram[v]++;\r
- pt+=3;\r
- }\r
- //タイリング\r
- for (;x>=0;x-=8){\r
- v=((input[pt+ 0]& 0xff)+(input[pt+ 1]& 0xff)+(input[pt+ 2]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+ 3]& 0xff)+(input[pt+ 4]& 0xff)+(input[pt+ 5]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+ 6]& 0xff)+(input[pt+ 7]& 0xff)+(input[pt+ 8]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+ 9]& 0xff)+(input[pt+10]& 0xff)+(input[pt+11]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+12]& 0xff)+(input[pt+13]& 0xff)+(input[pt+14]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+15]& 0xff)+(input[pt+16]& 0xff)+(input[pt+17]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+18]& 0xff)+(input[pt+19]& 0xff)+(input[pt+20]& 0xff))/3;\r
- o_histgram[v]++;\r
- v=((input[pt+21]& 0xff)+(input[pt+22]& 0xff)+(input[pt+23]& 0xff))/3;\r
- o_histgram[v]++;\r
- pt+=3*8;\r
- }\r
- }\r
- return sum; \r
- }\r
- }\r
- /**\r
- * BYTE1D_B8G8R8X8_32のヒストグラム計算クラス\r
- *\r
- */ \r
- final class CreateHistgramImpl_BYTE1D_B8G8R8X8_32 implements ICreateHistgramImpl\r
- {\r
- private int _v_interval;\r
- public CreateHistgramImpl_BYTE1D_B8G8R8X8_32(int i_v_interval)\r
- {\r
- this._v_interval = i_v_interval;\r
- return;\r
- }\r
- public int createHistgramImpl(INyARBufferReader i_reader, NyARIntSize i_size, int[] o_histgram)\r
- {\r
- assert(i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32));\r
- byte[] input = (byte[])i_reader.getBuffer();\r
- int pix_count = i_size.w;\r
- int pix_mod_part = pix_count - (pix_count % 8);\r
- int sum = 0;\r
- for (int y = i_size.h - 1; y >= 0; y -= this._v_interval)\r
- {\r
- sum += i_size.w;\r
- int pt = y * i_size.w * 4;\r
- int x, v;\r
- for (x = pix_count - 1; x >= pix_mod_part; x--)\r
- {\r
- v = ((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- pt += 4;\r
- }\r
- //タイリング\r
- for (; x >= 0; x -= 8)\r
- {\r
- v = ((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 4] & 0xff) + (input[pt + 5] & 0xff) + (input[pt + 6] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 8] & 0xff) + (input[pt + 9] & 0xff) + (input[pt + 10] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 12] & 0xff) + (input[pt + 13] & 0xff) + (input[pt + 14] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 16] & 0xff) + (input[pt + 17] & 0xff) + (input[pt + 18] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 20] & 0xff) + (input[pt + 21] & 0xff) + (input[pt + 22] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 24] & 0xff) + (input[pt + 25] & 0xff) + (input[pt + 26] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 28] & 0xff) + (input[pt + 29] & 0xff) + (input[pt + 30] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- pt += 4 * 8;\r
- }\r
- }\r
- return sum;\r
- }\r
- } \r
- /**\r
- * BYTE1D_X8R8G8B8_32のヒストグラム計算クラス\r
- *\r
- */ \r
- final class CreateHistgramImpl_BYTE1D_X8R8G8B8_32 implements ICreateHistgramImpl\r
- {\r
- private int _v_interval;\r
- public CreateHistgramImpl_BYTE1D_X8R8G8B8_32(int i_v_interval)\r
- {\r
- this._v_interval = i_v_interval;\r
- return;\r
- }\r
- public int createHistgramImpl(INyARBufferReader i_reader, NyARIntSize i_size, int[] o_histgram)\r
- {\r
- assert(i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32));\r
- byte[] input = (byte[])i_reader.getBuffer();\r
- int pix_count = i_size.w;\r
- int pix_mod_part = pix_count - (pix_count % 8);\r
- int sum = 0;\r
- for (int y = i_size.h - 1; y >= 0; y -= this._v_interval)\r
- {\r
- sum += i_size.w;\r
- int pt = y * i_size.w * 4;\r
- int x, v;\r
- for (x = pix_count - 1; x >= pix_mod_part; x--)\r
- {\r
- v = ((input[pt + 1] & 0xff) + (input[pt + 2] & 0xff) + (input[pt + 3] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- pt += 4;\r
- }\r
- //タイリング\r
- for (; x >= 0; x -= 8)\r
- {\r
- v = ((input[pt + 1] & 0xff) + (input[pt + 2] & 0xff) + (input[pt + 3] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 5] & 0xff) + (input[pt + 6] & 0xff) + (input[pt + 7] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 9] & 0xff) + (input[pt + 10] & 0xff) + (input[pt + 11] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 13] & 0xff) + (input[pt + 14] & 0xff) + (input[pt + 15] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 17] & 0xff) + (input[pt + 18] & 0xff) + (input[pt + 19] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 21] & 0xff) + (input[pt + 22] & 0xff) + (input[pt + 23] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 25] & 0xff) + (input[pt + 26] & 0xff) + (input[pt + 27] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- v = ((input[pt + 29] & 0xff) + (input[pt + 30] & 0xff) + (input[pt + 31] & 0xff)) / 3;\r
- o_histgram[v]++;\r
- pt += 4 * 8;\r
- }\r
- }\r
- return sum;\r
- }\r
- }\r
- \r
- /**\r
- * WORD1D_R5G6B5_16LEのヒストグラム計算クラス\r
- *\r
- */ \r
- final class CreateHistgramImpl_WORD1D_R5G6B5_16LE implements ICreateHistgramImpl\r
- {\r
- private int _v_interval;\r
- public CreateHistgramImpl_WORD1D_R5G6B5_16LE(int i_v_interval)\r
- {\r
- this._v_interval = i_v_interval;\r
- return;\r
- }\r
- public int createHistgramImpl(INyARBufferReader i_reader, NyARIntSize i_size, int[] o_histgram)\r
- {\r
- assert(i_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE));\r
- short[] input = (short[])i_reader.getBuffer();\r
- int pix_count = i_size.w;\r
- int pix_mod_part = pix_count - (pix_count % 8);\r
- int sum = 0;\r
- for (int y = i_size.h - 1; y >= 0; y -= this._v_interval)\r
- {\r
- sum += i_size.w;\r
- int pt = y * i_size.w;\r
- int x, v;\r
- for (x = pix_count - 1; x >= pix_mod_part; x--)\r
- {\r
- v =(int)input[pt];\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- pt++;\r
- }\r
- //タイリング\r
- for (; x >= 0; x -= 8)\r
- {\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- v =(int)input[pt];pt++;\r
- v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;\r
- o_histgram[v]++;\r
- }\r
- }\r
- return sum;\r
- }\r
- }\r
-\r
- \r
- \r
- \r
-\r
- private int _persentage;\r
- private int _threshold;\r
- private ICreateHistgramImpl _histgram;\r
- \r
- /**\r
- * @param i_persentage\r
- * 0<=50であること。白/黒マーカーの場合は10~20を推奨 正の場合、黒点を基準にします。 負の場合、白点を基準にします。\r
- * (CMOSカメラの場合、基準点は白点の方が良い)\r
- */\r
- public NyARRasterThresholdAnalyzer_SlidePTile(int i_persentage,int i_raster_format,int i_vertical_interval) throws NyARException\r
- {\r
- assert (0 <= i_persentage && i_persentage <= 50);\r
- this._persentage = i_persentage;\r
- switch (i_raster_format)\r
- {\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
- this._histgram = new CreateHistgramImpl_BYTE1D_RGB_24(i_vertical_interval);\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
- this._histgram = new CreateHistgramImpl_INT1D_GRAY_8(i_vertical_interval);\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
- this._histgram = new CreateHistgramImpl_BYTE1D_B8G8R8X8_32(i_vertical_interval);\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:\r
- this._histgram = new CreateHistgramImpl_BYTE1D_X8R8G8B8_32(i_vertical_interval);\r
- break;\r
- case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:\r
- this._histgram=new CreateHistgramImpl_WORD1D_R5G6B5_16LE(i_vertical_interval);\r
- break;\r
- default:\r
- throw new NyARException();\r
- }\r
- }\r
- public void setVerticalInterval(int i_step)\r
- {\r
- return;//未実装一号\r
- }\r
-\r
- private int[] _histgram_buf=new int[256];\r
- public void analyzeRaster(INyARRaster i_input) throws NyARException\r
- {\r
- final int[] histgram = this._histgram_buf;\r
- final NyARIntSize size=i_input.getSize();\r
- \r
- //最大画像サイズの制限\r
- assert size.w*size.h<0x40000000;\r
-\r
- //ヒストグラム初期化\r
- for (int i = 0; i < 256; i++) {\r
- histgram[i] = 0;\r
- }\r
- int sum_of_pixel=this._histgram.createHistgramImpl(i_input.getBufferReader(), size, histgram);\r
-\r
- // 閾値ピクセル数確定\r
- final int th_pixcels = sum_of_pixel * this._persentage / 100;\r
- int th_wk;\r
- int th_w, th_b;\r
-\r
- // 黒点基準\r
- th_wk = th_pixcels;\r
- for (th_b = 0; th_b < 254; th_b++) {\r
- th_wk -= histgram[th_b];\r
- if (th_wk <= 0) {\r
- break;\r
- }\r
- }\r
- // 白点基準\r
- th_wk = th_pixcels;\r
- for (th_w = 255; th_w > 1; th_w--) {\r
- th_wk -= histgram[th_w];\r
- if (th_wk <= 0) {\r
- break;\r
- }\r
- }\r
- // 閾値の保存\r
- this._threshold = (th_w + th_b) / 2;\r
- return;\r
- }\r
- public int getThreshold()\r
- {\r
- return this._threshold;\r
- }\r
-\r
- public int getThreshold(int i_x, int i_y)\r
- {\r
- return this._threshold;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasterfilter;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
-\r
-/**\r
- * エッジ検出フィルタ 入力 BUFFERFORMAT_INT2D 出力 BUFFERFORMAT_INT2D\r
- */\r
-public class NyARRasterFilter_Edge implements INyARRasterFilter\r
-{\r
- public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
- {\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
-\r
- int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
- int[] in_buf = (int[]) in_buffer_reader.getBuffer();\r
-\r
- int bp = 0;\r
- NyARIntSize size = i_output.getSize();\r
- for (int y = 1; y < size.h; y++) {\r
- int prev = 128;\r
- for (int x = 1; x < size.w; x++) {\r
- int w = in_buf[y* size.w+x];\r
- out_buf[y* size.w+x] = (Math.abs(w - prev) + Math.abs(w - in_buf[(y - 1)* size.w+x])) / 2;\r
- prev = w;\r
- bp += 3;\r
- }\r
- }\r
- return;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_GsToBin;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
-/**\r
- * 平均移動法を使った2値化フィルタ\r
- * \r
- */\r
-public class NyARRasterFilter_AreaAverage implements INyARRasterFilter_GsToBin\r
-{\r
- private int _area = 8;\r
-\r
- public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
- {\r
- final NyARIntSize size = i_output.getSize();\r
- final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();\r
- final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();\r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
- assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。\r
-\r
- final int area = this._area;\r
- int y1 = area;\r
- int x1 = area;\r
- int y2 = size.h - area;\r
- int x2 = size.w - area;\r
-\r
- for (int y = y1; y < y2; y++) {\r
- int sum, nn;\r
- sum = nn = 0;\r
- for (int yy = y - area; yy < y + area + 1; yy++) {\r
- for (int xx = x1 - area; xx < x1 + area; xx++) {\r
- sum += in_buf[yy*size.w+xx];\r
- nn++;\r
- }\r
- }\r
- boolean first = true;\r
- for (int x = area; x < x2; x++) {\r
- if (!first) {\r
- for (int yy = y - area; yy < y + area; yy++) {\r
- sum += in_buf[yy*size.w+x + area];\r
- sum -= in_buf[yy*size.w+x - area];\r
- }\r
- }\r
- first = false;\r
- int th = (sum / nn);\r
-\r
- int g = in_buf[y*size.w+x];\r
- out_buf[y*size.w+x] = th < g ? 1 : 0;\r
- }\r
- }\r
- return;\r
- }\r
-\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_GsToBin;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
-/**\r
- * 定数閾値による2値化をする。\r
- * \r
- */\r
-public class NyARRasterFilter_Threshold implements INyARRasterFilter_GsToBin\r
-{\r
- private int _threshold;\r
-\r
- public NyARRasterFilter_Threshold(int i_threshold)\r
- {\r
- this._threshold = i_threshold;\r
- return;\r
- }\r
-\r
- public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
- {\r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
-\r
- final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();\r
- final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();\r
-\r
- int bp = 0;\r
- NyARIntSize size = i_output.getSize();\r
- for (int y = 0; y < size.h - 1; y++) {\r
- for (int x = 0; x < size.w; x++) {\r
- out_buf[y*size.w+x] = in_buf[y*size.w+x] >= this._threshold ? 1 : 0;\r
- bp += 3;\r
- }\r
- }\r
- return;\r
- }\r
- public void setThreshold(int i_threshold)\r
- {\r
- this._threshold = i_threshold;\r
- return; \r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_RgbToGs;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
-\r
-public class NyARRasterFilter_RgbMul implements INyARRasterFilter_RgbToGs\r
-{\r
- public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
- {\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
-\r
- int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
- byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();\r
-\r
- NyARIntSize size = i_output.getSize();\r
- switch (in_buffer_reader.getBufferType()) {\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
- convert24BitRgb(in_buf, out_buf, size);\r
- break;\r
- default:\r
- throw new NyARException();\r
- }\r
- return;\r
- }\r
-\r
- private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)\r
- {\r
- int bp = 0;\r
- for (int y = 0; y < i_size.h; y++) {\r
- for (int x = 0; x < i_size.w; x++) {\r
- i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) * (i_in[bp + 1] & 0xff) * (i_in[bp + 2] & 0xff)) >> 16;\r
- bp += 3;\r
- }\r
- }\r
- return;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_RgbToGs;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
-\r
-public class NyARRasterFilter_RgbOr implements INyARRasterFilter_RgbToGs\r
-{\r
- public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
- {\r
- INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
- INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
-\r
- final int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
- final byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();\r
-\r
- NyARIntSize size = i_output.getSize();\r
- switch (in_buffer_reader.getBufferType()) {\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
- convert24BitRgb(in_buf, out_buf, size);\r
- break;\r
- default:\r
- throw new NyARException();\r
- }\r
- return;\r
- }\r
-\r
- private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)\r
- {\r
- int bp = 0;\r
- for (int y = 0; y < i_size.h; y++) {\r
- for (int x = 0; x < i_size.w; x++) {\r
- i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) | (i_in[bp + 1] & 0xff) | (i_in[bp + 2] & 0xff));\r
- bp += 3;\r
- }\r
- }\r
- return;\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-\r
-package jp.nyatla.nyartoolkit.core2.types;\r
-\r
-public class NyARFixedFloat16Point2d extends NyARI64Point2d\r
-{\r
- public static NyARFixedFloat16Point2d[] createArray(int i_number)\r
- {\r
- NyARFixedFloat16Point2d[] ret=new NyARFixedFloat16Point2d[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARFixedFloat16Point2d();\r
- }\r
- return ret;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types;\r
-\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
-public class NyARFixedFloat16Point3d extends NyARI64Point3d\r
-{\r
- /**\r
- * 配列ファクトリ\r
- * @param i_number\r
- * @return\r
- */\r
- public static NyARFixedFloat16Point3d[] createArray(int i_number)\r
- {\r
- NyARFixedFloat16Point3d[] ret=new NyARFixedFloat16Point3d[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARFixedFloat16Point3d();\r
- }\r
- return ret;\r
- }\r
- public void copyTo(NyARDoublePoint3d i_to)\r
- {\r
- i_to.x=(double)this.x/0x10000;\r
- i_to.y=(double)this.y/0x10000;\r
- i_to.z=(double)this.z/0x10000;\r
- return;\r
- }\r
- public void copyFrom(NyARDoublePoint3d i_from)\r
- {\r
- this.x=(long)(i_from.x*0x10000);\r
- this.y=(long)(i_from.y*0x10000);\r
- this.z=(long)(i_from.z*0x10000);\r
- return;\r
- }\r
-\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types;\r
-\r
-public class NyARI64Linear\r
-{\r
- public long rise;//y軸の増加量\r
- public long run;//x軸の増加量\r
- public long intercept;//切片\r
- public final void copyFrom(NyARI64Linear i_source)\r
- {\r
- this.rise=i_source.rise;\r
- this.run=i_source.run;\r
- this.intercept=i_source.intercept;\r
- return;\r
- }\r
- public static NyARI64Linear[] createArray(int i_number)\r
- {\r
- NyARI64Linear[] ret=new NyARI64Linear[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARI64Linear();\r
- }\r
- return ret;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types;\r
-\r
-public class NyARI64Point2d\r
-{\r
- public long x;\r
-\r
- public long y;\r
- /**\r
- * 配列ファクトリ\r
- * @param i_number\r
- * @return\r
- */\r
- public static NyARI64Point2d[] createArray(int i_number)\r
- {\r
- NyARI64Point2d[] ret=new NyARI64Point2d[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARI64Point2d();\r
- }\r
- return ret;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types;\r
-\r
-public class NyARI64Point3d\r
-{\r
- public long x;\r
- public long y;\r
- public long z;\r
- /**\r
- * 配列ファクトリ\r
- * @param i_number\r
- * @return\r
- */\r
- public static NyARI64Point3d[] createArray(int i_number)\r
- {\r
- NyARI64Point3d[] ret=new NyARI64Point3d[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARI64Point3d();\r
- }\r
- return ret;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types.matrix;\r
-\r
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;\r
-\r
-\r
-public class NyARFixedFloat16Matrix33 extends NyARI64Matrix33\r
-{\r
- public void copyFrom(NyARDoubleMatrix33 i_matrix)\r
- {\r
- this.m00=(long)i_matrix.m00*0x10000;\r
- this.m01=(long)i_matrix.m01*0x10000;\r
- this.m02=(long)i_matrix.m02*0x10000;\r
- this.m10=(long)i_matrix.m10*0x10000;\r
- this.m11=(long)i_matrix.m11*0x10000;\r
- this.m12=(long)i_matrix.m12*0x10000;\r
- this.m20=(long)i_matrix.m20*0x10000;\r
- this.m21=(long)i_matrix.m21*0x10000;\r
- this.m22=(long)i_matrix.m22*0x10000;\r
- return;\r
- }\r
- public static NyARFixedFloat16Matrix33[] createArray(int i_number)\r
- {\r
- NyARFixedFloat16Matrix33[] ret=new NyARFixedFloat16Matrix33[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARFixedFloat16Matrix33();\r
- }\r
- return ret;\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types.matrix;\r
-\r
-import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
-\r
-\r
-public class NyARFixedFloat24Matrix33 extends NyARI64Matrix33\r
-{\r
- public void copyFrom(NyARDoubleMatrix33 i_matrix)\r
- {\r
- this.m00=(long)i_matrix.m00*0x1000000;\r
- this.m01=(long)i_matrix.m01*0x1000000;\r
- this.m02=(long)i_matrix.m02*0x1000000;\r
- this.m10=(long)i_matrix.m10*0x1000000;\r
- this.m11=(long)i_matrix.m11*0x1000000;\r
- this.m12=(long)i_matrix.m12*0x1000000;\r
- this.m20=(long)i_matrix.m20*0x1000000;\r
- this.m21=(long)i_matrix.m21*0x1000000;\r
- this.m22=(long)i_matrix.m22*0x1000000;\r
- return;\r
- }\r
- public void copyTo(NyARDoubleMatrix33 i_to)\r
- {\r
- i_to.m00=(double)this.m00/0x1000000;\r
- i_to.m01=(double)this.m01/0x1000000;\r
- i_to.m02=(double)this.m02/0x1000000;\r
- i_to.m10=(double)this.m10/0x1000000;\r
- i_to.m11=(double)this.m11/0x1000000;\r
- i_to.m12=(double)this.m12/0x1000000;\r
- i_to.m20=(double)this.m20/0x1000000;\r
- i_to.m21=(double)this.m21/0x1000000;\r
- i_to.m22=(double)this.m22/0x1000000;\r
- return;\r
- }\r
- \r
- public static NyARFixedFloat24Matrix33[] createArray(int i_number)\r
- {\r
- NyARFixedFloat24Matrix33[] ret=new NyARFixedFloat24Matrix33[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARFixedFloat24Matrix33();\r
- }\r
- return ret;\r
- }\r
-\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types.matrix;\r
-\r
-public class NyARI64Matrix22\r
-{\r
- public long m00;\r
- public long m01;\r
- public long m10;\r
- public long m11;\r
-}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java edition ARToolKit class library.\r
- * Copyright (C)2008-2009 Ryo Iizuka\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core2.types.matrix;\r
-\r
-\r
-public class NyARI64Matrix33\r
-{\r
- public long m00;\r
- public long m01;\r
- public long m02;\r
- public long m10;\r
- public long m11;\r
- public long m12;\r
- public long m20;\r
- public long m21;\r
- public long m22;\r
- public static NyARI64Matrix33[] createArray(int i_number)\r
- {\r
- NyARI64Matrix33[] ret=new NyARI64Matrix33[i_number];\r
- for(int i=0;i<i_number;i++)\r
- {\r
- ret[i]=new NyARI64Matrix33();\r
- }\r
- return ret;\r
- }\r
-}\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.analyzer.raster.threshold.*;\r
import jp.nyatla.nyartoolkit.core.match.*;\r
import jp.nyatla.nyartoolkit.core.param.*;\r
import jp.nyatla.nyartoolkit.core.pickup.*;\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
import jp.nyatla.nyartoolkit.core.transmat.*;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
import jp.nyatla.nyartoolkit.core.squaredetect.*;\r
-import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.NyARRasterThresholdAnalyzer_SlidePTile;\r
\r
/**\r
* このクラスは、同時に1個のマーカを処理することのできる、アプリケーションプロセッサです。\r
//閾値フィードバック(detectExistMarkerにもあるよ)\r
if(!is_id_found){\r
//マーカがなければ、探索+DualPTailで基準輝度検索\r
- this._threshold_detect.analyzeRaster(i_raster);\r
- this._threshold=(this._threshold+this._threshold_detect.getThreshold())/2;\r
+ int th=this._threshold_detect.analyzeRaster(i_raster);\r
+ this._threshold=(this._threshold+th)/2;\r
}\r
}\r
\r
//閾値フィードバック(detectExistMarkerにもあるよ)\r
if(!is_id_found){\r
//マーカがなければ、探索+DualPTailで基準輝度検索\r
- this._threshold_detect.analyzeRaster(i_raster);\r
- this._threshold=(this._threshold+this._threshold_detect.getThreshold())/2;\r
+ int th=this._threshold_detect.analyzeRaster(i_raster);\r
+ this._threshold=(this._threshold+th)/2;\r
}\r
\r
}\r
package jp.nyatla.nyartoolkit.processor;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.analyzer.raster.threshold.*;\r
import jp.nyatla.nyartoolkit.core.param.*;\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
import jp.nyatla.nyartoolkit.core.transmat.*;\r
-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
import jp.nyatla.nyartoolkit.nyidmarker.*;\r
import jp.nyatla.nyartoolkit.nyidmarker.data.*;\r
-import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;\r
import jp.nyatla.nyartoolkit.core.squaredetect.*;\r
\r
public abstract class SingleNyIdMarkerProcesser\r
this._is_active=false;\r
this._data_temp=i_encoder.createDataInstance();\r
this._data_current=i_encoder.createDataInstance();\r
- this._tobin_filter = new NyARRasterFilter_ARToolkitThreshold(110,i_raster_format);\r
+ this._tobin_filter =new NyARRasterFilter_ARToolkitThreshold(110,i_raster_format);\r
this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_format,4);\r
this._initialized=true;\r
return;\r
this._current_threshold=(this._current_threshold+param.threshold)/2;\r
}else{\r
//マーカがなければ、探索+DualPTailで基準輝度検索\r
- this._threshold_detect.analyzeRaster(i_raster);\r
- this._current_threshold=(this._current_threshold+this._threshold_detect.getThreshold())/2;\r
+ int th=this._threshold_detect.analyzeRaster(i_raster);\r
+ this._current_threshold=(this._current_threshold+th)/2;\r
}\r
return;\r
}\r
this._current_threshold=(this._current_threshold+param.threshold)/2;\r
}else{\r
//マーカがなければ、探索+DualPTailで基準輝度検索\r
- this._threshold_detect.analyzeRaster(i_raster);\r
- this._current_threshold=(this._current_threshold+this._threshold_detect.getThreshold())/2;\r
+ int th=this._threshold_detect.analyzeRaster(i_raster);\r
+ this._current_threshold=(this._current_threshold+th)/2;\r
}\r
return;\r
}\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
\r
+/**\r
+ * BufferdImageとRasterイメージ間で、ビットマップをコピーします。\r
+ */\r
public class NyARRasterImageIO\r
{\r
/**\r
return;\r
}\r
/**\r
+ * GrayScale用\r
+ * @param i_in\r
+ * @throws NyARException\r
+ */\r
+ public static void copy(NyARGrayscaleRaster i_in,BufferedImage o_out) throws NyARException\r
+ {\r
+ assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());\r
+ if(i_in.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8))\r
+ {\r
+ final int[] buf=(int[])i_in.getBufferReader().getBuffer();\r
+ final int w=o_out.getWidth();\r
+ final int h=o_out.getHeight();\r
+ for(int y=h-1;y>=0;y--){\r
+ for(int x=w-1;x>=0;x--){\r
+ int v=buf[x+y*w];\r
+ o_out.setRGB(x, y,v*(1+0x100+0x10000));\r
+ }\r
+ }\r
+ }\r
+ return;\r
+ } \r
+ /**\r
* BIN_8用\r
* @param i_in\r
* @throws NyARException\r