void extractFeatures(const cv::Mat& image,
                     std::vector<SiftFeature>& features,
                     const SiftOptions& options) {
    // Clear list.
    features.clear();

    // SIFT settings.
    cv::SIFT sift(options.max_num_features, options.num_octave_layers,
                  options.contrast_threshold, options.edge_threshold, options.sigma);

    // Extract SIFT keypoints and descriptors.
    std::vector<cv::KeyPoint> keypoints;
    cv::Mat descriptors;
    sift(image, cv::noArray(), keypoints, descriptors, false);

    // Ensure that descriptors are 32-bit floats.
    CHECK(descriptors.type() == cv::DataType<float>::type);

    int num_features = keypoints.size();

    // Convert to features.
    for (int i = 0; i < num_features; i += 1) {
        SiftFeature feature;
        feature.position = keypointToSiftPosition(keypoints[i]);

        // Copy descriptor contents.
        cv::Mat row = descriptors.row(i);
        feature.descriptor.data.clear();
        std::copy(row.begin<float>(), row.end<float>(),
                  std::back_inserter(feature.descriptor.data));

        // Add to list.
        features.push_back(feature);
    }
}
Beispiel #2
0
void heap_sort(int a[], int n)
{
	int root, leaf;

	leaf = n - 1;
	root = (n-1) / 2; //leafに対する根
	
	//半順序木の作成
	while(compare(root, 0) >= 0){
		sift(a, root, leaf);
		--root;
	}
//	printf("〜半順序木完成〜\n");	
	  
	//ソート
//	printf("〜ヒープソート〜\n");
	while(compare(leaf, 0) > 0){
//		printf("compare(leaf, 0) == 1...swap!\n");
//		printf("swap(0, leaf)\n");
		swap(a, 0, leaf);
		leaf--;
		sift(a, 0, leaf);
	}
//	printf("end!\n");
}
/** Sort array using smoothsort.
 *
 * Sort @a N elements from array @a base starting with index @a r with smoothsort.
 *
 * @param base  pointer to array
 * @param r     lowest index to sort
 * @param N     number of elements to sort
 * @param less  comparison function returning nonzero if m[a] < m[b]
 * @param swap  swapper function exchanging elements m[a] and m[b]
 */
void su_smoothsort(void *base, size_t r, size_t N,
		   int (*less)(void *m, size_t a, size_t b),
		   void (*swap)(void *m, size_t a, size_t b))
{
  stretch s = { 1, 1, 1 };
  size_t q;

  array array_i;
  array* const array = &array_i;
  array->less = less;
  array->swap = swap;
  array->m = base;

  assert(less && swap);

  if (base == NULL || N <= 1 || less == NULL || swap == NULL)
    return;

  DEBUG(("\nsmoothsort(%p, %zu)\n", array, nmemb));

  for (q = 1; q != N; q++, r++, s.p++) {
    DEBUG(("loop0 q=%zu, b=%u, p=%s \n", q, s.b, binary(s.p)));

    if ((s.p & 7) == 3) {
      sift(array, r, s), stretch_up(&s), stretch_up(&s);
    }
    else /* if ((s.p & 3) == 1) */ { assert((s.p & 3) == 1);
      if (q + s.c < N)
	sift(array, r, s);
      else
	trinkle(array, r, s);

      while (stretch_down(&s, 0) > 1)
	;
    }
  }

  trinkle(array, r, s);

  for (; q > 1; q--) {
    s.p--;

    DEBUG(("loop1 q=%zu: b=%u p=%s\n", q, s.b, binary(s.p)));

    if (s.b <= 1) {
      while ((s.p & 1) == 0)
	stretch_up(&s);
      --r;
    }
    else /* if b >= 3 */ {
      if (s.p) semitrinkle(array, r - (s.b - s.c), s);
      stretch_down(&s, 1);
      semitrinkle(array, --r, s);
      stretch_down(&s, 1);
    }
  }
}
void heap_sort(){
	for(int i = n / 2; i >= 0; i--){
		sift(i);
	}

	while(n > 0){
		std::swap(val[0], val[n - 1]);
		n--;
		sift(0);
	}
}
Beispiel #5
0
void qsort(void *_base, size_t nel, size_t width, int (*cmp)(const void *, const void *))
{
	char *base = _base;
	size_t i;

	if (!nel) return;
	for (i=(nel+1)/2; i; i--)
		sift(base, i-1, nel-1, width, cmp);
	for (i=nel-1; i; i--) {
		swap(base, base+i*width, width);
		sift(base, 0, i-1, width, cmp);
	}
}
void heapSort(struct CElem m[], unsigned n) /* Пирамидално сортиране */
{ unsigned k;

  /* 1. Построяване на пирамидата */
  for (k = n/2 + 1; k > 1; k--)
    sift(m,k-1,n);

  /* 2. Построяване на сортирана последователност */
  for (k = n; k > 1; k--) {
    swap(m+1,m+k);
    sift(m,1,k-1);
  }
}
Beispiel #7
0
void heap_sort (int *ar, int n) {
	int i;
	int tmp;
	
	for (i = n / 2; i >= 0; i--) {
		sift (ar, i, n);
	}
	for (i = n; i >= 1; i--) {
		tmp = ar[0];
		ar[0] = ar[i];
		ar[i] = tmp;
		sift(ar, 0, i - 1);
	}
}
Beispiel #8
0
void HeapSort(int a[],int n)
{
	int i,t;
	for(i = n/2; i>0; --i)			//a[0 - n-1]建成大顶堆 ,从最后一个非终端结点开始筛选 
		sift(a,i,n);  				//数组已成堆,a[0]是最大值  
	for(i=n-1;i>0;--i) 
	{
		t = a[0];					//把a[0]和最后元素交换  
		a[0] = a[i];
		a[i] = t;
		sift(a,1,i);				//再次筛选成堆求次大值
	}

}
Beispiel #9
0
void build()
{
   void sift(int,int);
   struct adf t;
   int i;
   for (i=k/2;i>0;i--)
      sift(i,k);
   for (i=k;i>1;i--)
   {
      t=p[1];
      p[1]=p[i];
      p[i]=t;
      sift(1,i-1);
   }
}
Beispiel #10
0
static int iteroi()
        {
        int jj,nj;
        int i,gr,d;


        hav=muste_fopen(tempfile,"r+b");
        jj=0L; nj=0L;
        while (1)
            {
/*          sprintf(sbuf," %ld",jj+1); sur_print(sbuf); */
            hav_read1(jj,&gr); --gr;
            hav_read3(jj,xx);

            init_obs(gr);
            for (d=0; d<ng; ++d)
                {
                if (d==gr) continue;
                i=sift(gr,d);
                if (i) break;
                }
            if (d==ng) { ++nj; if (nj>=n) break; }
            else
                {
                nj=0L;
                shift(gr,d);
                ++d;
                hav_write1(jj,&d);
/*              sprintf(sbuf,"\nL=%g shift %d -> %d ",f2,gr+1,d); sur_print(sbuf); */
                }
            ++jj; if (jj==n) jj=0L;
            }
        muste_fclose(hav);
        return(1);
        }
