\r
import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
/**\r
- * 歪み成分マップを使用するINyARCameraDistortionFactor\r
+ * 歪み矯正した座標系を格納したクラスです。\r
+ * 2次元ラスタを1次元配列で表現します。\r
+ *\r
*/\r
-final public class NyARObserv2IdealMap\r
+public class NyARObserv2IdealMap\r
{\r
- private int _stride;\r
- private double[] _mapx;\r
- private double[] _mapy;\r
+ protected int _stride;\r
+ protected double[] _mapx;\r
+ protected double[] _mapy;\r
public NyARObserv2IdealMap(NyARCameraDistortionFactor i_distfactor,NyARIntSize i_screen_size)\r
{\r
NyARDoublePoint2d opoint=new NyARDoublePoint2d();\r
}\r
return;\r
}\r
- public void observ2Ideal(double ix, double iy, NyARDoublePoint2d o_point)\r
+ public void observ2Ideal(int ix, int iy, NyARDoublePoint2d o_point)\r
{\r
- int idx=(int)ix+(int)iy*this._stride;\r
+ int idx=ix+iy*this._stride;\r
o_point.x=this._mapx[idx];\r
o_point.y=this._mapy[idx];\r
return;\r
{\r
int idx;\r
int ptr=i_out_start_index;\r
- for (int j = 0; j < i_num; j++) {\r
- idx=i_x_coord[i_start + j]+i_y_coord[i_start + j]*this._stride;\r
- o_x_coord[ptr]=this._mapx[idx];\r
- o_y_coord[ptr]=this._mapy[idx];\r
+ final double[] mapx=this._mapx;\r
+ final double[] mapy=this._mapy;\r
+ final int stride=this._stride;\r
+ for (int j = 0; j < i_num; j++){\r
+ idx=i_x_coord[i_start + j]+i_y_coord[i_start + j]*stride;\r
+ o_x_coord[ptr]=mapx[idx];\r
+ o_y_coord[ptr]=mapy[idx];\r
ptr++;\r
}\r
return;\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.core.rasterfilter;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
+\r
+\r
+/**\r
+ * ネガポジ反転フィルタ。\r
+ * 画像の明暗を反転します。\r
+ *\r
+ */\r
+public class NyARRasterFilter_Reverse implements INyARRasterFilter\r
+{\r
+ private IdoFilterImpl _do_filter_impl; \r
+ public NyARRasterFilter_Reverse(int i_raster_type) throws NyARException\r
+ {\r
+ switch (i_raster_type) {\r
+ case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+ this._do_filter_impl=new IdoFilterImpl_GRAY_8();\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ }\r
+ public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
+ {\r
+ this._do_filter_impl.doFilter(i_input.getBufferReader(),i_output.getBufferReader(),i_input.getSize());\r
+ }\r
+ \r
+ interface IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException;\r
+ }\r
+ class IdoFilterImpl_GRAY_8 implements IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
+ {\r
+ assert (i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ int[] in_ptr =(int[])i_input.getBuffer();\r
+ int[] out_ptr=(int[])i_output.getBuffer();\r
+\r
+ \r
+ int number_of_pixel=i_size.h*i_size.w;\r
+ for(int i=0;i<number_of_pixel;i++){\r
+ out_ptr[i]=255-in_ptr[i];\r
+ }\r
+ return;\r
+ }\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.core.rasterfilter;\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.NyARIntSize;\r
+\r
+/**\r
+ * Roberts法で勾配を計算します。\r
+ * 出力画像のピクセルは、X,Y軸方向に-1され、下端、右端の画素は無効な値が入ります。\r
+ * X=|-1, 0| Y=|0,-1|\r
+ * | 0, 1| |1, 0|\r
+ * V=sqrt(X^2+Y+2)/2\r
+ */\r
+public class NyARRasterFilter_Roberts implements INyARRasterFilter\r
+{\r
+ private IdoFilterImpl _do_filter_impl; \r
+ public NyARRasterFilter_Roberts(int i_raster_type) throws NyARException\r
+ {\r
+ switch (i_raster_type) {\r
+ case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+ this._do_filter_impl=new IdoFilterImpl_GRAY_8();\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ }\r
+ public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
+ {\r
+ this._do_filter_impl.doFilter(i_input.getBufferReader(),i_output.getBufferReader(),i_input.getSize());\r
+ }\r
+ \r
+ interface IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException;\r
+ }\r
+ class IdoFilterImpl_GRAY_8 implements IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
+ {\r
+ assert (i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ int[] in_ptr =(int[])i_input.getBuffer();\r
+ int[] out_ptr=(int[])i_output.getBuffer();\r
+ int width=i_size.w;\r
+ int height=i_size.h;\r
+ for(int y=0;y<height-1;y++){\r
+ int idx=y*width;\r
+ int p00=in_ptr[idx];\r
+ int p10=in_ptr[width+idx];\r
+ int p01,p11;\r
+ for(int x=0;x<width-1;x++){\r
+ p01=in_ptr[idx+1];\r
+ p11=in_ptr[idx+width+1];\r
+ int fx=p11-p00;\r
+ int fy=p10-p01;\r
+ out_ptr[idx]=(int)Math.sqrt(fx*fx+fy*fy)>>1;\r
+ p00=p01;\r
+ p10=p11;\r
+ idx++;\r
+ }\r
+ }\r
+ return;\r
+ }\r
+ }\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.core.rasterfilter;\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.NyARIntSize;\r
+\r
+\r
+/**\r
+ * 平滑化フィルタ\r
+ * 画像を平滑化します。\r
+ * カーネルサイズは3x3です。\r
+ */\r
+public class NyARRasterFilter_SimpleSmooth implements INyARRasterFilter\r
+{\r
+ private IdoFilterImpl _do_filter_impl; \r
+ public NyARRasterFilter_SimpleSmooth(int i_raster_type) throws NyARException\r
+ {\r
+ switch (i_raster_type) {\r
+ case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+ this._do_filter_impl=new IdoFilterImpl_GRAY_8();\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ }\r
+ public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
+ {\r
+ assert (i_input!=i_output);\r
+ this._do_filter_impl.doFilter(i_input.getBufferReader(),i_output.getBufferReader(),i_input.getSize());\r
+ }\r
+ \r
+ interface IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException;\r
+ }\r
+ class IdoFilterImpl_GRAY_8 implements IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
+ {\r
+ assert (i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+ int[] in_ptr =(int[])i_input.getBuffer();\r
+ int[] out_ptr=(int[])i_output.getBuffer();\r
+ /* 画像端は捨てる。\r
+ */\r
+ int width=i_size.w;\r
+ int height=i_size.h;\r
+ int col0,col1,col2;\r
+ int bptr=0;\r
+ //1行目\r
+ col1=in_ptr[bptr ]+in_ptr[bptr+width ];\r
+ col2=in_ptr[bptr+1]+in_ptr[bptr+width+1];\r
+ out_ptr[bptr]=(col1+col2)/4;\r
+ bptr++;\r
+ for(int x=0;x<width-2;x++){\r
+ col0=col1;\r
+ col1=col2;\r
+ col2=in_ptr[bptr+1]+in_ptr[bptr+width+1];\r
+ out_ptr[bptr]=(col0+col1+col2)/6;\r
+ bptr++;\r
+ } \r
+ out_ptr[bptr]=(col1+col2)/4;\r
+ bptr++;\r
+ //2行目-末行-1\r
+\r
+ for(int y=0;y<height-2;y++){\r
+ //左端\r
+ col1=in_ptr[bptr ]+in_ptr[bptr-width ]+in_ptr[bptr+width ];\r
+ col2=in_ptr[bptr+1]+in_ptr[bptr-width+1]+in_ptr[bptr+width+1];\r
+ out_ptr[bptr]=(col1+col2)/6;\r
+ bptr++;\r
+ for(int x=0;x<width-2;x++){\r
+ col0=col1;\r
+ col1=col2;\r
+ col2=in_ptr[bptr+1]+in_ptr[bptr-width+1]+in_ptr[bptr+width+1];\r
+ out_ptr[bptr]=(col0+col1+col2)/9;\r
+ bptr++;\r
+ }\r
+ //右端\r
+ out_ptr[bptr]=(col1+col2)/6;\r
+ bptr++;\r
+ }\r
+ //末行目\r
+ col1=in_ptr[bptr ]+in_ptr[bptr-width ];\r
+ col2=in_ptr[bptr+1]+in_ptr[bptr-width+1];\r
+ out_ptr[bptr]=(col1+col2)/4;\r
+ bptr++;\r
+ for(int x=0;x<width-2;x++){\r
+ col0=col1;\r
+ col1=col2;\r
+ col2=in_ptr[bptr+1]+in_ptr[bptr-width+1];\r
+ out_ptr[bptr]=(col0+col1+col2)/6;\r
+ bptr++;\r
+ } \r
+ out_ptr[bptr]=(col1+col2)/4;\r
+ bptr++;\r
+ return;\r
+ }\r
+ }\r
+}
\ No newline at end of file
* このフィルタは、RGB値の平均値を、(R+G+B)/3で算出します。\r
*\r
*/\r
-public class NyARRasterFilter_RgbAveAdd implements INyARRasterFilter_RgbToGs\r
+public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs\r
{\r
IdoThFilterImpl _do_filter_impl;\r
- public NyARRasterFilter_RgbAveAdd(int i_raster_type) throws NyARException\r
+ public NyARRasterFilter_Rgb2Gs_AveAdd(int i_raster_type) throws NyARException\r
{\r
switch (i_raster_type) {\r
case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\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.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.rgb2gs.INyARRasterFilter_RgbToGs;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+\r
+/**\r
+ * RGBラスタをGrayScaleに変換するフィルタを作成します。\r
+ * このフィルタは、RGB値の平均値を、(R*G*B)/(255*255)で算出します。\r
+ * \r
+ * この値は、RGB成分の作る立方体の体積を0-255スケールにした値です。\r
+ *\r
+ */\r
+public class NyARRasterFilter_Rgb2Gs_RgbCube implements INyARRasterFilter_RgbToGs\r
+{\r
+ private IdoFilterImpl _dofilterimpl;\r
+ public NyARRasterFilter_Rgb2Gs_RgbCube(int i_raster_type) throws NyARException\r
+ {\r
+ switch (i_raster_type) {\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+ this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ }\r
+ public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
+ {\r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+ this._dofilterimpl.doFilter(i_input.getBufferReader(),i_output.getBufferReader(),i_input.getSize());\r
+ }\r
+ \r
+ interface IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException;\r
+ }\r
+ class IdoFilterImpl_BYTE1D_B8G8R8_24 implements IdoFilterImpl\r
+ {\r
+ /**\r
+ * This function is not optimized.\r
+ */\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
+ {\r
+ assert( i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24)\r
+ || i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24));\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)) >> 16;\r
+ bp += 3;\r
+ }\r
+ }\r
+ return;\r
+ }\r
+ }\r
+ \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.core.rasterfilter.rgb2gs;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.INyARRasterFilter_RgbToGs;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+/**\r
+ * YCbCr変換して、Y成分のグレースケールの値を計算します。\r
+ * 変換式は、http://www.tyre.gotdns.org/を参考にしました。\r
+ */\r
+public class NyARRasterFilter_Rgb2Gs_YCbCr implements INyARRasterFilter_RgbToGs\r
+{\r
+ private IdoFilterImpl _dofilterimpl;\r
+ public NyARRasterFilter_Rgb2Gs_YCbCr(int i_raster_type) throws NyARException\r
+ {\r
+ switch (i_raster_type) {\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+ this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();\r
+ break;\r
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ }\r
+ public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
+ {\r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+ this._dofilterimpl.doFilter(i_input.getBufferReader(),i_output.getBufferReader(),i_input.getSize());\r
+ }\r
+ \r
+ interface IdoFilterImpl\r
+ {\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException;\r
+ }\r
+ class IdoFilterImpl_BYTE1D_B8G8R8_24 implements IdoFilterImpl\r
+ {\r
+ /**\r
+ * This function is not optimized.\r
+ */\r
+ public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
+ {\r
+ assert( i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24));\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]=(306*(in_buf[bp+2] & 0xff)+601*(in_buf[bp + 1] & 0xff)+117 * (in_buf[bp + 0] & 0xff))>>10;\r
+ bp += 3;\r
+ }\r
+ }\r
+ return;\r
+ }\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
+package jp.nyatla.nyartoolkit.core.squaredetect;\r
+\r
+/**\r
+ * 座標店集合(輪郭線)から、頂点リストを計算します。\r
+ *\r
+ */\r
+public class Coord2SquareVertexIndexes\r
+{\r
+ private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ \r
+ private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();\r
+ private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();\r
+ public Coord2SquareVertexIndexes()\r
+ {\r
+ return;\r
+ }\r
+ /**\r
+ * 座標集合から、頂点候補になりそうな場所を4箇所探して、そのインデクス番号を返します。\r
+ * @param i_x_coord\r
+ * @param i_y_coord\r
+ * @param i_coord_num\r
+ * @param i_area\r
+ * @param o_vertex\r
+ * @return\r
+ */\r
+ public boolean getVertexIndexes(int[] i_x_coord, int[] i_y_coord, int i_coord_num, int i_area, int[] o_vertex)\r
+ {\r
+ final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;\r
+ final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;\r
+ int vertex1_index=getFarPoint(i_x_coord,i_y_coord,i_coord_num,0);\r
+ int prev_vertex_index=(vertex1_index+i_coord_num)%i_coord_num;\r
+ int v1=getFarPoint(i_x_coord,i_y_coord,i_coord_num,vertex1_index);\r
+ final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;\r
+\r
+ o_vertex[0] = vertex1_index;\r
+\r
+ if (!wv1.getVertex(i_x_coord, i_y_coord,i_coord_num, vertex1_index, v1, thresh)) {\r
+ return false;\r
+ }\r
+ if (!wv2.getVertex(i_x_coord, i_y_coord,i_coord_num, v1,prev_vertex_index, thresh)) {\r
+ return false;\r
+ }\r
+\r
+ int v2;\r
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
+ o_vertex[1] = wv1.vertex[0];\r
+ o_vertex[2] = v1;\r
+ o_vertex[3] = wv2.vertex[0];\r
+ } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {\r
+ //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。\r
+ if(v1>=vertex1_index){\r
+ v2 = (v1-vertex1_index)/2+vertex1_index;\r
+ }else{\r
+ v2 = ((v1+i_coord_num-vertex1_index)/2+vertex1_index)%i_coord_num;\r
+ }\r
+ if (!wv1.getVertex(i_x_coord, i_y_coord,i_coord_num, vertex1_index, v2, thresh)) {\r
+ return false;\r
+ }\r
+ if (!wv2.getVertex(i_x_coord, i_y_coord,i_coord_num, v2, v1, thresh)) {\r
+ return false;\r
+ }\r
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
+ o_vertex[1] = wv1.vertex[0];\r
+ o_vertex[2] = wv2.vertex[0];\r
+ o_vertex[3] = v1;\r
+ } else {\r
+ return false;\r
+ }\r
+ } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {\r
+ //v2 = (v1+ end_of_coord)/2;\r
+ if(v1<=prev_vertex_index){\r
+ v2 = (v1+prev_vertex_index)/2;\r
+ }else{\r
+ v2 = ((v1+i_coord_num+prev_vertex_index)/2)%i_coord_num;\r
+ \r
+ }\r
+ if (!wv1.getVertex(i_x_coord, i_y_coord,i_coord_num, v1, v2, thresh)) {\r
+ return false;\r
+ }\r
+ if (!wv2.getVertex(i_x_coord, i_y_coord,i_coord_num, v2, prev_vertex_index, thresh)) {\r
+ return false;\r
+ }\r
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
+ o_vertex[1] = v1;\r
+ o_vertex[2] = wv1.vertex[0];\r
+ o_vertex[3] = wv2.vertex[0];\r
+ } else {\r
+ \r
+ return false;\r
+ }\r
+ } else {\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+ /**\r
+ * i_pointの輪郭座標から、最も遠方にある輪郭座標のインデクスを探します。\r
+ * @param i_xcoord\r
+ * @param i_ycoord\r
+ * @param i_coord_num\r
+ * @return\r
+ */\r
+ private static int getFarPoint(int[] i_coord_x, int[] i_coord_y,int i_coord_num,int i_point)\r
+ {\r
+ //\r
+ final int sx = i_coord_x[i_point];\r
+ final int sy = i_coord_y[i_point];\r
+ int d = 0;\r
+ int w, x, y;\r
+ int ret = 0;\r
+ for (int i = i_point+1; i < i_coord_num; i++) {\r
+ x = i_coord_x[i] - sx;\r
+ y = i_coord_y[i] - sy;\r
+ w = x * x + y * y;\r
+ if (w > d) {\r
+ d = w;\r
+ ret = i;\r
+ }\r
+ }\r
+ for (int i = 0; i < i_point; i++) {\r
+ x = i_coord_x[i] - sx;\r
+ y = i_coord_y[i] - sy;\r
+ w = x * x + y * y;\r
+ if (w > d) {\r
+ d = w;\r
+ ret = i;\r
+ }\r
+ } \r
+ return ret;\r
+ } \r
+}
\ No newline at end of file
import jp.nyatla.nyartoolkit.core.types.NyARLinear;\r
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;\r
\r
+\r
+\r
+\r
public class SquareContourDetector\r
{\r
- private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ \r
private final double[] _xpos;\r
private final double[] _ypos; \r
- private final int[] __detectMarker_mkvertex = new int[5];\r
- private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();\r
- private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();\r
+ private final int[] __detectMarker_mkvertex = new int[4];\r
private final INyARPca2d _pca;\r
private final NyARDoubleMatrix22 __getSquareLine_evec=new NyARDoubleMatrix22();\r
private final double[] __getSquareLine_mean=new double[2];\r
private final double[] __getSquareLine_ev=new double[2];\r
+ private final Coord2SquareVertexIndexes _coord2vertex=new Coord2SquareVertexIndexes();\r
private final NyARObserv2IdealMap _dist_factor;\r
public SquareContourDetector(NyARIntSize i_size,NyARCameraDistortionFactor i_distfactor_ref)\r
{\r
this._dist_factor = new NyARObserv2IdealMap(i_distfactor_ref,i_size);\r
\r
\r
- // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。\r
+ // 輪郭バッファ\r
this._pca=new NyARPca2d_MatrixPCA_O2();\r
this._xpos=new double[i_size.w+i_size.h];//最大辺長はthis._width+this._height\r
this._ypos=new double[i_size.w+i_size.h];//最大辺長はthis._width+this._height\r
{\r
\r
final int[] mkvertex = this.__detectMarker_mkvertex;\r
- int vertex_1=getFarPoint(i_xcoord,i_ycoord,i_coord_num,0);\r
// 頂点情報を取得\r
- if (!getSquareVertex(i_xcoord, i_ycoord, vertex_1, i_coord_num-1, i_label_area, mkvertex)) {\r
+ if (!this._coord2vertex.getVertexIndexes(i_xcoord, i_ycoord, i_coord_num, i_label_area, mkvertex)) {\r
// 頂点の取得が出来なかったので破棄\r
return false;\r
}\r
final double[] mean=this.__getSquareLine_mean;\r
final double[] ev=this.__getSquareLine_ev;\r
\r
- double w1; \r
+ double w1;\r
for (int i = 0; i < 4; i++){\r
+ //頂点を取得\r
+ int ver1=i_mkvertex[i];\r
+ int ver2=i_mkvertex[(i+1)%4];\r
int n,st,ed;\r
//探索区間の決定\r
- if(i_mkvertex[i + 1]>=i_mkvertex[i]){\r
+ if(ver2>=i_mkvertex[i]){\r
//頂点[i]から頂点[i+1]までの輪郭が、1区間にあるとき\r
- w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;\r
+ w1 = (double) (ver2 - ver1 + 1) * 0.05 + 0.5;\r
//探索区間の決定\r
- st = (int) (i_mkvertex[i]+w1);\r
- ed = (int) (i_mkvertex[i+1] - w1);\r
+ st = (int) (ver1+w1);\r
+ ed = (int) (ver2 - w1);\r
}else{\r
//頂点[i]から頂点[i+1]までの輪郭が、2区間に分かれているとき\r
- w1 = (double) (i_mkvertex[i + 1]+i_cood_num-i_mkvertex[i]+1)%i_cood_num * 0.05 + 0.5;\r
+ w1 = (double) (ver2+i_cood_num-ver1+1)%i_cood_num * 0.05 + 0.5;\r
//探索区間の決定\r
- st = (int) (i_mkvertex[i]+w1)%i_cood_num;\r
- ed = (int) (i_mkvertex[i+1]+i_cood_num-w1)%i_cood_num;\r
+ st = (int) (ver1+w1)%i_cood_num;\r
+ ed = (int) (ver2+i_cood_num-w1)%i_cood_num;\r
}\r
//探索区間数を確認\r
if(st<=ed){\r
final NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;\r
final NyARIntPoint2d[] l_imvertex = o_square.imvertex;\r
for (int i = 0; i < 4; i++) {\r
- final NyARLinear l_line_i = l_line[i];\r
- final NyARLinear l_line_2 = l_line[(i + 3) % 4];\r
- w1 = l_line_2.dy * l_line_i.dx - l_line_i.dy * l_line_2.dx;\r
- if (w1 == 0.0) {\r
+ //直線同士の交点計算\r
+ if(!NyARLinear.crossPos(l_line[i],l_line[(i + 3) % 4],l_sqvertex[i])){\r
return false;\r
}\r
- l_sqvertex[i].x = (l_line_2.dx * l_line_i.c - l_line_i.dx * l_line_2.c) / w1;\r
- l_sqvertex[i].y = (l_line_i.dy * l_line_2.c - l_line_2.dy * l_line_i.c) / w1;\r
// 頂点インデクスから頂点座標を得て保存\r
l_imvertex[i].x = i_xcoord[i_mkvertex[i]];\r
l_imvertex[i].y = i_ycoord[i_mkvertex[i]];\r
}\r
return true;\r
} \r
- \r
-\r
- private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)\r
- {\r
- final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;\r
- final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;\r
- int prev_vertex_index=(i_vertex1_index+i_coord_num)%i_coord_num;\r
- int v1=getFarPoint(i_x_coord,i_y_coord,i_coord_num,i_vertex1_index);\r
- final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;\r
-\r
- o_vertex[0] = i_vertex1_index;\r
-\r
- if (!wv1.getVertex(i_x_coord, i_y_coord,i_coord_num, i_vertex1_index, v1, thresh)) {\r
- return false;\r
- }\r
- if (!wv2.getVertex(i_x_coord, i_y_coord,i_coord_num, v1,prev_vertex_index, thresh)) {\r
- return false;\r
- }\r
-\r
- int v2;\r
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {\r
- o_vertex[1] = wv1.vertex[0];\r
- o_vertex[2] = v1;\r
- o_vertex[3] = wv2.vertex[0];\r
- } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {\r
- //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。\r
- if(v1>=i_vertex1_index){\r
- v2 = (v1-i_vertex1_index)/2+i_vertex1_index;\r
- }else{\r
- v2 = ((v1+i_coord_num-i_vertex1_index)/2+i_vertex1_index)%i_coord_num;\r
- }\r
- if (!wv1.getVertex(i_x_coord, i_y_coord,i_coord_num, i_vertex1_index, v2, thresh)) {\r
- return false;\r
- }\r
- if (!wv2.getVertex(i_x_coord, i_y_coord,i_coord_num, v2, v1, thresh)) {\r
- return false;\r
- }\r
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
- o_vertex[1] = wv1.vertex[0];\r
- o_vertex[2] = wv2.vertex[0];\r
- o_vertex[3] = v1;\r
- } else {\r
- return false;\r
- }\r
- } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {\r
- //v2 = (v1+ end_of_coord)/2;\r
- if(v1<=prev_vertex_index){\r
- v2 = (v1+prev_vertex_index)/2;\r
- }else{\r
- v2 = ((v1+i_coord_num+prev_vertex_index)/2)%i_coord_num;\r
- \r
- }\r
- if (!wv1.getVertex(i_x_coord, i_y_coord,i_coord_num, v1, v2, thresh)) {\r
- return false;\r
- }\r
- if (!wv2.getVertex(i_x_coord, i_y_coord,i_coord_num, v2, prev_vertex_index, thresh)) {\r
- return false;\r
- }\r
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
- o_vertex[1] = v1;\r
- o_vertex[2] = wv1.vertex[0];\r
- o_vertex[3] = wv2.vertex[0];\r
- } else {\r
- \r
- return false;\r
- }\r
- } else {\r
- return false;\r
- }\r
- o_vertex[4] = prev_vertex_index;\r
- return true;\r
- }\r
-\r
- /**\r
- * i_pointの輪郭座標から、最も遠方にある輪郭座標のインデクスを探します。\r
- * @param i_xcoord\r
- * @param i_ycoord\r
- * @param i_coord_num\r
- * @return\r
- */\r
- private static int getFarPoint(int[] i_coord_x, int[] i_coord_y,int i_coord_num,int i_point)\r
- {\r
- //\r
- final int sx = i_coord_x[i_point];\r
- final int sy = i_coord_y[i_point];\r
- int d = 0;\r
- int w, x, y;\r
- int ret = 0;\r
- for (int i = i_point+1; i < i_coord_num; i++) {\r
- x = i_coord_x[i] - sx;\r
- y = i_coord_y[i] - sy;\r
- w = x * x + y * y;\r
- if (w > d) {\r
- d = w;\r
- ret = i;\r
- }\r
- }\r
- for (int i = 0; i < i_point; i++) {\r
- x = i_coord_x[i] - sx;\r
- y = i_coord_y[i] - sy;\r
- w = x * x + y * y;\r
- if (w > d) {\r
- d = w;\r
- ret = i;\r
- }\r
- } \r
- return ret;\r
- } \r
}
\ No newline at end of file
this.total_of_data-=s;\r
}\r
/**\r
- * 指定したi_pos未満サンプルを0にします。\r
+ * 指定したi_pos以上のサンプルを0にします。\r
* @param i_pos\r
*/\r
public void highCut(int i_pos)\r
this.c=i_source.c;\r
return;\r
}\r
+ /**\r
+ * 2直線の交点を計算します。\r
+ * @param l_line_i\r
+ * @param l_line_2\r
+ * @param o_point\r
+ * @return\r
+ */\r
+ public final static boolean crossPos(NyARLinear l_line_i,NyARLinear l_line_2,NyARDoublePoint2d o_point)\r
+ {\r
+ final double w1 = l_line_2.dy * l_line_i.dx - l_line_i.dy * l_line_2.dx;\r
+ if (w1 == 0.0) {\r
+ return false;\r
+ }\r
+ o_point.x = (l_line_2.dx * l_line_i.c - l_line_i.dx * l_line_2.c) / w1;\r
+ o_point.y = (l_line_i.dy * l_line_2.c - l_line_2.dy * l_line_i.c) / w1;\r
+ return true;\r
+ } \r
}\r