/// <summary> /// Build descriptor vector for each interest point in the supplied list /// </summary> /// <param name="img"></param> /// <param name="ipts"></param> /// <param name="upright"></param> public void DescribeInterestPoints(List <IPoint2> ipts, bool upright, bool extended, IntegralImage img) { if (ipts.Count == 0) { return; } this.img = img; foreach (IPoint2 ip in ipts) { // determine descriptor size if (extended) { ip.descriptorLength = 128; } else { ip.descriptorLength = 64; } // if we want rotation invariance get the orientation if (!upright) { GetOrientation(ip); } // Extract SURF descriptor GetDescriptor(ip, upright, extended); } }
/// <summary> /// Constructor with parameters /// </summary> /// <param name="thresh"></param> /// <param name="octaves"></param> /// <param name="init_sample"></param> /// <param name="img"></param> public FastHessian(float thresh, int octaves, int init_sample, IntegralImage img) { this.thresh = thresh; this.octaves = octaves; this.init_sample = init_sample; this.img = img; }
public static IntegralImage FromImage(Bitmap image) { IntegralImage pic = new IntegralImage(image.Width, image.Height); float rowsum = 0; /* for (int y = 0; y < image.Height; y++) * { * rowsum = 0; * for (int x = 0; x < image.Width; x++) * { * Color c = image.GetPixel(x, y); * rowsum += (cR * c.R + cG * c.G + cB * c.B) / 255f; * * // integral image is rowsum + value above * if(y==0) * pic[0, x] = rowsum; * else * pic[y, x] = rowsum + pic[y - 1, x]; * } * }*/ BitmapData dataIn = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte *pIn = (byte *)(dataIn.Scan0.ToPointer()); for (int y = 0; y < dataIn.Height; y++) { rowsum = 0; for (int x = 0; x < dataIn.Width; x++) { int cb = (byte)(pIn[0]); int cg = (byte)(pIn[1]); int cr = (byte)(pIn[2]); // 0 1 2代表的次序是B G R rowsum += (cR * cr + cG * cg + cB * cb) / 255f; // integral image is rowsum + value above if (y == 0) { pic[0, x] = rowsum; } else { pic[y, x] = rowsum + pic[y - 1, x]; } pIn += 3; } pIn += dataIn.Stride - dataIn.Width * 3; } } image.UnlockBits(dataIn); return(pic); }
List <IPoint2> GetFtPntList(Bitmap bitImg, float thread) { List <IPoint2> ipts1 = new List <IPoint2>();//图片1的特征点 //-------------------------------------------------- // Create Integral Image IntegralImage iimg = IntegralImage.FromImage(bitImg); // Extract the interest points ipts1 = FastHessian.getIpoints(thread, //此值越小,特征点越多 5, 2, iimg); // Describe the interest points SurfDescriptor.DecribeInterestPoints(ipts1, false, //是否表示方向 false, //false为64,true为128 iimg); iimg.Dispose(); iimg = null; return(ipts1); }
/// <summary> /// Static one-call do it all function /// </summary> /// <param name="img"></param> /// <param name="ipts"></param> /// <param name="extended"></param> /// <param name="upright"></param> public static void DecribeInterestPoints(List <IPoint2> ipts, bool upright, bool extended, IntegralImage img) { SurfDescriptor des = new SurfDescriptor(); des.DescribeInterestPoints(ipts, upright, extended, img); }
/// <summary> /// Static one-call do it all method /// </summary> /// <param name="thresh"></param> /// <param name="octaves"></param> /// <param name="init_sample"></param> /// <param name="img"></param> /// <returns></returns> public static List<IPoint2> getIpoints(float thresh, int octaves, int init_sample, IntegralImage img) { FastHessian fh = new FastHessian(thresh, octaves, init_sample, img); return fh.getIpoints(); }