Beispiel #11
0
void sort_pts()
{
	int i;
	double aux;
	for (i = hn / 2; i >= 0; sift(i--));
	while (hn)
	{
		a[0] = (a[0] ^ a[hn - 1]) ^ (a[hn - 1] = a[0]);
		aux = t[0]; t[0] = t[hn - 1]; t[hn - 1] = aux;
		hn--; sift(0);
	}
	i = i;
	memset(ot, 0, sizeof(ot));
	for (i = 0; i < n; i++) ot[a[i]] = t[i];
	memcpy(t, ot, sizeof(ot));
}
Beispiel #12
0
//下面代码堆排序均是从0索引开始 所以左孩子是 2*i+1 右孩子2*i+2
void Sort::sift(RecType R[], int root, int size)
{
    //左孩子
    int child = 2 * root + 1;
    
    //如果child > high - 1 代表该根没有孩子
    if (child <= size - 1)
    {
        int rightChild = child + 1;
        if (rightChild <= size - 1)//判断是否存在右孩子
        {
            //右孩子节点大,就将j指向右孩子
            if (R[child].key < R[rightChild].key)
            {
                child = rightChild;
            }
            //如果该root节点小,不符合大根堆的条件,就和2*root+1进行交换
            if (R[root].key < R[child].key)
            {
                //交换之后可能数组就不是堆了,所以后面要使用递归来调整,直到根没有孩子
                RecType temp = R[child];
                R[child] = R[root];
                R[root] = temp;
                //使用递归 使得根也是堆
                sift(R, child, size);
            }
        }
    }
}
SiftResults_t *siftDetectDescribe( IplImage *img, SiftParams_t params )
{
  SIFT sift( img, params.octaves, params.intervals );
  sift.DoSift();

  return buildSiftResults( sift.keypoints(), sift.descriptors() );
}
Beispiel #14
0
void sort()
{  
  for (int i=N-1; i>=1; i--)
    { 
      heap[0]=(heap[0]^heap[i])^(heap[i]=heap[0]);
      sift(i, 0);
    }
}
Beispiel #15
0
 void operator()(std::size_t n) const {
   auto start = std::chrono::high_resolution_clock::now();
   std::vector<T> data(n);
   sift(std::begin(data), n);
   auto end = std::chrono::high_resolution_clock::now();
   std::chrono::duration<double> elapsed = end - start;
   std::cout << std::setw(6) << std::fixed
             << std::setprecision(6) << elapsed.count() << "\t";
 }
