Exemplo n.º 1
0
vector<RotatedRect> getComparison(string dir){
	
	vector<RotatedRect> rect;
	
	DIR *dp;
	//struct dirent *dirp;
	if((dp = opendir(dir.c_str())) == NULL) {
		cout << "Error" << endl;
		CV_Assert(false);
	}
	
	//READING THE PATCH'S POSITION
	int length;
	char * buffer;
	
	ifstream is;
	string iniFile = dir+ "/comparisonCoord.txt";
	
	is.open (iniFile.c_str(), ios::binary );
	
	// get length of file:
	is.seekg (0, ios::end);
	length = is.tellg();
	is.seekg (0, ios::beg);
	// allocate memory:
	buffer = new char [length];
	// read data as a block:
	is.read (buffer,length);
	
	string content(buffer,length);
	stringstream ss(content);
	string sline;
	RotatedRect auxRect(Point2i(0,0), cv::Size(1,1), 0);
	
	while (getline(ss, sline)) {
		
		auxRect.center.x = atof(sline.substr(0,sline.find(',')).c_str());
		sline = sline.substr(sline.find(',')+1);
		auxRect.center.y = atof(sline.substr(0,sline.find(',')).c_str());
		sline = sline.substr(sline.find(',')+1);
		auxRect.size.width = atof(sline.substr(0,sline.find(',')).c_str());
		sline = sline.substr(sline.find(',')+1);
		auxRect.size.height = atof(sline.substr(0,sline.find(',')).c_str());

		auxRect.center.x += auxRect.size.width/2;
		auxRect.center.y += auxRect.size.height/2;
		
		rect.push_back(auxRect);
	}
	is.close();
	delete[] buffer;
	

	
	return rect;
}
Exemplo n.º 2
0
void CovariancePatchModel::updateBackgroundModel(GenericFeature *feature1) {
    CovariancePatchDescriptor *f1 = (CovariancePatchDescriptor *) feature1;

    //int min_radius = ceil( sqrt( pow(f1->m_rect.size.width/2,2)+pow(f1->m_rect.size.height/2,2) )*2);
    int min_radius = ceil(min(f1->m_rect.size.width,f1->m_rect.size.height));
    int randAngle = 0, x = 0, y = 0;
    int numMemorie = 20;

    /*
    //Mat tmp = this->m_last_img.clone();
    m_backgroundModel.clear();

    for (int i=0; i<numMemorie; i++) {
    	//randAngle = randint((360/numMemorie)*i, (360/numMemorie)*(i+1));
    	randAngle = (360/numMemorie)*i;

    	x = f1->m_rect.center.x + cos(randAngle)*min_radius;
    	y = f1->m_rect.center.y + sin(randAngle)*min_radius;

    	//cout << "x: "<<x<< " y: "<<y<<endl;

    	RotatedRect auxRect(Point2i(x,y),Size2i(f1->m_rect.size.width, f1->m_rect.size.height),0);
    	CovariancePatchDescriptor auxFeature(auxRect);
    	auxFeature.computeFeature(this);
    	//distance(&auxFeature);
    	m_backgroundModel.push_back(auxFeature);
    	//drawRotatedRect(tmp, auxRect,CV_RGB(0,0,255),1);
    	//imwrite(CreatefileNameString(), auxFeature.m_imgPatch);
    }
    //cvNamedWindow("Particle distribution");
    //imshow( "Particle distribution", tmp);
    //cvWaitKey();
    */


    if (m_backgroundModel.empty()) {
        for (int i=0; i<numMemorie; i++) {
            randAngle = randint((360/numMemorie)*i, (360/numMemorie)*(i+1));
            x = f1->m_rect.center.x + cos(randAngle)*min_radius;
            y = f1->m_rect.center.y + sin(randAngle)*min_radius;

            RotatedRect auxRect(Point2i(x,y),Size2i(f1->m_rect.size.width, f1->m_rect.size.height),0);
            CovariancePatchDescriptor auxFeature(auxRect,tracker_param);
            auxFeature.computeFeature(this);
            //distance(&auxFeature);
            m_backgroundModel.push_back(auxFeature);
        }
    }

    else {
        //sort (this->m_backgroundModel.begin(),this->m_backgroundModel.end(), compareFeaturesAsc);
        for (int i=0; i<numMemorie; i++) {
            randAngle = randint((360/numMemorie)*i, (360/numMemorie)*(i+1));
            x = f1->m_rect.center.x + cos(randAngle)*min_radius;
            y = f1->m_rect.center.y + sin(randAngle)*min_radius;

            RotatedRect auxRect(Point2i(x,y),Size2i(f1->m_rect.size.width, f1->m_rect.size.height),0);
            CovariancePatchDescriptor auxFeature(auxRect,tracker_param);
            auxFeature.computeFeature(this);
            //distance(&auxFeature);
            //cout << "p_ini: "<<m_backgroundModel[0].m_probability<<endl;
            //cout << "p_end: "<<m_backgroundModel[numMemorie-1].m_probability<<endl;
            //cout << "auxFeature.m_probability: "<<auxFeature.m_probability<<endl;
            m_backgroundModel.push_back(auxFeature);
            //if (this->m_backgroundModel[0].m_probability < auxFeature.m_probability+5){
            //	m_backgroundModel[0] = auxFeature;
            //	sort (this->m_backgroundModel.begin(),this->m_backgroundModel.end(), compareFeaturesAsc);
            //}
        }
    }


}
Exemplo n.º 3
0
GLuint MeshTexturizer::Imp::textureAlloc(const TRaster32P &ras, const TRaster32P &aux,
										 int x, int y, int textureLx, int textureLy,
										 bool premultiplied)
{
	struct locals {
		static void clearMatte(const TRaster32P &ras, int xBegin, int yBegin, int xEnd, int yEnd)
		{
			for (int y = yBegin; y != yEnd; ++y) {
				TPixel32 *line = ras->pixels(y), *pixEnd = line + xEnd;

				for (TPixel32 *pix = line + xBegin; pix != pixEnd; ++pix)
					pix->m = 0;
			}
		}

		static void clearMatte_border(const TRaster32P &ras, int border0, int border1)
		{
			assert(border0 < border1);

			// Horizontal
			clearMatte(ras, border0, border0, ras->getLx() - border0, border1);
			clearMatte(ras, border0, ras->getLy() - border1, ras->getLx() - border0, ras->getLy() - border0);

			// Vertical
			clearMatte(ras, border0, border1, border1, ras->getLy() - border1);
			clearMatte(ras, ras->getLx() - border1, border1, ras->getLx() - border0, ras->getLy() - border1);
		}
	}; // locals

	// Prepare the texture tile
	assert(aux->getLx() >= textureLx + TOTAL_BORDER_2 && aux->getLy() >= textureLy + TOTAL_BORDER_2);

	TRect rasRect(x, y, x + textureLx - 1, y + textureLy - 1);
	rasRect = rasRect.enlarge(premultiplied ? COPIED_BORDER : COPIED_BORDER + NONPREM_BORDER);
	rasRect = rasRect * ras->getBounds();

	TRect auxRect(rasRect - TPoint(x - TOTAL_BORDER, y - TOTAL_BORDER));

	// An auxiliary raster must be used to supply the transparent border
	TRaster32P tex(aux->extract(0, 0, textureLx + TOTAL_BORDER_2 - 1, textureLy + TOTAL_BORDER_2 - 1));
	tex->clear();
	aux->extract(auxRect)->copy(ras->extract(rasRect));

	if (!premultiplied && NONPREM_BORDER > 0)
		locals::clearMatte_border(aux, TRANSP_BORDER - NONPREM_BORDER, TRANSP_BORDER);

	// Pass the raster into VRAM
	GLuint texId;
	glGenTextures(1, &texId);
	glBindTexture(GL_TEXTURE_2D, texId);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);	  // These must be used on a bound texture,
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);	  // and are remembered in the OpenGL context.
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // They can be set here, no need for
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // the user to do it.

	glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->getWrap());
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glTexImage2D(GL_TEXTURE_2D,
				 0,				   // one level only
				 GL_RGBA,		   // pixel channels count
				 tex->getLx(),	 // width
				 tex->getLy(),	 // height
				 0,				   // border size
				 TGL_FMT,		   // pixel format
				 GL_UNSIGNED_BYTE, // pixel data type
				 (GLvoid *)tex->getRawData());

	return texId;
}
Exemplo n.º 4
0
RotatedRect searchFace(Mat& src, GenericModel *model, cv::Size2f scaleFactor, bool draw){
	
	GenericFeature *minFeature;
	Mat auxImg, auxImg2;
	resize(src, auxImg,cv::Size2i(scaleFactor.width*src.size().width, scaleFactor.height*src.size().height));
	auxImg2 = auxImg.clone();
	
	CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*) cvLoad (CASCADE_NAME, 0, 0, 0);
    CvMemStorage* storage = cvCreateMemStorage(0);
    assert (storage);
	if (! cascade)
        abort ();
	
	CvHaarClassifierCascade* cascadeProfile = (CvHaarClassifierCascade*) cvLoad (CASCADE_NAME_PROFILE, 0, 0, 0);
    CvMemStorage* storageProfile = cvCreateMemStorage(0);
    assert (storageProfile);
	if (! cascadeProfile)
        abort ();
	
	IplImage *gray_image = cvCreateImage(src.size(), IPL_DEPTH_8U, 1);
	IplImage aux = IplImage(src);
	
	cvCvtColor (&aux, gray_image, CV_BGR2GRAY);
	cvEqualizeHist( gray_image, gray_image );
	
	CvSeq* faces = cvHaarDetectObjects (gray_image, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize (25, 25));
	CvSeq* facesProfiles = cvHaarDetectObjects (gray_image, cascadeProfile, storageProfile, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize (25, 25));
	
	double minValue = 10000.0;
	RotatedRect minRect;
	
	model->updateModel(auxImg);
	if (draw) cvNamedWindow("ROI");
	
	for (int i = 0; i < (faces ? faces->total : 0); i++){
		CvRect* r = (CvRect*) cvGetSeqElem (faces, i);
		RotatedRect auxRect(Point2i(r->x+r->width/2,r->y+r->height/2),Size2i(r->width,r->height),0);
		auxRect = scaleRect(auxRect, cv::Size2f(scaleFactor.width, scaleFactor.height));
		if (draw) drawRotatedRect(auxImg2, auxRect,CV_RGB(100,50,50) , 2);
		
		
		if(model->ModelType == COV_FULL_IMAGE){
			//minFeature = (GenericFeature *)new CovarianceFullDescriptor(auxRect,model->tracker_param);
			CV_Assert(false);
		}
		else if(model->ModelType == COV_SUB_WINDOWS)
			minFeature = (GenericFeature *)new CovariancePatchDescriptor(auxRect,model->tracker_param);
		else if(model->ModelType == COV_SUB_WINDOWS_B)
			minFeature = (GenericFeature *)new CovariancePatchDescriptor(auxRect,model->tracker_param);
		
		minFeature->computeFeature(model);
		double dist = model->distance(minFeature);
		
		if (dist<minValue) {
			minValue = dist;
			minRect = auxRect;
		}
		
		minFeature->clear();
		delete minFeature;
		if (draw){
			cout << "dist: "<<dist<<endl;
			imshow( "ROI", auxImg2);
			cvWaitKey();
		}
		
	}
	
	for (int i = 0; i < (facesProfiles ? facesProfiles->total : 0); i++){
		CvRect* r = (CvRect*) cvGetSeqElem (facesProfiles, i);
		RotatedRect auxRect(Point2i(r->x+r->width/2,r->y+r->height/2),Size2i(r->width,r->height),0);
		auxRect = scaleRect(auxRect, cv::Size2f(scaleFactor.width, scaleFactor.height));
		if (draw) drawRotatedRect(auxImg2, auxRect,CV_RGB(0,0,0) , 2);
		
		if(model->ModelType == COV_FULL_IMAGE){
			//minFeature = (GenericFeature *)new CovarianceFullDescriptor(auxRect,model->tracker_param);
			CV_Assert(false);
		}
		else if(model->ModelType == COV_SUB_WINDOWS)
			minFeature = (GenericFeature *)new CovariancePatchDescriptor(auxRect,model->tracker_param);
		else if(model->ModelType == COV_SUB_WINDOWS_B)
			minFeature = (GenericFeature *)new CovariancePatchDescriptor(auxRect,model->tracker_param);
		
		minFeature->computeFeature(model);
		double dist = model->distance(minFeature);
		
		
		if (dist<minValue) {
			minValue = dist;
			minRect = auxRect;
		}
		
		minFeature->clear();
		delete minFeature;
		if (draw){
			cout << "dist: "<<dist<<endl;
			imshow( "ROI", auxImg2);
			cvWaitKey();
		}	
	}	
	
	
	if (draw){
		drawRotatedRect(auxImg2, minRect,CV_RGB(255,0,0) , 3);	
		imshow( "ROI", auxImg2);
		cvWaitKey();
		cvDestroyWindow("ROI");
	}
	auxImg2.release();
	auxImg.release();
	
	cvReleaseImage(&gray_image);
	
	cvClearMemStorage(storage);
	cvClearMemStorage(storageProfile);
	
	return scaleRect(minRect, cv::Size2f(1/scaleFactor.width, 1/scaleFactor.height));	
}