void CueContrastKernel::test() {
	int startx = std::min(m_track.winnerSize.width, m_track.winnerPos.x - cvRound((float)m_track.winnerSize.width/2.0));
	int endx = std::max(m_track.imageSize.width-m_track.winnerSize.width, m_track.winnerPos.x + cvRound((float)m_track.winnerSize.width/2.0));
	int starty = std::min(m_track.winnerSize.height, m_track.winnerPos.y - cvRound((float)m_track.winnerSize.height/2.0));
	int endy = std::max(m_track.imageSize.height-m_track.winnerSize.height, m_track.winnerPos.y + cvRound((float)m_track.winnerSize.height/2.0));

	CvPoint2D32f pos;

	cvSetZero(mp_cvoutputimg->ipl);
	float* salmap = (float*)(mp_cvoutputimg->ipl->imageData);
	int salwidth = mp_cvoutputimg->width;

	for(int j = starty;j<endy;++j) {
		for(int i = startx;i<endx;++i) {
			pos.x = i;
			pos.y = j;
			cropNResize(&pos, &(m_track.winnerSize), 1.0);			
			calculateProbability(&(mp_target_candidate[0]), 1.0);
			float sim = computeSimilarity(&(mp_target_candidate[0]), &m_target_model);
			salmap[j*salwidth + i] = sim;			
		}
	}

	cvSalImageOut.out();
}
void CueContrastKernel::runkernel(CvPoint2D32f* nextpos, CSCVector* prob_cand, float* rel, float hval) {
	if(debug) std::cout << getName() << "::runkernel()\n";
	bool result = false;
	int count = 0;
	CvPoint2D32f oldpos = m_y0;
	//CvSize objsize = m_track.winnerSize;

	if(debug) std::cout << getName() << "::runkernel()::oldpos = [" << oldpos.x << " " << oldpos.y << "]\n";

	while(!result){
	
		switch(m_opmode) {
			case SIMPLE:
				//cropNResize(&oldpos, &objsize, hval);
				cropNResize(&oldpos, &m_objsizenorm, hval);
				calculateProbability(prob_cand, hval);
				break;
			default:
				std::cerr << getName() << "::runkernel()::Currently only SIMPLE mode is supported!\n";
				return;
		}
		computeWeights(prob_cand); // Step2
		findNextLocation(nextpos, hval); // Step 3
		//if(debug) std::cout << getName() << "::runkernel()::nextpos = [" << nextpos->x << " " << nextpos->y << "]\n";
		result = checkCondition(&oldpos, nextpos, count); // Step 6
		if(debug) std::cout << getName() << "::runkernel()::count = " << count << ", nextpos = [" << nextpos->x << ", " << nextpos->y << "]\n";
		count++;
	}
	(*rel) = computeSimilarity(prob_cand, &m_target_model);
	if(debug) std::cout << getName() << "::runkernel()::while() loop complete::count = " << count << ", rel = " << (*rel) << ", nextpos = [" << nextpos->x << ", " << nextpos->y << "]\n";
}
Exemplo n.º 3
0
void Similarity::initialize(boost::shared_ptr<Corpus> ptrInCorp, boost::shared_ptr<Corpus> ptrOutCorp, boost::shared_ptr<XenVocab> ptrVocab) {
    ptrVoc = ptrVocab;
    ptrID = ptrInCorp;
    ptrOOD = ptrOutCorp;
    
    loadWords();
    computeInDomainTFIDF();
    computeOutOfDomainTFIDF();
    buildIDVector();
    computeOutOfDomainIDF();
    computeSimilarity();
}
void CueContrastKernel::initialize() {

	if(debug) std::cout << getName() << "::initialize()\n";

	obtainInput();

	TrackData* track = trackIn.getBuffer();
	if(!track) { 
		if(debug) std::cerr << getName() << "::ERROR::initialize()::trackIn is NULL!...\n"; 
		return; 
	}

	if(track->reliability < m_threshold) {
		if(debug) std::cerr << getName() << "::ERROR::initialize()::track->reliability below threshold!...\n"; 
		return;
	}

	if (!mp_cvoutputimg) {
		unsigned int width = mp_cvimg1->width;
		unsigned int height = mp_cvimg1->height;
		if(debug) std::cout << getName() << "::initialize()::mp_cvimg1 size = [" << width << " " << height << "]\n"; 
		mp_cvoutputimg = new CVImage(cvSize(width, height), CV_32FC1, 0);
		cvSalImageOut.setBuffer(mp_cvoutputimg);
	}
	
	cvSetZero(mp_cvoutputimg->ipl);

	if(!mp_cvimg1) { std::cerr << getName() << "::ERROR::initialize()::mp_cvimg1 is NULL!\n"; return; }

	float xratio, yratio;
	xratio = (float)(mp_cvimg1->width) / (float)(track->imageSize.width);
	yratio = (float)(mp_cvimg1->height) / (float)(track->imageSize.height);

	m_track.winnerPos.x = cvRound( (float)(track->winnerPos.x) * xratio );
	m_track.winnerPos.y = cvRound( (float)(track->winnerPos.y) * yratio );
	m_track.winnerSize.width = cvRound( (float)(track->winnerSize.width) * xratio );
	m_track.winnerSize.height = cvRound( (float)(track->winnerSize.height) * xratio );

	m_track.winnerRect.x = m_track.winnerPos.x - cvRound( (float)(m_track.winnerSize.width)/2.0 );
	m_track.winnerRect.y = m_track.winnerPos.y - cvRound( (float)(m_track.winnerSize.height)/2.0 );
	m_track.winnerRect.width = m_track.winnerSize.width;
	m_track.winnerRect.height = m_track.winnerSize.height;

	m_track.reliability = track->reliability;

	m_track.imageSize.width = mp_cvimg1->width;
	m_track.imageSize.height = mp_cvimg1->height;

//	mp_objSize = &(m_track.winnerSize);
	m_objsize = m_track.winnerSize;
	if(!m_forceNormSize) m_objsizenorm = m_objsize;

	m_target_model.setZero();
	for(int i = 0;i<3;i++) mp_target_candidate[i].setZero();

	unsigned int size;
	if(m_forceMinSize) {
		size = std::max(m_track.winnerSize.width, m_minSize);
		m_track.winnerSize.width = size;	
		size = std::max(m_track.winnerSize.height, m_minSize);
		m_track.winnerSize.height = size;	
	}
	size = (m_track.winnerSize.width) * (m_track.winnerSize.height);
	m_weight.allocate(size);
	m_weight.setZero();

	CvPoint2D32f winner;
	winner.x = (float)(m_track.winnerPos.x);
	winner.y = (float)(m_track.winnerPos.y);
	
	CvSize objsize;
	objsize = m_track.winnerSize;
	
	if(debug) std::cout << getName() << "::initialize()::obj size = [" << objsize.width << " " << objsize.height << "]\n";
	
	if(mp_cvmaskimg) delete mp_cvmaskimg;
	mp_cvmaskimg = NULL;

	float* src = m_target_model.getData();
	float* dst = mp_target_candidate[0].getData();
	float* orig = m_target_orig.getData();
	float sim;
	
	switch(m_opmode) {
		case SIMPLE:
			//cropNResize(&winner, &objsize, 1.0);
			cropNResize(&winner, &m_objsizenorm, 1.0);
			calculateProbability(&m_target_model, 1.0);
			memcpy((char*)dst, (char*)src, m_totalnumbins*sizeof(float));
			memcpy((char*)orig, (char*)src, m_totalnumbins*sizeof(float));
			sim = computeSimilarity(&(mp_target_candidate[0]), &m_target_model);
			drawGrayBall(&winner, &objsize);

			break;
		default:
			std::cerr << getName() << "::initialize()::ERROR::Currently only SIMPLE mode is supported!\n";
			return;	
	}

	cvSalImageOut.out();

	if(draw) {
		mpDrawModel->dataIn.setBuffer(&m_target_model);
		mpDrawCandidate->dataIn.setBuffer(&(mp_target_candidate[0]));
		mpDrawModel->execute();
		mpDrawCandidate->execute();
		cvModelOut.setBuffer(mpDrawModel->cvImageOut.getBuffer());
		cvCandidateOut.setBuffer(mpDrawCandidate->cvImageOut.getBuffer());
		cvModelOut.out();
		cvCandidateOut.out();
	}

	m_init = true;
	
	if(debug) std::cout << getName() << "::initialize() complete\n";
}
Exemplo n.º 5
0
int main(int argc, char **argv)
	{
		
	int rank;
        int size;
        MPI_Status status;

        MPI_Init(&argc, &argv);
        MPI_Comm_size(MPI_COMM_WORLD, &size);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	int i;
	int check = 0;
	char** books = (char**)malloc(sizeof(char*) * 40);
	char* word = (char*)malloc(sizeof(char)*100);
	int BOOK = 0;
	int numBooks = 40;

	FILE* textFile = fopen(argv[1], "r");
	if(textFile == NULL)
		{
		printf("Error: File Not Found\n");
		exit(1);
		}

	int b = 0;
	while(fscanf(textFile, "%s", word) != EOF)
		{
		books[b] = strdup(word);
		b ++;
		}
	fclose(textFile);	

					    

	if(rank != 0)
		{
		for(BOOK = (rank-1); BOOK < numBooks; BOOK += (size - 1))
			{
			char bookName[50] = "C_";
			strcat(bookName, books[BOOK]);
			hashTable textHash = textToHash(books[BOOK]);
			hashToDisk(textHash, bookName);
			free(textHash);
			}
		
		MPI_Send(&check, 1, MPI_INT, 0, 11, MPI_COMM_WORLD);
		}
	else
		{
		for(i = 1; i < size; i ++)
			{
			MPI_Recv(&check, 1, MPI_INT, i, 11, MPI_COMM_WORLD, &status);
			}
		}

		if(rank == 0)
			{
			check = 1;
			}

        	MPI_Bcast(&check, 1, MPI_INT, 0, MPI_COMM_WORLD);

		while(check != 1);

	
		
	if(rank != 0)
		{
		int k;
		for(BOOK = (rank-1); BOOK < numBooks; BOOK += (size - 1))
			{
			for(k = 0; k < numBooks; k ++)
				{
				char bookName0[50] = "C_";
				char bookName1[50] = "C_";
				strcat(bookName0, books[BOOK]);
				strcat(bookName1, books[k]);
				hashTable H0 = diskToHash(bookName0);
				hashTable H1 = diskToHash(bookName1);
				double similarity;
				similarity = computeSimilarity(H0, H1);
				printf("%10s vs %10s: %10f\n", books[BOOK], books[k], similarity);
				free(H0);
				free(H1);
				}
			}
		}
		
		//Start Comparing Books

	//hashTable textHash0 = textToHash(argv[1]);
	//hashTable textHash1 = textToHash(argv[2]);

	//double similarity;

	//similarity = computeSimilairty(textHash0, textHash1);
	//printf("%f\n", similarity);

	//hashToDisk(textHash0, "hash1.txt");

	//hashTable textHash1 = diskToHash("hash1.txt");

	//hashToDisk(textHash1, "hash2.txt");


	MPI_Finalize();
	}
