public BinaryHierarchicalNode(int id, FreakFeaturePoint i_feature, bool i_is_leaf, FreakMatchPointSetStack.Item[] i_reserv_index, BinaryHierarchicalNode[] i_children)
 {
     this.is_leaf      = i_is_leaf;
     this.id           = id;
     this.reserv_index = i_reserv_index;
     if (i_feature != null)
     {
         this.center = i_feature;
     }
     else
     {
         this.center = null;
     }
     this.children = i_children;
 }
        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));
        }
        /**
         * Condition four 2D points such that the mean is zero and the standard
         * deviation is sqrt(2).
         */
        private static bool condition4Points2d(NyARDoublePoint2d xp1, NyARDoublePoint2d xp2, NyARDoublePoint2d xp3,
                                               NyARDoublePoint2d xp4, double[] mus, // ms[2],sの3要素
                                               FreakFeaturePoint x1, FreakFeaturePoint x2, FreakFeaturePoint x3, FreakFeaturePoint x4)
        {
            double[] d1 = new double[2], d2 = new double[2], d3 = new double[2], d4 = new double[2];

            mus[0] = (x1.x + x2.x + x3.x + x4.x) / 4;
            mus[1] = (x1.y + x2.y + x3.y + x4.y) / 4;

            d1[0] = x1.x - mus[0];
            d1[1] = x1.y - mus[1];
            d2[0] = x2.x - mus[0];
            d2[1] = x2.y - mus[1];
            d3[0] = x3.x - mus[0];
            d3[1] = x3.y - mus[1];
            d4[0] = x4.x - mus[0];
            d4[1] = x4.y - mus[1];

            double ds1 = (double)Math.Sqrt(d1[0] * d1[0] + d1[1] * d1[1]);
            double ds2 = (double)Math.Sqrt(d2[0] * d2[0] + d2[1] * d2[1]);
            double ds3 = (double)Math.Sqrt(d3[0] * d3[0] + d3[1] * d3[1]);
            double ds4 = (double)Math.Sqrt(d4[0] * d4[0] + d4[1] * d4[1]);
            double d   = (ds1 + ds2 + ds3 + ds4) / 4;

            if (d == 0)
            {
                return(false);
            }

            double s = (double)((1 / d) * SQRT2);

            mus[2] = s;
            xp1.x  = d1[0] * s;
            xp1.y  = d1[1] * s;
            xp2.x  = d2[0] * s;
            xp2.y  = d2[1] * s;
            xp3.x  = d3[0] * s;
            xp3.y  = d3[1] * s;
            xp4.x  = d4[0] * s;
            xp4.y  = d4[1] * s;

            return(true);
        }
예제 #4
0
        /**
         * Extract the descriptors for all the feature points.
         */
        private void ExtractFREAK84(FreakFeaturePointStack store,
                                    GaussianScaleSpacePyramid pyramid, DogFeaturePointStack points,
                                    double[] points_ring0, double[] points_ring1, double[] points_ring2,
                                    double[] points_ring3, double[] points_ring4, double[] points_ring5,
                                    double sigma_center, double sigma_ring0, double sigma_ring1,
                                    double sigma_ring2, double sigma_ring3, double sigma_ring4,
                                    double sigma_ring5, double expansion_factor)
        {
            // ASSERT(pyramid, "Pyramid is NULL");
            // ASSERT(store.size() == points.size(),
            // "Feature store has not been allocated");
            for (int i = 0; i < points.getLength(); i++)
            {
                FreakFeaturePoint sp = store.prePush();
                if (sp == null)
                {
                    prepush_wawning();
                    break;
                }
                DogFeaturePoint pt = points.getItem(i);
                if (!ExtractFREAK84(sp.descripter,
                                    pyramid, pt, points_ring0, points_ring1,
                                    points_ring2, points_ring3, points_ring4, points_ring5,
                                    sigma_center, sigma_ring0, sigma_ring1, sigma_ring2,
                                    sigma_ring3, sigma_ring4, sigma_ring5, expansion_factor

                                    ))
                {
                    store.pop();
                    continue;
                }
                sp.angle  = pt.angle;
                sp.x      = pt.x;
                sp.y      = pt.y;
                sp.scale  = pt.sigma;
                sp.maxima = pt.score > 0;
                //			store.point(num_points).set(points[i]);
            }
        }
