public void prepare(INyARPerspectiveCopy i_pcopy, INyARGrayscaleRaster i_gs, int th) { this._ref_input_rfb = i_pcopy; this._ref_input_gs = i_gs; this._ref_th = th; this._sq_stack.clear(); }
public void build(INyARGrayscaleRaster i_raster) { Debug.Assert(i_raster.getSize().isEqualSize(this.mPyramid[0].getSize())); Debug.Assert(this.mPyramid.Length == mNumOctaves * mNumScalesPerOctave); // First octave apply_filter(mPyramid[0], i_raster); apply_filter(mPyramid[1], mPyramid[0]); apply_filter_twice(mPyramid[2], mPyramid[1]); // Remaining octaves for (int i = 1; i < mNumOctaves; i++) { // Downsample downsample_bilinear( (double[])mPyramid[i * mNumScalesPerOctave].getBuffer(), (double[])mPyramid[i * mNumScalesPerOctave - 1].getBuffer(), mPyramid[i * mNumScalesPerOctave - 1].getWidth(), mPyramid[i * mNumScalesPerOctave - 1].getHeight()); // Apply binomial filters apply_filter(mPyramid[i * mNumScalesPerOctave + 1], mPyramid[i * mNumScalesPerOctave]); apply_filter_twice(mPyramid[i * mNumScalesPerOctave + 2], mPyramid[i * mNumScalesPerOctave + 1]); } return; }
/** この関数はメインクラスのupdateから実行します。 * */ public bool updateInputImage(INyARGrayscaleRaster i_input) { if (this._th == null) { return(false); } lock (this) { ThreadState st = this._th.ThreadState; //スレッドが無期限待機中でなければなにもしない。 if (st != ThreadState.WaitSleepJoin) { return(false); } //計算結果のコピー foreach (NftTarget target in this._ref_nftdatalist) { //検出フラグの更新 if (target.back_has_result && target.stage == NftTarget.ST_KPM_SEARCH) { //見つかった時だけ更新 //System.out.println("ST_KPM_FOUND"); target.stage = NftTarget.ST_KPM_FOUND; target.front_transmat.setValue(target.back_transmat); target.back_has_result = false; } } //KPMスレッドの再開 this._attached_matcher.updateInputImage(i_input); this._th.Interrupt(); } return(true); }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); INyARRgbPixelDriver input = this._raster.getRgbPixelDriver(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.getSize(); int skip_dst = (s.w - i_w); int skip_src = skip_dst; //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int[] rgb = this.__rgb; for (int y = 0; y < i_h; y++) { int x; for (x = 0; x < i_w; x++) { input.getPixel(x + i_l, y + i_t, rgb); output[pt_dst++] = (rgb[0] + rgb[1] + rgb[2]) <= th ? 0 : 1; } //スキップ pt_dst += skip_dst; } return; }
public static INyARGrayscaleRaster createInstance(int i_w, int i_h, int i_raster_type, Object i_src) { INyARGrayscaleRaster ret = createInstance(i_w, i_h, i_raster_type, false); ret.wrapBuffer(i_src); return(ret); }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); INyARRgbPixelDriver input = this._raster.getRgbPixelDriver(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.getSize(); int skip_dst = (s.w - i_w); int skip_src = skip_dst; //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int[] rgb = this.__rgb; for (int y = 0; y <i_h; y++) { int x; for (x = 0; x < i_w; x++) { input.getPixel(x + i_l, y + i_t, rgb); output[pt_dst++] = (rgb[0] + rgb[1] + rgb[2]) <= th ? 0 : 1; } //スキップ pt_dst += skip_dst; } return; }
public bool update(INyARGrayscaleRaster i_raster, SquareStack.Item i_sq) { if (!this._id_pickup.pickFromRaster(i_raster, i_sq.ob_vertex, this._id_patt, this._id_param)) { return(false); } if (!this._id_encoder.encode(this._id_patt, this._id_data)) { return(false); } //IDを検出 long s = this._id_data.marker_id; for (int i = this.Count - 1; i >= 0; i--) { Item target = this[i]; if (target.nyid_range_s > s || s > target.nyid_range_e) { continue; } //既に認識済なら無視 if (target.lost_count == 0) { continue; } //一致したよー。 target.nyid = s; target.dir = this._id_param.direction; target.sq = i_sq; return(true); } return(false); }
public double get_similarity(INyARGrayscaleRaster imageBW, int cx, int cy) { int ts1 = this._ts1; int ts2 = this._ts2; int xsize = imageBW.getWidth(); int ysize = imageBW.getHeight(); if (cy - ts1 < 0 || cy + ts2 >= ysize || cx - ts1 < 0 || cx + ts2 >= xsize) { return(-1); } int tp = 0; double p_sum = 0.0f; double pxp_sum = 0; double img_sum = 0; double img_p_sum = 0; for (int j = -ts1; j <= ts2; j++) { for (int i = -ts1; i <= ts2; i++) { int p = (imageBW.getPixel(cx + i, cy + j)); double t = this.img[tp++]; pxp_sum += p * p; p_sum += p; img_sum += t; img_p_sum += t * p; } } double ave = p_sum / ((ts1 + ts2 + 1) * (ts1 + ts2 + 1)); double w1 = img_p_sum - img_sum * ave; double vlen2 = Math.Sqrt((pxp_sum - 2 * p_sum * ave) + (ave * ave * (ts1 + ts2 + 1) * (ts1 + ts2 + 1))); return(w1 / (this.vlen * vlen2)); }
public bool update(INyARGrayscaleRaster i_raster, SquareStack.Item i_sq) { if (!this._pickup.getARPlayCardId(i_raster.getGsPixelDriver(), i_sq.ob_vertex, this._id_param)) { return(false); } //IDを検出 int s = this._id_param.id; for (int i = this.Count - 1; i >= 0; i--) { Item target = this[i]; if (target.nyid_range_s > s || s > target.nyid_range_e) { continue; } //既に認識済なら無視 if (target.lost_count == 0) { continue; } //一致したよー。 target.id = s; target.dir = this._id_param.direction; target.sq = i_sq; return(true); } return(false); }
/** * この関数は、インスタンスを初期化します。 * 継承先のクラスから呼び出してください。 * @param i_param * カメラパラメータオブジェクト。このサイズは、{@link #detectMarker}に入力する画像と同じサイズである必要があります。 * @param i_encoder * IDマーカの値エンコーダを指定します。 * @param i_marker_width * マーカの物理縦横サイズをmm単位で指定します。 * @ */ protected void initInstance(NyARParam i_param, INyIdMarkerDataEncoder i_encoder, double i_marker_width) { //初期化済? Debug.Assert(this._initialized == false); NyARIntSize scr_size = i_param.getScreenSize(); // 解析オブジェクトを作る this._square_detect = new RleDetector( i_param, i_encoder, new NyIdMarkerPickup()); this._transmat = new NyARTransMat(i_param); // 2値画像バッファを作る this._gs_raster = NyARGrayscaleRaster.createInstance(scr_size.w, scr_size.h); this._histmaker = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster)); //ワーク用のデータオブジェクトを2個作る this._data_current = i_encoder.createDataInstance(); this._threshold_detect = new NyARHistogramAnalyzer_SlidePTile(15); this._initialized = true; this._is_active = false; this._offset = new NyARRectOffset(); this._offset.setSquare(i_marker_width); return; }
public void line(int i_x, int i_y, double i_a, INyARGrayscaleRaster i_output) { if (i_a == 0) { int i; for (i = 0; i <= i_x; i++) { this._table[i] = 0; } for (i = 0; i < 256; i++) { this._table[i] = 255; } } else { int b = i_y - (int)(i_a * i_x); for (int i = 0; i < 256; i++) { int v = (int)(i_a * i) + b; this._table[i] = v < 0 ? 0 : v > 255 ? 255 : v; } } this._tone_filter.doFilter(this._table, i_output); }
/** * この関数は、ラスタドライバから画像を読み出します。 * @param i_pix_drv * @param i_size * @param i_vertex * @param o_data * @param o_param * @return * @ */ public bool pickFromRaster(INyARGrayscaleRaster i_raster, NyARDoublePoint2d[] i_vertex, NyIdMarkerPattern o_data, NyIdMarkerParam o_param) { if (!this._perspective_reader.setSourceSquare(i_vertex)) { return(false); } return(this._pickFromRaster(i_raster, o_data, o_param)); }
/** * この関数は、ラスタドライバから画像を読み出します。 * @param i_pix_drv * @param i_size * @param i_vertex * @param o_data * @param o_param * @return * @throws NyARException */ public bool getARPlayCardId(INyARGrayscaleRaster i_raster, NyARDoublePoint2d[] i_vertex, PsArIdParam i_result) { if (!this._perspective_reader.setSourceSquare(i_vertex)) { return(false); } return(this._pickFromRaster(i_raster, i_result)); }
public NyARTemplateMatchingDriver_ANY(INyARGrayscaleRaster i_ref_raster) { Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); this._i_ref_raster = i_ref_raster; this._mbuf = new byte[i_ref_raster.getWidth() * i_ref_raster.getHeight()]; this._search_area.x = AR2_DEFAULT_SEARCH_SIZE; this._search_area.y = AR2_DEFAULT_SEARCH_SIZE; }
public void gamma(double i_gamma, INyARGrayscaleRaster i_output) { for (int i = 0; i < 256; i++) { this._table[i] = (int)(Math.Pow((double)i / 255.0, i_gamma) * 255.0); } this._tone_filter.doFilter(this._table, i_output); }
/** * 検索ウインドウは(i_px*2+1)*(i_py*2+1)サイズの矩形。 * @param i_ref_raster * @param i_search_x * 検索ウインドウの範囲を指定する。 * @param i_search_y */ public NyARTemplateMatchingDriver_INT1D(INyARGrayscaleRaster i_ref_raster, int i_search_x, int i_search_y) { Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); this._i_ref_raster = i_ref_raster; this._mbuf = new byte[i_ref_raster.getWidth() * i_ref_raster.getHeight()]; this._search_area.x = i_search_x; this._search_area.y = i_search_y; }
/** * i_imageから、idマーカを読みだします。 * o_dataにはマーカデータ、o_paramにはマーカのパラメータを返却します。 * @param image * @param i_vertex * @param o_data * @param o_param * @return * @throws NyARException */ private bool _pickFromRaster(INyARGrayscaleRaster i_raster, PsArIdParam i_result) { if (!this._perspective_reader.readDataBits(i_raster, this._decoder)) { return(false); } //敷居値検索 return(this._decoder.decodePatt(i_result)); }
public void sigmoid(int i_x, int i_y, double i_gain, INyARGrayscaleRaster i_output) { for (int i = 0; i < 256; i++) { int v = 255 * (int)(1 / (1 + Math.Exp(i_gain * (i - i_x))) - 0.5) + i_y; this._table[i] = v < 0 ? 0 : v > 255 ? 255 : v; } this._tone_filter.doFilter(this._table, i_output); }
public NyARSensor(NyARIntSize i_size) { this._gs_raster = NyARGrayscaleRaster.createInstance(i_size.w, i_size.h, NyARBufferType.INT1D_GRAY_8, true); this._gs_hist = new NyARHistogram(256); this._src_ts = 0; this._gs_id_ts = 0; this._gs_hist_ts = 0; this._hist_drv = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster)); }
/** * この関数は、ラスタの指定点を基点に、画像の特定の範囲内から輪郭線を抽出します。 * 開始点は、輪郭の一部である必要があります。 * 通常は、ラべリングの結果の上辺クリップとX軸エントリポイントを開始点として入力します。 * @param i_raster * 輪郭線を抽出するラスタを指定します。 * @param i_area * 輪郭線の抽出範囲を指定する矩形。i_rasterのサイズ内である必要があります。 * @param i_th * 輪郭とみなす暗点の敷居値を指定します。 * @param i_entry_x * 輪郭抽出の開始点です。 * @param i_entry_y * 輪郭抽出の開始点です。 * @param o_coord * 輪郭点を格納するオブジェクトを指定します。 * @return * 輪郭線がo_coordの長さを超えた場合、falseを返します。 * @ */ public bool getContour(INyARGrayscaleRaster i_raster, NyARIntRect i_area, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord) { //ラスタドライバの切り替え if (i_raster != this._ref_last_input_raster) { this._imdriver = (IRasterDriver)i_raster.createInterface(typeof(IRasterDriver)); this._ref_last_input_raster = i_raster; } return(this._imdriver.getContour(i_area.x, i_area.y, i_area.x + i_area.w - 1, i_area.h + i_area.y - 1, i_entry_x, i_entry_y, i_th, o_coord)); }
public override bool labeling(INyARGrayscaleRaster i_raster, int i_th) { //配列初期化 this.label_stack.clear(); //ラベルの検出 bool ret = base.labeling(i_raster, i_th); //ソート this.label_stack.sortByArea(); return ret; }
/** * この関数は、i_rasterを操作するピクセルドライバインスタンスを生成します。 * @param i_raster * @return * @throws NyARException */ public static INyARGsRasterGraphics CreateDriver(INyARGrayscaleRaster i_raster) { switch (i_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: return new NyARGsRasterGraphics_GS_INT8(i_raster); default: break; } throw new NyARException(); }
/** * Grayscale画像からisetファイルイメージを生成します。 * @param i_raster * @param srcdpi * @param dpis * @return */ public static NyARNftIsetFile genImageSet(INyARGrayscaleRaster i_raster, double srcdpi, double[] dpis) { NyARNftIsetFile.ReferenceImage[] rlist = new NyARNftIsetFile.ReferenceImage[dpis.Length]; rlist[0] = new NyARNftIsetFile.ReferenceImage(i_raster, srcdpi, srcdpi); for (int i = 1; i < dpis.Length; i++) { rlist[i] = new NyARNftIsetFile.ReferenceImage(i_raster, srcdpi, dpis[i]); } return(new NyARNftIsetFile(rlist)); }
public override bool labeling(INyARGrayscaleRaster i_raster, int i_th) { //配列初期化 this.label_stack.clear(); //ラベルの検出 bool ret = base.labeling(i_raster, i_th); //ソート this.label_stack.sortByArea(); return(ret); }
/** * この関数は、ラスタの指定点を基点に、輪郭線を抽出します。 * 開始点は、輪郭の一部である必要があります。 * 通常は、ラべリングの結果の上辺クリップとX軸エントリポイントを開始点として入力します。 * @param i_raster * 輪郭線を抽出するラスタを指定します。 * @param i_th * 輪郭とみなす暗点の敷居値を指定します。 * @param i_entry_x * 輪郭抽出の開始点です。 * @param i_entry_y * 輪郭抽出の開始点です。 * @param o_coord * 輪郭点を格納する配列を指定します。i_array_sizeよりも大きなサイズの配列が必要です。 * @return * 輪郭の抽出に成功するとtrueを返します。輪郭抽出に十分なバッファが無いと、falseになります。 * @ */ public bool getContour(INyARGrayscaleRaster i_raster, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord) { NyARIntSize s = i_raster.getSize(); //ラスタドライバの切り替え if (i_raster != this._ref_last_input_raster) { this._imdriver = (IRasterDriver)i_raster.createInterface(typeof(IRasterDriver)); this._ref_last_input_raster = i_raster; } return(this._imdriver.getContour(0, 0, s.w - 1, s.h - 1, i_entry_x, i_entry_y, i_th, o_coord)); }
/** * この関数は、i_rasterを操作するピクセルドライバインスタンスを生成します。 * @param i_raster * @return * @throws NyARException */ public static INyARGsRasterGraphics createDriver(INyARGrayscaleRaster i_raster) { switch (i_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: return(new NyARGsRasterGraphics_GS_INT8(i_raster)); default: break; } throw new NyARException(); }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { NyARIntSize size = this._ref_raster.getSize(); int bp = (l + t * size.w); int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); int src_ptr = t * size.w + l; int[] in_buf = (int[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int v; int[] out_buf = (int[])o_raster.getBuffer(); for (int y = t; y < b; y++) { int x = 0; for (x = pix_count - 1; x >= pix_mod_part; x--) { v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2; } for (; x >= 0; x -= 8) { v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; } bp += row_padding_dst; src_ptr += row_padding_src; } return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { v = in_buf[src_ptr++]; out_drv.setPixel(x, y, (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3); } } return; } }
public void copyTo(int i_left, int i_top, int i_skip, INyARGrayscaleRaster o_output) { Debug.Assert(this._raster.getSize().isInnerSize(i_left + o_output.getWidth() * i_skip, i_top + o_output.getHeight() * i_skip)); int[] input = (int[])this._raster.getBuffer(); switch (o_output.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] output = (int[])o_output.getBuffer(); NyARIntSize dest_size = o_output.getSize(); NyARIntSize src_size = this._raster.getSize(); int skip_src_y = (src_size.w - dest_size.w * i_skip) + src_size.w * (i_skip - 1); int pix_count = dest_size.w; int pix_mod_part = pix_count - (pix_count % 8); // 左上から1行づつ走査していく int pt_dst = 0; int pt_src = (i_top * src_size.w + i_left); for (int y = dest_size.h - 1; y >= 0; y -= 1) { int x; for (x = pix_count - 1; x >= pix_mod_part; x--) { output[pt_dst++] = input[pt_src]; pt_src += i_skip; } for (; x >= 0; x -= 8) { output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; } // スキップ pt_src += skip_src_y; } return; default: throw new NyARException(); } }
public void doFilter(int[] i_tone_table, INyARGrayscaleRaster i_output) { INyARGsPixelDriver outd = i_output.getGsPixelDriver(); INyARGsPixelDriver ind = this._raster.getGsPixelDriver(); NyARIntSize s = this._raster.getSize(); for (int y = s.h - 1; y >= 0; y--) { for (int x = s.w - 1; x >= 0; x--) { outd.setPixel(x, y, i_tone_table[ind.getPixel(x, y)]); } } }
public void doFilter(INyARGrayscaleRaster i_output) { INyARGsPixelDriver ind = this._raster.getGsPixelDriver(); INyARGsPixelDriver outd = i_output.getGsPixelDriver(); NyARIntSize s = this._raster.getSize(); for (int y = s.h - 1; y >= 0; y--) { for (int x = s.w - 1; x >= 0; x--) { outd.setPixel(x, y, 255 - ind.getPixel(x, y)); } } }
public void doFilter(int[] i_tone_table, INyARGrayscaleRaster i_output) { INyARGrayscaleRaster outd = i_output; INyARGrayscaleRaster ind = this._raster; NyARIntSize s = this._raster.getSize(); for (int y = s.h - 1; y >= 0; y--) { for (int x = s.w - 1; x >= 0; x--) { outd.setPixel(x, y, i_tone_table[ind.getPixel(x, y)]); } } }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); byte[] input = (byte[])this._raster.getBuffer(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = this._raster.getSize(); int skip_dst = (s.w - i_w); int skip_src = skip_dst * 3; int pix_count = i_w; int pix_mod_part = pix_count - (pix_count % 8); //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int pt_src = pt_dst * 3; for (int y = i_h - 1; y >= 0; y -= 1) { int x; for (x = pix_count - 1; x >= pix_mod_part; x--) { output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; } for (; x >= 0; x -= 8) { output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th ? 0 : 1; pt_src += 3; } //スキップ pt_src += skip_src; pt_dst += skip_dst; } return; }
public bool make_template(INyARGrayscaleRaster imageBW, int cx, int cy, double sd_thresh) { int ts1 = this._ts1; int ts2 = this._ts2; int xsize = imageBW.getWidth(); int ysize = imageBW.getHeight(); if (cy - ts1 < 0 || cy + ts2 >= ysize || cx - ts1 < 0 || cx + ts2 >= xsize) { return(false); } double ave = 0.0f; for (int j = -ts1; j <= ts2; j++) { // int ip = (cy+j)*xsize+(cx-ts1); for (int i = -ts1; i <= ts2; i++) { // ave += *(ip++); ave += imageBW.getPixel(cx + i, cy + j); } } ave /= (ts1 + ts2 + 1) * (ts1 + ts2 + 1); int tp = 0; double vlen1 = 0.0f; for (int j = -ts1; j <= ts2; j++) { for (int i = -ts1; i <= ts2; i++) { double p = (imageBW.getPixel(cx + i, cy + j)) - ave; this.img[tp] = p; vlen1 += p * p; tp++; } } if (vlen1 == 0.0f) { return(false); } if (vlen1 / ((ts1 + ts2 + 1) * (ts1 + ts2 + 1)) < sd_thresh * sd_thresh) { return(false); } this.vlen = Math.Sqrt(vlen1); return(true); }
public void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); BitmapData bm = this._raster.lockBitmap(); byte[] work = this._work; int[] output = (int[])i_gsraster.getBuffer(); NyARIntSize s = this._raster.getSize(); int th = i_th * 3; int skip_dst = (s.w - i_w); int skip_src = skip_dst * 4; int pix_count = i_w; int pix_mod_part = pix_count - (pix_count % 8); //左上から1行づつ走査していく long pt_dst = (i_t * s.w + i_l); long pt_src = pt_dst * 4 + (long)bm.Scan0; for (int y = i_h - 1; y >= 0; y -= 1) { int x; int p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p = Marshal.ReadInt32((IntPtr)pt_src); output[pt_dst++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) <= th ? 0 : 1; pt_src += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)pt_src, work, 0, 32); output[pt_dst] = (work[0] + work[1] + work[2]) <= th ? 0 : 1; output[pt_dst + 1] = (work[4] + work[5] + work[6]) <= th ? 0 : 1; output[pt_dst + 2] = (work[8] + work[9] + work[10]) <= th ? 0 : 1; output[pt_dst + 3] = (work[12] + work[13] + work[14]) <= th ? 0 : 1; output[pt_dst + 4] = (work[16] + work[17] + work[18]) <= th ? 0 : 1; output[pt_dst + 5] = (work[20] + work[21] + work[22]) <= th ? 0 : 1; output[pt_dst + 6] = (work[24] + work[25] + work[26]) <= th ? 0 : 1; output[pt_dst + 7] = (work[28] + work[29] + work[30]) <= th ? 0 : 1; pt_src += 32; pt_dst += 8; } //スキップ pt_src += skip_src; pt_dst += skip_dst; } this._raster.unlockBitmap(); return; }
public static IRasterDriver createDriver(INyARGrayscaleRaster i_ref_raster) { switch (i_ref_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: case NyARBufferType.INT1D_BIN_8: return new NyARContourPickup_BIN_GS8(i_ref_raster); default: if (i_ref_raster is NyARContourPickup_GsReader) { return new NyARContourPickup_GsReader((INyARGrayscaleRaster)i_ref_raster); } break; } throw new NyARException(); }
public static INyARHistogramFromRaster createInstance(INyARGrayscaleRaster i_raster) { switch(i_raster.getBufferType()){ case NyARBufferType.INT1D_GRAY_8: case NyARBufferType.INT1D_BIN_8: return new NyARHistogramFromRaster_INTGS8(i_raster); default: if(i_raster is INyARGrayscaleRaster){ return new NyARHistogramFromRaster_AnyGs((INyARGrayscaleRaster)i_raster); } if (i_raster is INyARRgbRaster) { return new NyARHistogramFromRaster_AnyRgb((INyARRgbRaster)i_raster); } break; } throw new NyARException(); }
public void doFilter(int i_hist_interval, INyARGrayscaleRaster i_output) { //ヒストグラムを得る NyARHistogram hist = this._histogram; this._histdrv.createHistogram(i_hist_interval, hist); //変換テーブルを作成 int hist_total = this._histogram.total_of_data; int min = hist.getMinData(); int hist_size = this._histogram.length; int sum = 0; for (int i = 0; i < hist_size; i++) { sum += hist.data[i]; this._hist[i] = (int)((sum - min) * (hist_size - 1) / ((hist_total - min))); } //変換 this._tone_table.doFilter(this._hist, i_output); return; }
/** * ラスタから画素ドライバを構築します。構築したラスタドライバには、i_ref_rasterをセットします。 * @param i_ref_raster * @return * @ */ public static INyARGsPixelDriver createDriver(INyARGrayscaleRaster i_ref_raster) { INyARGsPixelDriver ret; switch (i_ref_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: case NyARBufferType.INT1D_BIN_8: ret = new NyARGsPixelDriver_INT1D_GRAY_8(); break; default: //RGBRasterインタフェイスがある場合 if (i_ref_raster is INyARRgbRaster) { ret = new NyARGsPixelDriver_RGBX((INyARRgbRaster)i_ref_raster); break; } throw new NyARException(); } ret.switchRaster(i_ref_raster); return ret; }
public void doFilter(int i_h, INyARGrayscaleRaster i_gsraster) { NyARIntSize s = this._raster.getSize(); this.doFilter(0, 0, s.w, s.h, i_h, i_gsraster); }
public NyARContourPickup_GsReader(INyARGrayscaleRaster i_ref_raster) { this._ref_raster = i_ref_raster; }
/** * この関数は、ラスタの指定点を基点に、輪郭線を抽出します。 * 開始点は、輪郭の一部である必要があります。 * 通常は、ラべリングの結果の上辺クリップとX軸エントリポイントを開始点として入力します。 * @param i_raster * 輪郭線を抽出するラスタを指定します。 * @param i_th * 輪郭とみなす暗点の敷居値を指定します。 * @param i_entry_x * 輪郭抽出の開始点です。 * @param i_entry_y * 輪郭抽出の開始点です。 * @param o_coord * 輪郭点を格納する配列を指定します。i_array_sizeよりも大きなサイズの配列が必要です。 * @return * 輪郭の抽出に成功するとtrueを返します。輪郭抽出に十分なバッファが無いと、falseになります。 * @ */ public bool getContour(INyARGrayscaleRaster i_raster, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord) { NyARIntSize s = i_raster.getSize(); //ラスタドライバの切り替え if (i_raster != this._ref_last_input_raster) { this._imdriver = (IRasterDriver)i_raster.createInterface(typeof(IRasterDriver)); this._ref_last_input_raster = i_raster; } return this._imdriver.getContour(0, 0, s.w - 1, s.h - 1, i_entry_x, i_entry_y, i_th, o_coord); }
public void doFilter(INyARGrayscaleRaster i_output) { Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); NyARIntSize size = this._raster.getSize(); int[] in_ptr = (int[])this._raster.getBuffer(); switch (this._raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_ptr = (int[])i_output.getBuffer(); int width = size.w; int idx = 0; int idx2 = width; int fx, fy; int mod_p = (width - 2) - (width - 2) % 8; for (int y = size.h - 2; y >= 0; y--) { int p00 = in_ptr[idx++]; int p10 = in_ptr[idx2++]; int p01, p11; int x = width - 2; for (; x >= mod_p; x--) { p01 = in_ptr[idx++]; p11 = in_ptr[idx2++]; fx = p11 - p00; fy = p10 - p01; out_ptr[idx - 2] = ((fx < 0 ? -fx : fx) + (fy < 0 ? -fy : fy)) >> 1; p00 = p01; p10 = p11; } for (; x >= 0; x -= 4) { p01 = in_ptr[idx++]; p11 = in_ptr[idx2++]; fx = p11 - p00; fy = p10 - p01; out_ptr[idx - 2] = ((fx < 0 ? -fx : fx) + (fy < 0 ? -fy : fy)) >> 1; p00 = p01; p10 = p11; p01 = in_ptr[idx++]; p11 = in_ptr[idx2++]; fx = p11 - p00; fy = p10 - p01; out_ptr[idx - 2] = ((fx < 0 ? -fx : fx) + (fy < 0 ? -fy : fy)) >> 1; p00 = p01; p10 = p11; p01 = in_ptr[idx++]; p11 = in_ptr[idx2++]; fx = p11 - p00; fy = p10 - p01; out_ptr[idx - 2] = ((fx < 0 ? -fx : fx) + (fy < 0 ? -fy : fy)) >> 1; p00 = p01; p10 = p11; p01 = in_ptr[idx++]; p11 = in_ptr[idx2++]; fx = p11 - p00; fy = p10 - p01; out_ptr[idx - 2] = ((fx < 0 ? -fx : fx) + (fy < 0 ? -fy : fy)) >> 1; p00 = p01; p10 = p11; } out_ptr[idx - 1] = 0; } for (int x = width - 1; x >= 0; x--) { out_ptr[idx++] = 0; } return; default: //ANY未対応 throw new NyARException(); } }
/** * この関数は、ラスタの指定点を基点に、画像の特定の範囲内から輪郭線を抽出します。 * 開始点は、輪郭の一部である必要があります。 * 通常は、ラべリングの結果の上辺クリップとX軸エントリポイントを開始点として入力します。 * @param i_raster * 輪郭線を抽出するラスタを指定します。 * @param i_area * 輪郭線の抽出範囲を指定する矩形。i_rasterのサイズ内である必要があります。 * @param i_th * 輪郭とみなす暗点の敷居値を指定します。 * @param i_entry_x * 輪郭抽出の開始点です。 * @param i_entry_y * 輪郭抽出の開始点です。 * @param o_coord * 輪郭点を格納するオブジェクトを指定します。 * @return * 輪郭線がo_coordの長さを超えた場合、falseを返します。 * @ */ public bool getContour(INyARGrayscaleRaster i_raster, NyARIntRect i_area, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord) { //ラスタドライバの切り替え if (i_raster != this._ref_last_input_raster) { this._imdriver = (IRasterDriver)i_raster.createInterface(typeof(IRasterDriver)); this._ref_last_input_raster = i_raster; } return this._imdriver.getContour(i_area.x, i_area.y, i_area.x + i_area.w - 1, i_area.h + i_area.y - 1, i_entry_x, i_entry_y, i_th, o_coord); }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { byte[] work = this._work; BitmapData bm = this._ref_raster.lockBitmap(); NyARIntSize size = this._ref_raster.getSize(); int bp = (l + t * size.w) * 4 + (int)bm.Scan0; int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst * 4; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); int dst_ptr = t * size.w + l; // in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); for (int y = t; y < b; y++) { int x = 0; for (x = pix_count - 1; x >= pix_mod_part; x--) { int p = Marshal.ReadInt32((IntPtr)bp); out_buf[dst_ptr++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) / 3; bp += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)bp, work, 0, 32); out_buf[dst_ptr++] = (work[0] + work[1] + work[2]) / 3; out_buf[dst_ptr++] = (work[4] + work[5] + work[6]) / 3; out_buf[dst_ptr++] = (work[8] + work[9] + work[10]) / 3; out_buf[dst_ptr++] = (work[12] + work[13] + work[14]) / 3; out_buf[dst_ptr++] = (work[16] + work[17] + work[18]) / 3; out_buf[dst_ptr++] = (work[20] + work[21] + work[22]) / 3; out_buf[dst_ptr++] = (work[24] + work[25] + work[26]) / 3; out_buf[dst_ptr++] = (work[28] + work[29] + work[30]) / 3; bp += 32; } bp += row_padding_src; dst_ptr += row_padding_dst; } this._ref_raster.unlockBitmap(); return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { int p = Marshal.ReadInt32((IntPtr)bp); out_drv.setPixel(x, y, (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) / 3); bp += 4; } bp += row_padding_src; } this._ref_raster.unlockBitmap(); return; } }
/** * 画像ドライバに依存するインスタンスの生成。 * 継承クラスで上書きする。 * @param s * @ */ protected void initResource(NyARIntSize s) { this._gs_raster = new NyARGrayscaleRaster(s.w, s.h, NyARBufferType.INT1D_GRAY_8, true); }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { Color32[] c=(Color32[])(this._ref_raster.getBuffer()); NyARIntSize size = this._ref_raster.getSize(); int src = (l + t * size.w) * 4; int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst * 4; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); // in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); int dst_ptr; if(this._is_inverse){ dst_ptr=(h-1-t) * size.w + l; row_padding_dst-=size.w*2; }else{ dst_ptr=t * size.w + l; } for (int y = t; y < b; y++) { int x = 0; Color32 p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; } for (; x >= 0; x -= 8) { p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; } dst_ptr+=row_padding_dst; src += row_padding_src; } return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { Color32 p = c[src++]; out_drv.setPixel(x, y,(p.r+p.g+p.b) / 3); } src += row_padding_src; } return; } }
/** * Initialize call back handler. */ public void init(INyARGrayscaleRaster i_raster, INyIdMarkerData i_prev_data) { this.marker_data = null; this._prev_data = i_prev_data; this._ref_raster = i_raster; }
public NyARGsToneTableFilter(INyARGrayscaleRaster i_raster) { this._tone_filter = NyARGsFilterFactory.createCustomToneTableFilter(i_raster); }
public abstract void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster);
public void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); BitmapData bm = this._raster.lockBitmap(); byte[] work = this._work; int[] output = (int[])i_gsraster.getBuffer(); NyARIntSize s = this._raster.getSize(); int th = i_th * 3; int skip_dst = (s.w - i_w); int skip_src = skip_dst * 4; int pix_count = i_w; int pix_mod_part = pix_count - (pix_count % 8); //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int pt_src = pt_dst * 4+(int)bm.Scan0; for (int y = i_h - 1; y >= 0; y -= 1) { int x; int p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p = Marshal.ReadInt32((IntPtr)pt_src); output[pt_dst++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) <= th ? 0 : 1; pt_src += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)pt_src, work, 0, 32); output[pt_dst ] = (work[0]+work[1]+work[2]) <= th ? 0 : 1; output[pt_dst+1] = (work[4] + work[5] + work[6]) <= th ? 0 : 1; output[pt_dst+2] = (work[8] + work[9] + work[10]) <= th ? 0 : 1; output[pt_dst+3] = (work[12] + work[13] + work[14]) <= th ? 0 : 1; output[pt_dst+4] = (work[16] + work[17] + work[18]) <= th ? 0 : 1; output[pt_dst+5] = (work[20] + work[21] + work[22]) <= th ? 0 : 1; output[pt_dst+6] = (work[24] + work[25] + work[26]) <= th ? 0 : 1; output[pt_dst+7] = (work[28] + work[29] + work[30]) <= th ? 0 : 1; pt_src += 32; pt_dst += 8; } //スキップ pt_src += skip_src; pt_dst += skip_dst; } this._raster.unlockBitmap(); return; }
public NyARHistogramFromRaster_AnyGs(INyARGrayscaleRaster i_raster) { this._gsr = i_raster; }
public void convert(INyARGrayscaleRaster i_raster) { NyARIntSize s = this._ref_raster.getSize(); this.convertRect(0, 0, s.w, s.h, i_raster); }
public NyARGsRobertsFilter_GS8(INyARGrayscaleRaster i_raster) { this._raster = i_raster; }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); short[] input = (short[])this._raster.getBuffer(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.getSize(); int skip_dst = (s.w - i_w); int skip_src = skip_dst; int pix_count = i_w; int pix_mod_part = pix_count - (pix_count % 8); //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int pt_src = pt_dst; for (int y = i_h - 1; y >= 0; y -= 1) { int x, v; for (x = pix_count - 1; x >= pix_mod_part; x--) { v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; } for (; x >= 0; x -= 8) { v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th ? 0 : 1; } //スキップ pt_src += skip_src; pt_dst += skip_dst; } return; }
public void line(double i_a, INyARGrayscaleRaster i_output) { this.line(0, 0, i_a, i_output); }