Beispiel #16
0
int main(){
	int m, n, i, x, y, z, tam, exist;
	vector<edge> myvector;
	vector<int> stack;
	edge edge1, aux, element;
	while(1){
		scanf("%d %d", &n, &m);
		if(n == 0 && m == 0){
			break;
		}
		myvector.push_back(edge1);
		for(i = 0; i < m; i++){
			scanf("%d %d %d", &x, &y, &z);
			edge1.x = x;
			edge1.y = y;
			edge1.z = z;
			myvector.push_back(edge1);
		}
		tam = myvector.size();
		heapify(tam-1, myvector);
		stack.push_back(1);
		while(tam-1){
			element = myvector[0];
			
			exist = 0;
			for(i = 0; i < tam-1; i++){
				if(myvector[i].x == stack[i]){
					exist = 1;
					break;
				}
			}
			if(exist == 0){
				stack.push_back(myvector[i].x);
			}
			exist = 0;
			for(i = 0; i < tam-1; i++){
				if(myvector[i].y == stack[i]){
					exist = 1;
					break;
				}
			}
			if(exist == 0){
				stack.push_back(myvector[i].y);
			}
			myvector[0] = myvector[tam-1];
			myvector.pop_back();
			tam = myvector.size();
			sift(1, tam-1, myvector);
		}
		for(i = 0; i < m; i++){
			cout << myvector[i].x;
			cout << myvector[i].y;
			cout << myvector[i].z;
		}
	}	
}
Beispiel #17
0
		void prime_iterator::expand(int index)
		{
			//概算よりちょっとだけ大きいところまで計算 無駄も出るけど
			auto approx = prime_approx(index);
			
			while( index >= static_cast<int>(p_.size()) )
			{
				sift( approx = static_cast<decltype(approx)>(approx * 1.05) );
			}
		}
