protected boolean _is_index_table_enable;\r
public NyARLabelingImage(int i_width, int i_height) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D);\r
+ super(i_width,i_height,NyARBufferType.INT1D);\r
this._ref_buf =new int[i_height*i_width];\r
this._label_list = new NyARLabelingLabelStack(MAX_LABELS);\r
this._index_table=new int[MAX_LABELS];\r
*/\r
public NyARBinRaster(int i_width, int i_height,int i_raster_type,boolean i_is_alloc) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),i_raster_type);\r
+ super(i_width,i_height,i_raster_type);\r
if(!initInstance(this._size,i_raster_type,i_is_alloc)){\r
throw new NyARException();\r
}\r
}\r
public NyARBinRaster(int i_width, int i_height,boolean i_is_alloc) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_BIN_8);\r
+ super(i_width,i_height,NyARBufferType.INT1D_BIN_8);\r
if(!initInstance(this._size,NyARBufferType.INT1D_BIN_8,i_is_alloc)){\r
throw new NyARException();\r
}\r
}\r
public NyARBinRaster(int i_width, int i_height) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_BIN_8);\r
+ super(i_width,i_height,NyARBufferType.INT1D_BIN_8);\r
if(!initInstance(this._size,NyARBufferType.INT1D_BIN_8,true)){\r
throw new NyARException();\r
}\r
\r
public NyARGrayscaleRaster(int i_width, int i_height) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_GRAY_8);\r
+ super(i_width,i_height,NyARBufferType.INT1D_GRAY_8);\r
if(!initInstance(this._size,NyARBufferType.INT1D_GRAY_8,true)){\r
throw new NyARException();\r
}\r
} \r
public NyARGrayscaleRaster(int i_width, int i_height,boolean i_is_alloc) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_GRAY_8);\r
+ super(i_width,i_height,NyARBufferType.INT1D_GRAY_8);\r
if(!initInstance(this._size,NyARBufferType.INT1D_GRAY_8,i_is_alloc)){\r
throw new NyARException();\r
}\r
*/\r
public NyARGrayscaleRaster(int i_width, int i_height,int i_raster_type,boolean i_is_alloc) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),i_raster_type);\r
+ super(i_width,i_height,i_raster_type);\r
if(!initInstance(this._size,i_raster_type,i_is_alloc)){\r
throw new NyARException();\r
}\r
public NyARHsvRaster(int i_width, int i_height)\r
{\r
//このクラスは外部参照バッファ/形式多重化が使えない簡易実装です。\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_X7H9S8V8_32);\r
+ super(i_width,i_height,NyARBufferType.INT1D_X7H9S8V8_32);\r
this._ref_buf = new int[i_height*i_width];\r
}\r
public Object getBuffer()\r
*/\r
public NyARRaster(int i_width, int i_height,int i_buffer_type,boolean i_is_alloc) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),i_buffer_type);\r
+ super(i_width,i_height,i_buffer_type);\r
if(!initInstance(this._size,i_buffer_type,i_is_alloc)){\r
throw new NyARException();\r
}\r
\r
public NyARRaster(int i_width, int i_height,int i_buffer_type) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),i_buffer_type);\r
+ super(i_width,i_height,i_buffer_type);\r
if(!initInstance(this._size,i_buffer_type,true)){\r
throw new NyARException();\r
}\r
{\r
protected NyARIntSize _size;\r
private int _buffer_type;\r
- protected NyARRaster_BasicClass(final NyARIntSize i_size,int i_buffer_type)\r
+ protected NyARRaster_BasicClass(int i_width,int i_height,int i_buffer_type)\r
{\r
- this._size= i_size;\r
+ this._size= new NyARIntSize(i_width,i_height);\r
this._buffer_type=i_buffer_type;\r
}\r
\r
*/\r
public NyARRgbRaster(int i_width, int i_height,int i_raster_type,boolean i_is_alloc) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),i_raster_type);\r
+ super(i_width,i_height,i_raster_type);\r
if(!initInstance(this._size,i_raster_type,i_is_alloc)){\r
throw new NyARException();\r
}\r
*/\r
public NyARRgbRaster(int i_width, int i_height,int i_raster_type) throws NyARException\r
{\r
- super(new NyARIntSize(i_width,i_height),i_raster_type);\r
+ super(i_width,i_height,i_raster_type);\r
if(!initInstance(this._size,i_raster_type,true)){\r
throw new NyARException();\r
}\r
{\r
final protected NyARIntSize _size;\r
private int _buffer_type;\r
- \r
- protected NyARRgbRaster_BasicClass(final NyARIntSize i_size,int i_buffer_type)\r
+ protected NyARRgbRaster_BasicClass(int i_width,int i_height,int i_buffer_type)\r
{\r
- this._size= i_size;\r
+ this._size= new NyARIntSize(i_width,i_height);\r
this._buffer_type=i_buffer_type;\r
}\r
final public int getWidth()\r
\r
public NyARRgbRaster_Blank(int i_width, int i_height)\r
{\r
- super(new NyARIntSize(i_width,i_height),NyARBufferType.NULL_ALLZERO);\r
+ super(i_width,i_height,NyARBufferType.NULL_ALLZERO);\r
this._reader = new PixelReader();\r
return;\r
}\r
}\r
public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException\r
{\r
- NyARException.notImplement(); \r
+ final byte[] ref_buf = this._ref_buf;\r
+ final int idx=(i_y*this._size.w+i_x)*3;\r
+ ref_buf[idx + 0] = (byte)i_rgb[0];// R\r
+ ref_buf[idx + 1] = (byte)i_rgb[1];// G\r
+ ref_buf[idx + 2] = (byte)i_rgb[2];// B\r
}\r
public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException\r
{\r
ed = (int) (i_ed - w1);\r
}else{\r
//頂点[i]から頂点[i+1]までの輪郭が、2区間に分かれているとき\r
- w1 = (double) (i_ed+i_cood_num-i_st+1)%i_cood_num * 0.05 + 0.5;\r
+ w1 = (double)((i_ed+i_cood_num-i_st+1)%i_cood_num) * 0.05 + 0.5;\r
//探索区間の決定\r
- st = (int) (i_st+w1)%i_cood_num;\r
- ed = (int) (i_ed+i_cood_num-w1)%i_cood_num;\r
+ st = ((int) (i_st+w1))%i_cood_num;\r
+ ed = ((int) (i_ed+i_cood_num-w1))%i_cood_num;\r
}\r
//探索区間数を確認\r
if(st<=ed){\r
import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;\r
import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;\r
import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;\r
-import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;\r
import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;\r
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
\r
* \r
* @param i_param\r
*/\r
- public NyARSquareContourDetector_ARToolKit(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException\r
+ public NyARSquareContourDetector_ARToolKit(NyARIntSize i_size) throws NyARException\r
{\r
this._width = i_size.w;\r
this._height = i_size.h;\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.labeling.NyARLabelOverlapChecker;\r
import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.*;\r
-import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;\r
import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
-import java.util.*;\r
\r
\r
public class NyARSquareContourDetector_Rle extends NyARSquareContourDetector\r
* \r
* @param i_param\r
*/\r
- public NyARSquareContourDetector_Rle(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException\r
+ public NyARSquareContourDetector_Rle(NyARIntSize i_size) throws NyARException\r
{\r
this._width = i_size.w;\r
this._height = i_size.h;\r
det=1/det;\r
this.m00=a22*det;\r
this.m01=-a12*det;\r
- this.m10=a21*det;\r
- this.m11=-a11*det;\r
+ this.m10=-a21*det;\r
+ this.m11=a11*det;\r
return true;\r
} \r
}\r
package jp.nyatla.nyartoolkit.core.utils;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
\r
/**\r
* 遠近法を用いたPerspectiveパラメータを計算するクラスです。\r
this._local_y=i_local_y;\r
return;\r
}\r
+\r
+ \r
public boolean getParam(final NyARIntPoint2d[] i_vertex,double[] o_param)throws NyARException\r
{\r
- double[][] la1,la2;\r
- double[] ra1,ra2;\r
double ltx=this._local_x;\r
double lty=this._local_y;\r
double rbx=ltx+this._width;\r
double rby=lty+this._height;\r
- la1=new double[4][5];\r
- la2=new double[4][5];\r
- ra1=new double[4];\r
- ra2=new double[4];\r
- //A,B,C,(GH)の方程式\r
- la1[0][0]=ltx; la1[0][1]=lty; la1[0][2]=1; la1[0][3]=-ltx*i_vertex[0].x; la1[0][4]=-lty*i_vertex[0].x;\r
- la1[1][0]=rbx; la1[1][1]=lty; la1[1][2]=1; la1[1][3]=-rbx*i_vertex[1].x; la1[1][4]=-lty*i_vertex[1].x;\r
- la1[2][0]=rbx; la1[2][1]=rby; la1[2][2]=1; la1[2][3]=-rbx*i_vertex[2].x; la1[2][4]=-rby*i_vertex[2].x;\r
- la1[3][0]=ltx; la1[3][1]=rby; la1[3][2]=1; la1[3][3]=-ltx*i_vertex[3].x; la1[3][4]=-rby*i_vertex[3].x;\r
- ra1[0]=i_vertex[0].x;ra1[1]=i_vertex[1].x;ra1[2]=i_vertex[2].x;ra1[3]=i_vertex[3].x;\r
- NyARSystemOfLinearEquationsProcessor.doGaussianElimination(la1,ra1,5,4);\r
+ double x1,x2,x3,x4;\r
+ double y1,y2,y3,y4;\r
+ x1=i_vertex[0].x;\r
+ x2=i_vertex[1].x;\r
+ x3=i_vertex[2].x;\r
+ x4=i_vertex[3].x;\r
+ y1=i_vertex[0].y;\r
+ y2=i_vertex[1].y;\r
+ y3=i_vertex[2].y;\r
+ y4=i_vertex[3].y;\r
+ \r
+ \r
+ NyARDoubleMatrix44 mat_x=new NyARDoubleMatrix44();\r
+ mat_x.m00=ltx; mat_x.m01=lty; mat_x.m02=-ltx*x1; mat_x.m03=-lty*x1;\r
+ mat_x.m10=rbx; mat_x.m11=lty; mat_x.m12=-rbx*x2; mat_x.m13=-lty*x2;\r
+ mat_x.m20=rbx; mat_x.m21=rby; mat_x.m22=-rbx*x3; mat_x.m23=-rby*x3;\r
+ mat_x.m30=ltx; mat_x.m31=rby; mat_x.m32=-ltx*x4; mat_x.m33=-rby*x4;\r
+ mat_x.inverse(mat_x);\r
+ NyARDoubleMatrix44 mat_y=new NyARDoubleMatrix44();\r
+ mat_y.m00=ltx; mat_y.m01=lty; mat_y.m02=-ltx*y1; mat_y.m03=-lty*y1;\r
+ mat_y.m10=rbx; mat_y.m11=lty; mat_y.m12=-rbx*y2; mat_y.m13=-lty*y2;\r
+ mat_y.m20=rbx; mat_y.m21=rby; mat_y.m22=-rbx*y3; mat_y.m23=-rby*y3;\r
+ mat_y.m30=ltx; mat_y.m31=rby; mat_y.m32=-ltx*y4; mat_y.m33=-rby*y4;\r
+ mat_y.inverse(mat_y);\r
+ double a=mat_x.m20*x1+mat_x.m21*x2+mat_x.m22*x3+mat_x.m23*x4;\r
+ double b=mat_x.m20+mat_x.m21+mat_x.m22+mat_x.m23;\r
+ double d=mat_x.m30*x1+mat_x.m31*x2+mat_x.m32*x3+mat_x.m33*x4;\r
+ double f=mat_x.m30+mat_x.m31+mat_x.m32+mat_x.m33;\r
+ \r
+ double g=mat_y.m20*y1+mat_y.m21*y2+mat_y.m22*y3+mat_y.m23*y4;\r
+ double h=mat_y.m20+mat_y.m21+mat_y.m22+mat_y.m23;\r
+ double i=mat_y.m30*y1+mat_y.m31*y2+mat_y.m32*y3+mat_y.m33*y4;\r
+ double j=mat_y.m30+mat_y.m31+mat_y.m32+mat_y.m33;\r
+ \r
+ NyARDoubleMatrix22 tm=new NyARDoubleMatrix22();\r
+ tm.m00=b;\r
+ tm.m01=-h;\r
+ tm.m10=f;\r
+ tm.m11=-j;\r
+ tm.inverse(tm);\r
\r
- //D,E,F,(GH)の方程式\r
- la2[0][0]=ltx; la2[0][1]=lty; la2[0][2]=1; la2[0][3]=-ltx*i_vertex[0].y; la2[0][4]=-lty*i_vertex[0].y;\r
- la2[1][0]=rbx; la2[1][1]=lty; la2[1][2]=1; la2[1][3]=-rbx*i_vertex[1].y; la2[1][4]=-lty*i_vertex[1].y;\r
- la2[2][0]=rbx; la2[2][1]=rby; la2[2][2]=1; la2[2][3]=-rbx*i_vertex[2].y; la2[2][4]=-rby*i_vertex[2].y;\r
- la2[3][0]=ltx; la2[3][1]=rby; la2[3][2]=1; la2[3][3]=-ltx*i_vertex[3].y; la2[3][4]=-rby*i_vertex[3].y;\r
- ra2[0]=i_vertex[0].y;ra2[1]=i_vertex[1].y;ra2[2]=i_vertex[2].y;ra2[3]=i_vertex[3].y;\r
- NyARSystemOfLinearEquationsProcessor.doGaussianElimination(la2,ra2,5,4);\r
- //GHを計算\r
+ \r
double A,B,C,D,E,F,G,H;\r
- H=(ra2[3]-ra1[3])/(la2[3][4]-la1[3][4]);\r
- G=ra2[3]-la2[3][4]*H;\r
- //残りを計算\r
- F=ra2[2]-H*la2[2][4]-G*la2[2][3];\r
- E=ra2[1]-H*la2[1][4]-G*la2[1][3]-F*la2[1][2];\r
- D=ra2[0]-H*la2[0][4]-G*la2[0][3]-F*la2[0][2]-E*la2[0][1];\r
- C=ra1[2]-H*la1[2][4]-G*la1[2][3];\r
- B=ra1[1]-H*la1[1][4]-G*la1[1][3]-C*la1[1][2];\r
- A=ra1[0]-H*la1[0][4]-G*la1[0][3]-C*la1[0][2]-B*la1[0][1];\r
+\r
+ C=tm.m00*(a-g)+tm.m01*(d-i); //C\r
+ F=tm.m10*(a-g)+tm.m11*(d-i); //F\r
+ G=a-C*b;\r
+ H=d-C*f;\r
+ A=(mat_x.m00*x1+mat_x.m01*x2+mat_x.m02*x3+mat_x.m03*x4)-C*(mat_x.m00+mat_x.m01+mat_x.m02+mat_x.m03);\r
+ B=(mat_x.m10*x1+mat_x.m11*x2+mat_x.m12*x3+mat_x.m13*x4)-C*(mat_x.m10+mat_x.m11+mat_x.m12+mat_x.m13);\r
+ D=(mat_y.m00*y1+mat_y.m01*y2+mat_y.m02*y3+mat_y.m03*y4)-F*(mat_y.m00+mat_y.m01+mat_y.m02+mat_y.m03);\r
+ E=(mat_y.m10*y1+mat_y.m11*y2+mat_y.m12*y3+mat_y.m13*y4)-F*(mat_y.m10+mat_y.m11+mat_y.m12+mat_y.m13);\r
+\r
+\r
o_param[0]=A;\r
o_param[1]=B;\r
o_param[2]=C;\r
o_param[5]=F;\r
o_param[6]=G;\r
o_param[7]=H;\r
+ \r
+\r
return true;\r
+\r
}\r
}\r
{\r
super(i_local_x,i_local_y,i_width,i_height);\r
return;\r
- }\r
+ }/*\r
final public boolean getParam(final NyARIntPoint2d[] i_vertex,double[] o_param)throws NyARException\r
{\r
double G,H;\r
o_param[1]=w1;\r
o_param[0]=w2;\r
return true;\r
- }\r
+ }*/\r
}\r
i_ref_code,i_number_of_code,i_ref_param);\r
this._transmat = new NyARTransMat(i_ref_param);\r
//NyARToolkitプロファイル\r
- this._square_detect =new NyARSquareContourDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ this._square_detect =new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());\r
this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);\r
\r
//実サイズ保存\r
switch(i_profile_id){\r
case PF_ARTOOLKIT_COMPATIBLE:\r
patt_inst=new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());\r
- sqdetect_inst=new NyARSquareContourDetector_ARToolKit(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ sqdetect_inst=new NyARSquareContourDetector_ARToolKit(i_ref_param.getScreenSize());\r
transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);\r
break;\r
case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:\r
patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
- sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());\r
transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);\r
break;\r
case PF_NYARTOOLKIT://default\r
patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
- sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());\r
transmat_inst=new NyARTransMat(i_ref_param);\r
break;\r
default:\r
\r
NyARIntSize scr_size = i_param.getScreenSize();\r
// 解析オブジェクトを作る\r
- this._square_detect = new NyARSquareContourDetector_Rle(i_param.getDistortionFactor(), scr_size);\r
+ this._square_detect = new NyARSquareContourDetector_Rle(scr_size);\r
this._transmat = new NyARTransMat(i_param);\r
this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(110,i_raster_type);\r
\r
this._square_detect.detectMarkerCB(this._bin_raster,this._detectmarker_cb);\r
\r
// 認識状態を更新\r
- final boolean is_id_found=updateStatus(this._detectmarker_cb.square,this._detectmarker_cb.code_index);\r
+ final boolean is_id_found=this.updateStatus(this._detectmarker_cb.square,this._detectmarker_cb.code_index);\r
//閾値フィードバック(detectExistMarkerにもあるよ)\r
if(!is_id_found){\r
//マーカがなければ、探索+DualPTailで基準輝度検索\r
return;\r
}\r
private boolean _initialized=false;\r
- protected void initInstance(NyARParam i_param,INyIdMarkerDataEncoder i_encoder,int i_marker_width,int i_raster_format) throws NyARException\r
+ protected void initInstance(NyARParam i_param,INyIdMarkerDataEncoder i_encoder,double i_marker_width,int i_raster_format) throws NyARException\r
{\r
//初期化済?\r
assert(this._initialized==false);\r
\r
NyARIntSize scr_size = i_param.getScreenSize();\r
// 解析オブジェクトを作る\r
- this._square_detect = new NyARSquareContourDetector_Rle(i_param.getDistortionFactor(), scr_size);\r
+ this._square_detect = new NyARSquareContourDetector_Rle(scr_size);\r
this._transmat = new NyARTransMat(i_param);\r
this._callback=new DetectSquareCB(i_param,i_encoder);\r
\r