public static NyARNftFsetFile genFeatureSet(NyARNftIsetFile i_iset_file, int i_occupancy_size, double i_max_sim_th, double i_min_sim_th, double i_sd_th) { NyARNftIsetFile.ReferenceImage[] items = i_iset_file.items; NyARNftFsetFile.NyAR2FeaturePoints[] points = new NyARNftFsetFile.NyAR2FeaturePoints[items.Length]; for (int i = 0; i < items.Length; i++) { NyARNftIsetFile.ReferenceImage rimg = items[i]; //MAX-dpiとMIN-dpiを計算 double max_dpi = Double.MaxValue; double min_dpi = rimg.dpi * 0.5; for (int j = 0; j < items.Length; j++) { if (rimg.dpi < items[j].dpi && max_dpi > items[j].dpi) { max_dpi = items[j].dpi; } if (rimg.dpi > items[j].dpi && min_dpi < items[j].dpi) { min_dpi = items[j].dpi; } } if (max_dpi == Double.MaxValue) { max_dpi = rimg.dpi * 2; } else { max_dpi = rimg.dpi * 0.8 + max_dpi * 0.2; } //MIN-dpiの計算(一番近い小さい値 points[i] = new NyARNftFsetFile.NyAR2FeaturePoints(rimg, i_occupancy_size, i_max_sim_th, i_min_sim_th, i_sd_th, max_dpi, min_dpi, i); } return(new NyARNftFsetFile(points)); }
/** * 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 IsetFileDataParserV5(NyARNftIsetFile.ReferenceImage i_src_img, float[] i_sub_dpis) { this.image = ArrayUtils.toByteArray_impl(i_src_img.img); this.image_dpi_x = (float)i_src_img.dpi; this.image_dpi_y = (float)i_src_img.dpi; this.image_size = new NyARIntSize(i_src_img.width, i_src_img.height); this.image_unit = 1; this.sub_dpis = i_sub_dpis; this.num_of_iset = i_sub_dpis.Length + 1; return; }
public IsetFileDataParserV5Raw(NyARNftIsetFile.ReferenceImage i_src_img, float[] i_sub_dpis) { this.image_width = i_src_img.width; this.image_height = i_src_img.height; this.image = ArrayUtils.toByteArray_impl(i_src_img.img); this.dpis = new float[i_sub_dpis.Length + 1]; this.dpis[0] = (float)i_src_img.dpi; for (int i = 0; i < i_sub_dpis.Length; i++) { this.dpis[i + 1] = i_sub_dpis[i]; } return; }
public NyAR2FeaturePoints(NyARNftIsetFile.ReferenceImage i_refimg, int i_occ_size, double i_max_sim_thresh, double i_min_sim_thresh, double i_sd_th, double i_max_dpi, double i_min_dpi, int i_scale) { NyARSurfaceFeatureMap fmap = new NyARSurfaceFeatureMap( i_refimg, NyARSurfaceTracker.AR2_DEFAULT_TS1 * NyARTemplatePatchImage.AR2_TEMP_SCALE, NyARSurfaceTracker.AR2_DEFAULT_TS2 * NyARTemplatePatchImage.AR2_TEMP_SCALE, AR2_DEFAULT_GEN_FEATURE_MAP_SEARCH_SIZE1, AR2_DEFAULT_GEN_FEATURE_MAP_SEARCH_SIZE2, AR2_DEFAULT_MAX_SIM_THRESH2, AR2_DEFAULT_SD_THRESH2); this.coord = fmap.ar2SelectFeature(i_refimg.dpi, AR2_DEFAULT_GEN_FEATURE_MAP_SEARCH_SIZE2, i_occ_size, i_max_sim_thresh, i_min_sim_thresh, i_sd_th); this.maxdpi = i_max_dpi; this.mindpi = i_min_dpi; this.scale = i_scale; return; }
public static NyARNftFreakFsetFile genFeatureSet3(NyARNftIsetFile i_iset_file) { int max_features = 500; DogFeaturePointStack _dog_feature_points = new DogFeaturePointStack(max_features); FreakFeaturePointStack query_keypoint = new FreakFeaturePointStack(max_features); // List <NyARNftFreakFsetFile.RefDataSet> refdataset = new List <NyARNftFreakFsetFile.RefDataSet>(); List <NyARNftFreakFsetFile.ImageInfo> imageinfo = new List <NyARNftFreakFsetFile.ImageInfo>(); for (int ii = 0; ii < i_iset_file.items.Length; ii++) { NyARNftIsetFile.ReferenceImage rimg = i_iset_file.items[ii]; FREAKExtractor mFeatureExtractor = new FREAKExtractor(); int octerves = BinomialPyramid32f.octavesFromMinimumCoarsestSize(rimg.width, rimg.height, 8); BinomialPyramid32f _pyramid = new BinomialPyramid32f(rimg.width, rimg.height, octerves, 3); DoGScaleInvariantDetector _dog_detector = new DoGScaleInvariantDetector(rimg.width, rimg.height, octerves, 3, 3, 4, max_features); //RefDatasetの作成 _pyramid.build(NyARGrayscaleRaster.createInstance(rimg.width, rimg.height, NyARBufferType.INT1D_GRAY_8, rimg.img)); // Detect feature points _dog_feature_points.clear(); _dog_detector.detect(_pyramid, _dog_feature_points); // Extract features query_keypoint.clear(); mFeatureExtractor.extract(_pyramid, _dog_feature_points, query_keypoint); for (int i = 0; i < query_keypoint.getLength(); i++) { FreakFeaturePoint ffp = query_keypoint.getItem(i); NyARNftFreakFsetFile.RefDataSet rds = new NyARNftFreakFsetFile.RefDataSet(); rds.pageNo = 1; rds.refImageNo = ii; rds.coord2D.setValue(ffp.x, ffp.y); rds.coord3D.setValue((ffp.x + 0.5f) / rimg.dpi * 25.4f, ((rimg.height - 0.5f) - ffp.y) / rimg.dpi * 25.4f); rds.featureVec.angle = ffp.angle; rds.featureVec.maxima = ffp.maxima ? 1 : 0; rds.featureVec.scale = ffp.scale; ffp.descripter.getValueLe(rds.featureVec.v); refdataset.Add(rds); } imageinfo.Add(new NyARNftFreakFsetFile.ImageInfo(rimg.width, rimg.height, ii)); } NyARNftFreakFsetFile.PageInfo[] pi = new NyARNftFreakFsetFile.PageInfo[1]; pi[0] = new NyARNftFreakFsetFile.PageInfo(1, imageinfo.ToArray()); return(new NyARNftFreakFsetFile(refdataset.ToArray(), pi)); }
/** * 元ar2GenTemplate関数。 * 与えられた座標を中心に、テンプレート画像を生成する。 * 座標は観察座標点。 * @param i_x * @param i_y * @param i_scale * @param o_template * @return * @throws NyARException */ public void makeFromReferenceImage(double i_x, double i_y, NyARDoubleMatrix44 i_ref_ctrans, INyARCameraDistortionFactor i_ref_dist_factor, NyARNftIsetFile.ReferenceImage i_source) { int[] img = this.img; int img1_ptr = 0; int k = 0; int sum2 = 0; int sum = 0; NyARDoublePoint2d ideal = this.__in; for (int j = -(this.yts); j <= this.yts; j++) { for (int i = -(this.xts); i <= this.xts; i++) { i_ref_dist_factor.observ2Ideal(i_x + i * AR2_TEMP_SCALE, i_y + j * AR2_TEMP_SCALE, ideal); double ideal_x = ideal.x; double ideal_y = ideal.y; //ar2ScreenCoord2MarkerCoord(in.x,in.y,i_ref_ctrans,in);の展開 double c11 = i_ref_ctrans.m20 * ideal_x - i_ref_ctrans.m00; double c12 = i_ref_ctrans.m21 * ideal_x - i_ref_ctrans.m01; double c21 = i_ref_ctrans.m20 * ideal_y - i_ref_ctrans.m10; double c22 = i_ref_ctrans.m21 * ideal_y - i_ref_ctrans.m11; double b1 = i_ref_ctrans.m03 - i_ref_ctrans.m23 * ideal_x; double b2 = i_ref_ctrans.m13 - i_ref_ctrans.m23 * ideal_y; double m = c11 * c22 - c12 * c21; //public int ar2GetImageValue(double sx, double sy) throws NyARExceptionの展開 { int ix = (int)((((c22 * b1 - c12 * b2) / m) * i_source.dpi / 25.4f) + 0.5); int iy = (int)((i_source.height - (((c11 * b2 - c21 * b1) / m) * i_source.dpi) / 25.4f) + 0.5); //座標計算と値取得は分けよう。 if (ix < 0 || ix >= i_source.width || iy < 0 || iy >= i_source.height) { img[img1_ptr] = AR2_TEMPLATE_NULL_PIXEL; } else { int ret = img[img1_ptr] = i_source.img[iy * i_source.width + ix]; sum2 += ret * ret; sum += ret; k++; } //byte値はint化 } img1_ptr++; } } int vlen = sum2 - sum * sum / k; this.vlen = (int)Math.Sqrt((double)(vlen)); this.sum_of_img = sum; this.valid_pixels = k; return; }
/** * @param i_raster * @param ts1 * @param ts2 * @param search_size1 * @param search_size2 * @param max_sim_thresh * @param sd_thresh * @return * @throws InterruptedException */ public NyARSurfaceFeatureMap(NyARNftIsetFile.ReferenceImage i_refimage, int ts1, int ts2, int search_size1, int search_size2, double max_sim_thresh, double sd_thresh) { int w = i_refimage.width; int h = i_refimage.height; //アクセス用のテンポラリラスタ TemplateSourceRaster refraster = new TemplateSourceRaster(w, h, i_refimage.img); this._refimage = refraster; this.fimage = new double[w * h]; this._tmpimg = new TemplateImage_O1(ts1, ts2); double max; double[] tmp_fimg2 = new double[w * h]; int fp2 = 0; //fimegeに数値を設定。エッジは-1 for (int i = 0; i < w; i++) { tmp_fimg2[fp2++] = -1.0f; } for (int j = 1; j < h - 1; j++) { tmp_fimg2[fp2++] = -1.0f; for (int i = 1; i < w - 1; i++) { double dx = (refraster.getPixel(i + 1, j - 1) - refraster.getPixel(i - 1, j - 1) + refraster.getPixel(i + 1, j) - refraster.getPixel(i - 1, j) + refraster.getPixel(i + 1, j + 1) - refraster.getPixel(i - 1, j + 1)) / (double)(3 * 256); double dy = (refraster.getPixel(i + 1, j + 1) - refraster.getPixel(i + 1, j - 1) + refraster.getPixel(i, j + 1) - refraster.getPixel(i, j - 1) + refraster.getPixel(i - 1, j + 1) - refraster.getPixel(i - 1, j - 1)) / (double)(3 * 256); tmp_fimg2[fp2++] = (double)Math.Sqrt((dx * dx + dy * dy) / (double)2.0f); } tmp_fimg2[fp2++] = -1.0f; } for (int i = 0; i < w; i++) { tmp_fimg2[fp2++] = -1.0f; } int[] hist = new int[1000]; for (int i = 0; i < hist.Length; i++) { hist[i] = 0; } fp2 = w + 1;//(1,1の位置) for (int j = 1; j < h - 1; j++) { for (int i = 1; i < w - 1; i++) { if (tmp_fimg2[fp2] > tmp_fimg2[fp2 - 1] && tmp_fimg2[fp2] > tmp_fimg2[fp2 + 1] && tmp_fimg2[fp2] > tmp_fimg2[fp2 - w] && tmp_fimg2[fp2] > tmp_fimg2[fp2 + w]) { int k = (int)(tmp_fimg2[fp2] * 1000.0f); if (k > 999) { k = 999; } if (k < 0) { k = 0; } hist[k]++; } fp2++; } fp2 += 2; } int sum_of_hist = 0; int k2 = 0; for (int i = 999; i >= 0; i--) { sum_of_hist += hist[i]; if ((double)sum_of_hist / (double)(w * h) >= 0.02f) { k2 = i; break; } } double[] fimg = this.fimage; int fp = 0; fp2 = 0; for (int i = 0; i < w; i++) { fimg[fp++] = 1.0f; fp2++; } TemplateImage_O1 ti = this._tmpimg; for (int j = 1; j < h - 1; j++) { //長時間かかるループなので割り込み監視はブレーク可能。 // if (Thread.interrupted()) // { // throw new InterruptedException(); // } fimg[fp++] = 1.0f; fp2++; for (int i = 1; i < w - 1; i++) { if (tmp_fimg2[fp2] <= tmp_fimg2[fp2 - 1] || tmp_fimg2[fp2] <= tmp_fimg2[fp2 + 1] || tmp_fimg2[fp2] <= tmp_fimg2[fp2 - w] || tmp_fimg2[fp2] <= tmp_fimg2[fp2 + w]) { fimg[fp++] = 1.0f; fp2++; continue; } if ((int)(tmp_fimg2[fp2] * 1000) < k2) { fimg[fp++] = 1.0f; fp2++; continue; } if (!ti.make_template(refraster, i, j, sd_thresh)) { fimg[fp++] = 1.0f; fp2++; continue; } max = -1.0f; for (int jj = -search_size1; jj <= search_size1; jj++) { for (int ii = -search_size1; ii <= search_size1; ii++) { //円を作ってるね。 if (ii * ii + jj * jj <= search_size2 * search_size2) { continue; } double sim = ti.get_similarity(refraster, i + ii, j + jj); if (sim > max) { max = sim; if (max > max_sim_thresh) { break; } } } if (max > max_sim_thresh) { break; } } fimg[fp++] = (double)max; fp2++; } fimg[fp++] = 1.0f; fp2++; } for (int i = 0; i < w; i++) { fimg[fp++] = 1.0f; fp2++; } return; }