Beispiel #18
0
void heap_sort(int d[], int n)
{
    int i = 0, t;
        //#初始化建堆, i从最后一个非叶子节点开始#%
        for(i = n / 2; i >= 0; i--)
                sift(d, i, n);

        for(i = 0; i < n; i++)
        {
                //#交换#%
                t = d[0];
                d[0] = d[n - i - 1];
                d[n - i - 1] = t;

                //#筛选编号为0 #%
                sift(d, 0, n - i - 1);

        }
}
void SiftDescriptorExtractor::computeImpl( const Mat& image,
										   vector<KeyPoint>& keypoints,
										   Mat& descriptors) const
{
    bool useProvidedKeypoints = true;
    Mat grayImage = image;
    if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY );

    sift(grayImage, Mat(), keypoints, descriptors, useProvidedKeypoints);
}
Beispiel #20
0
void greedy()
{
    int i;
    for (i = 1; i <= N; i++)
    {
        heap[1] += A[i];
        if (heap[1] > Max) Max = heap[1];
        Kq[Cs[i]] = Tt[1];
        sift();
    }
}
void ObjectRecognition::loadFeatures(Mat& inImage, vector< KeyPoint >& keypoints, vector< std::vector< float > >& features, Mat& descriptors)
{
	features.clear();
	keypoints.clear();
	if(input_type==0) //input_type = 0 camera
		cvtColor(inImage, inImage, CV_RGB2GRAY);


#if FEATURE_EXTRATION
	//---------------using SIFT to get features descriptors-------------------------
	//cout<< "...Extracting SIFT features..." << endl;

	initModule_nonfree();
	SIFT sift(1, 3, 0.04, 10, 1.0);
	sift(inImage, noArray(), keypoints, descriptors);


	//     vector<vector<float> > vdesc;
	//     vdesc.reserve(descriptors.rows);
	for (int i=0; i<descriptors.rows; i++)
	{
		features.push_back(descriptors.row(i));
	}
	//     cout<< "descriptors: " << vdesc.size() << "  " << vdesc[0].size() << endl;

#else
	//-----------using SURF to get features descriptors------------------------
	vector<float> descriptors;
	cv::Mat mask;
	cv::SURF surf(400, 4, 2, EXTENDED_SURF);
	surf(inimage, mask, keypoints, descriptors);
	features.push_back(vector<vector<float> >());
	changeStructure(descriptors, features.back(), surf.descriptorSize());
#endif

	//----------------------------display keypoints--------------------------  
	//     drawKeypoints(image, keypoints, image, Scalar(255,0,0));
	//     imshow("clusters", image);
	//     waitKey();

}
Beispiel #22
0
void smoothsort(void *_list, unsigned int size, int (compare)(void*, void*)) {
	unsigned int q = 1;
	r = 0;
	p = 1; level = 1;
	for (; q < size; q++) {
		r1 = r;
		if ((p & 7) == 3) {
			level1 = level;
			sift((void**)_list, compare);
			p = (p + 1) >> 2;
			level += 2;
		} else if ((p & 3) == 1) {
Beispiel #23
0
void Sort::heapSort(RecType R[], int n)
{
    traverseArray(R, n);
    
    //建立初始堆(只是必须要的)
    for (int i = n - 1; i >= 0; i--)
    {
        sift(R, i, n);
    }
    
    int last = n - 1;//最后面一个节点
    for (int i = 1; i <= n;i++,last--)
    {
        RecType temp = R[0];
        R[0] = R[last];
        R[last] = temp;
        sift(R, 0, last);
    }
    
    traverseArray(R, n);
}
Beispiel #24
0
    ExecutionStatus execute(NodeSocketReader& reader, NodeSocketWriter& writer) override
    {
        // Read input sockets
        const cv::Mat& src = reader.readSocket(0).getImageMono();
        // Acquire output sockets
        KeyPoints& kp = writer.acquireSocket(0).getKeypoints();
        cv::Mat& descriptors = writer.acquireSocket(1).getArray();

        // Validate inputs
        if(src.empty())
            return ExecutionStatus(EStatus::Ok);

        // Do stuff
        cv::SIFT sift(_nFeatures, _nOctaveLayers,
            _contrastThreshold, _edgeThreshold, _sigma);
        sift(src, cv::noArray(), kp.kpoints, descriptors);
        kp.image = src;

        return ExecutionStatus(EStatus::Ok, 
            string_format("Keypoints detected: %d", (int) kp.kpoints.size()));
    }
int main() {
  std::vector<int> v(500);
  sift0(begin(v), 50);
  std::cout << "sift0(begin(v), 50):\n";
  print_sieve(begin(v), 50);
  sift1(begin(v), 50);
  std::cout << "sift1(begin(v), 50):\n";
  print_sieve(begin(v), 50);
  sift(begin(v), 500);
  std::cout << "sift(begin(v), 500):\n";
  print_sieve(begin(v), 500);
  std::cout << "gcm(15, 9) = " << gcm(15, 9) << std::endl;
}
void Homography::computeKeypointAndDescriptors(cv::Mat inputImage, std::vector<cv::KeyPoint>& kp, cv::Mat& descriptors)
{
    cv::FernClassifier
    //cv::FAST(inputImage, kp, 100);
    //orb.detect(inputImage, kp);
    //surf.compute(inputImage, kp, descriptors);
    //orb(inputImage, cv::Mat(), kp, descriptors);
    sift(inputImage, cv::Mat(), kp, descriptors);
    //freak.compute(inputImage, kp, descriptors);
    //cv::FAST(inputImage, kp, 100);
    //surf.compute(inputImage, kp, descriptors);
    //surf(inputImage, cv::Mat(), kp, descriptors);
    
}
Beispiel #27
0
void heapSort(int * ArrayToSort, int NumberOfInts)
{
    int l, r;
    
    
    // building up the heap
    
    for(l = (NumberOfInts - 2) / 2; l >= 0; l--)
    {
        sift(ArrayToSort, l, NumberOfInts - 1);
    }
    
    
    //
    
    for(r = NumberOfInts - 1; r > 0; r--)
    {
        exchangeInts((ArrayToSort + 0), (ArrayToSort + r));
        
        sift(ArrayToSort, 0, r - 1);
    }
    
}
void sift(int pos){
	int biggest = val[pos], follower = pos;

	for(int i = 1; i <= 2; i++){
		if(2 * pos + i < n and val[2 * pos + i] > biggest){
			biggest = val[2 * pos + i], follower = 2 * pos + i;
		}
	}

	if(follower != pos){
		std::swap(val[pos], val[follower]);
		sift(follower);
	}
}
Beispiel #29
0
void  HeapSort(RecordType  r[],int length)
/* 对r[1..n]进行堆排序,执行本算法后,r中记录按关键字由大到小有序排列 */ 
{
	int i,n;
	RecordType b;
	crt_heap(r, length);
		n= length;
	for (  i=n ; i>= 2; --i) 
	{
		b=r[1];              /* 将堆顶记录和堆中的最后一个记录互换 */ 
		r[1]= r[i];
		r[i]=b; 
		sift(r,1,i-1);  /* 进行调整,使r[1..i-1]变成堆 */ 
	}
} /* HeapSort */ 
Beispiel #30
0
void heapify(int *heap, int n)
{
    int i = n / 2;
    for(i; i >= 0; i--)
    {
        sift(heap, i, n);
    }
//    while(n-1 > 0)
//    {
//        int tmp = heap[n-1];
//        heap[n-1] = heap[0];
//        heap[0] = tmp;
//        sift(heap, 0, n-1);
//        n--;
//    }
}