예제 #5
0
        private BinaryHierarchicalNode build(FreakMatchPointSetStack.Item[] features, FreakFeaturePoint i_center, int[] i_indices, int num_indices)
        {
            int t = mBinarykMedoids.k();

            if (t < this.mMinFeaturePerNode)
            {
                t = this.mMinFeaturePerNode;
            }
            if (num_indices <= t)
            {
                FreakMatchPointSetStack.Item[] index = intArray2FeaturePointArray(features, i_indices);
                return(new BinaryHierarchicalNode(this.nextNodeId(), i_center, true, index, null));
            }
            SortedDictionary <int, List <int> > cluster_map = new SortedDictionary <int, List <int> >();

            // Perform clustering
            // Get a list of features for each cluster center
            int[] assignment = this.mBinarykMedoids.assign(features, i_indices, num_indices);

            // ASSERT(assignment.size() == num_indices, "Assignment size wrong");
            for (int i = 0; i < num_indices; i++)
            {
                // ASSERT(assignment[i] != -1, "Assignment is invalid");
                // ASSERT(assignment[i] < num_indices, "Assignment out of range");
                // ASSERT(indices[assignment[i]] < num_features, "Assignment out of range");

                List <int> li;
                if (!cluster_map.ContainsKey(i_indices[assignment[i]]))
                {
                    li = new List <int>();
                    cluster_map.Add(i_indices[assignment[i]], li);
                }
                else
                {
                    li = cluster_map[i_indices[assignment[i]]];
                }
                li.Add(i_indices[i]);
            }

            // If there is only 1 cluster then make this node a leaf
            if (cluster_map.Count == 1)
            {
                FreakMatchPointSetStack.Item[] index = intArray2FeaturePointArray(features, i_indices);
                return(new BinaryHierarchicalNode(this.nextNodeId(), i_center, true, index, null));
            }
            int n = 0;

            BinaryHierarchicalNode[] cl = new BinaryHierarchicalNode[cluster_map.Count];
            // Create a new node for each cluster center
            foreach (KeyValuePair <int, List <int> > l in cluster_map)
            {
                int first = l.Key;

                // Recursively build the tree
                int[] v = ArrayUtils.toIntArray_impl(l.Value, 0, l.Value.Count);
                cl[n] = this.build(features, features[first], v, v.Length);
                n++;
            }
            return(new BinaryHierarchicalNode(this.nextNodeId(), i_center, false, null, cl));
        }
예제 #6
0
        private int vote(FeaturePairStack i_point_pair, int i_center_x, int i_center_y, SubBinLocation[] i_sub_bin_locations)
        {
            int size = i_point_pair.getLength();


            int num_features_that_cast_vote = 0;

            for (int i = 0; i < size; i++)
            {
                //mapCorrespondence(r,i_point_pair.getItem(i),i_center_x,i_center_y);
                double rx, ry, rangle, rscale;
                {
                    FreakFeaturePoint ins  = i_point_pair.getItem(i).query;
                    FreakFeaturePoint ref_ = i_point_pair.getItem(i).ref_;

                    //angle
                    rangle = ins.angle - ref_.angle;
                    // Map angle to (-pi,pi]
                    if (rangle <= -PI)
                    {
                        rangle += (2 * PI);
                    }
                    else if (rangle > PI)
                    {
                        rangle -= (2 * PI);
                    }

                    double scale = SafeDivision(ins.scale, ref_.scale);
                    double c     = (scale * Math.Cos(rangle));
                    double s     = (scale * Math.Sin(rangle));

                    //scale
                    rscale = (double)(Math.Log(scale) * this.mScaleOneOverLogK);
                    //x,y
                    rx = c * i_center_x - s * i_center_y + (ins.x - (c * ref_.x - s * ref_.y));
                    ry = s * i_center_x + c * i_center_y + (ins.y - (s * ref_.x + c * ref_.y));
                    // Check that the vote is within range
                    if (rx < mMinX || rx >= mMaxX || ry < mMinY || ry >= mMaxY ||
                        rangle <= -PI || rangle > PI ||
                        rscale < mMinScale || rscale >= mMaxScale)
                    {
                        continue;
                    }
                }
                // Compute the bin location
                SubBinLocation sub_bin = i_sub_bin_locations[num_features_that_cast_vote];
                mapVoteToBin(sub_bin, rx, ry, rangle, rscale);
                int binX     = (int)Math.Floor(sub_bin.x - 0.5f);
                int binY     = (int)Math.Floor(sub_bin.y - 0.5f);
                int binScale = (int)Math.Floor(sub_bin.scale - 0.5f);
                int binAngle = ((int)Math.Floor(sub_bin.angle - 0.5f) + mNumAngleBins) % mNumAngleBins;

                // Check that we can voting to all 16 bin locations
                if (binX < 0 || (binX + 1) >= mNumXBins || binY < 0 ||
                    (binY + 1) >= mNumYBins || binScale < 0 ||
                    (binScale + 1) >= mNumScaleBins)
                {
                    continue;
                }
                sub_bin.index = i;
                num_features_that_cast_vote++;
                this.votemap.vote16(binX, binY, binAngle, binScale, 1);
            }
            return(num_features_that_cast_vote);
        }