Exemplo n.º 6
0
/****************************************************************
 * Name    : establish_hyperGraph                               *
 * Function: establish hyperGraph based on the points           *
 *           information.                                       *
 * Input   :  void                                              *
 * Output  : int                                                *
 ****************************************************************/
static int establish_hyperGraph() {
  int i, j, k, l;
  double *similarity = NULL;
  double bestSimi;
  int indexBestSimi;
  int flag = 0;

  similarity = (double *)calloc(sizeof(double), N);
  if(similarity == NULL)
    return -1;

  /* find the k_nearest points for each of the N point */
  for (i=0; i<N; i++){
    /* compute similarity of point i with each point j */
    for (j =0; j<N; j++){
       similarity[j] = computeSimilarity(i,j);
    }/* end for j */

    /* find the K_nearest points around point i */
    for (k=0; k<K_nearest; k++){

      bestSimi = 0.0;
      indexBestSimi = 0;

      for (j=0; j<N; j++){
	if(j != i){
	  if (similarity[j]>bestSimi){
	    indexBestSimi = j;
	    bestSimi = similarity[j];
	  }/* end if */
	}/* end if */
      }/* end for j */
      
      /* add a new edge to one of the two points */
      if(i<indexBestSimi){
	points[i].edges[points[i].length].pointNO = indexBestSimi;
	points[i].edges[points[i].length].similarity = bestSimi;
	points[i].length += 1;
	if(points[i].length > K5_nearest)
	  {
	    printf("length of the edges exceeds K5_nearest! bestSimi is %f \n", 
		   bestSimi);
	    return -1;
	  }
      }
      else {
	/* check whether this edge has already been added from the
	 * other point.
	 */
	flag = 0;
	for(l=0; l<points[indexBestSimi].length; l++){
	  if(points[indexBestSimi].edges[l].pointNO == i){
	    flag = 1;
	    break;
	  }/* end if */
	}/* end for l */
	
	if(flag == 0){
	  points[indexBestSimi].edges[points[indexBestSimi].length].pointNO = i;
	  points[indexBestSimi].edges[points[indexBestSimi].length].similarity = bestSimi;
	  points[indexBestSimi].length += 1;
	  if(points[indexBestSimi].length > K5_nearest)
	  {
	    printf("length of the edges exceeds K5_nearest!bestSimi is %f \n", 
		   bestSimi);
	    return -1;
	  }
	}/* end if */
      }/* end else */

      similarity[indexBestSimi] = 0.0;

    }/* end for k */
    
  }/* end for i */

#ifdef Debug_establish_hyperGraph
  j =0;
  printf("hyper edge for point %d is: \n", j);
  for(i=0; i<points[j].length; i++){
    printf("%d  %f \n", points[j].edges[i].pointNO,  points[j].edges[i].similarity);
  }/* end for */
  j = 36;
  printf("hyper edge for point %d is: \n", j);
  for(i=0; i<points[j].length; i++){
    printf("%d  %f \n", points[j].edges[i].pointNO,  points[j].edges[i].similarity);
  }/* end for */
  j = 49;
  printf("hyper edge for point %d is: \n", j);
  for(i=0; i<points[j].length; i++){
    printf("%d  %f \n", points[j].edges[i].pointNO,  points[j].edges[i].similarity);
  }/* end for */
#endif 

  free(similarity);
  similarity = NULL;
  return 1;

}/* end establish_hyperGraph */