Esempio n. 1
0
File: Main.cpp Progetto: mly/BMW
void renderFrame() {
	//perform HSI converison
	GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	
	GLuint programID = hsi->programID();
	
	GL_CHECK(glUseProgram(programID));

	DrawQuad(programID);
	GL_CHECK(glUseProgram(0));
	
	
	*frame = window.Capture();
	
	//perform dilation
	GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	
	programID = dilation->programID();
	
	GL_CHECK(glUseProgram(programID));
	
	DrawQuad(programID);
	GL_CHECK(glUseProgram(0));
	
	*frame = window.Capture();
	dilate = false;
	
	//perform erosion
	GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	
	programID = erosion->programID();
	
	GL_CHECK(glUseProgram(programID));
	
	DrawQuad(programID);
	GL_CHECK(glUseProgram(0));
	 
	*frame = window.Capture();
	
	Blob* boundaries[BASE_SIZE];
	int nBlob = 0;
	
	memset(boundaries,0,sizeof(boundaries));
	
	sf::Image *labels = new sf::Image(frame->GetWidth(), frame->GetHeight());
	
	LabelRegions(frame, labels, boundaries, &nBlob);
	
	//printf("%d\n", nBlob);
	
	// draw rectangles
	for (int i=1; i<= nBlob; i++){
		// find the points
		BlobPoint ll, ur;
		ll.x = 99999;
		ll.y = 99999;
		ur.x = 0;
		ur.y = 0;
		Blob* blob = boundaries[i];
		BlobPoint* next = blob->points;
		printf("%d\n", blob->numPoints);
		while(next != NULL)
		{
			if(next->x < ll.x) ll.x = next->x;
			if(next->y < ll.y) ll.y = next->y;
			if(next->x > ur.x) ur.x = next->x;
			if(next->y > ur.y) ur.y = next->y;
			next = next->nextPoint;
			
		}
		
		ll.x -= 2;
		ll.y -= 2;
		ur.x += 2;
		ur.y += 2;
		bool fillBlack = false;
		if (!circleTest(blob)) {
			fillBlack = true;
		}
		drawRectangle(frame, ll, ur, sf::Color(0,0,255), fillBlack);
	}
		
	GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	
	programID = dead->programID();
	
	GL_CHECK(glUseProgram(programID));
	
	DrawQuad(programID);
	GL_CHECK(glUseProgram(0));
	
	FreeAllRegions(boundaries, nBlob);
}