Exemple #1
0
int main( int argc, char* argv[] ) {

	uint8_t buffer[VIDEO_BUFFER_SIZE];
	surface_blob blob[256];
	int result,frame = 0;

	usb_dev_handle* s40 = usb_get_device_handle( ID_MICROSOFT, ID_SURFACE );

	surface_init( s40 );

	while (1) {
		result = surface_get_blobs( s40, blob );
		if (result <= 0) continue;
		printf("%d blobs\n",result);
		for (int i = 0; i < result; i++)
			printf("    x: %d y: %d size: %d\n",blob[i].pos_x,blob[i].pos_y,blob[i].area);
		if ((frame++ % 60) == 0) printf("status 0x%08x\n",surface_get_status(s40));
	}

	surface_get_image( s40, buffer );
	FILE* foo = fopen("surface.raw","w+");
	fwrite(buffer,VIDEO_BUFFER_SIZE,1,foo);
	fclose(foo);
}
Exemple #2
0
void display() {

	int curtime = glutGet( GLUT_ELAPSED_TIME );
	curframe++;

	if ((curtime - lasttime) >= 1000) {
		fps = (1000.0*(curframe-lastframe))/((double)(curtime-lasttime));
		lasttime  = curtime;
		lastframe = curframe;
		snprintf(buffer,sizeof(buffer),"FPS: %f",fps);
		printf("%s\n",buffer);
	}

	// clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// move to origin
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0,VIDEO_RES_Y,0);
	glScalef(1.0f, -1.0f, 1.0f);

	surface_get_image( s40, image );
	int bc = surface_get_blobs( s40, blobs );

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture);
	glTexImage2D(GL_TEXTURE_2D, 0, 1, VIDEO_RES_X, VIDEO_RES_Y, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);

	glBegin(GL_TRIANGLE_FAN);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glTexCoord2f(0, 0); glVertex3f(0,0,0);
	glTexCoord2f(1, 0); glVertex3f(VIDEO_RES_X,0,0);
	glTexCoord2f(1, 1); glVertex3f(VIDEO_RES_X,VIDEO_RES_Y,0);
	glTexCoord2f(0, 1); glVertex3f(0,VIDEO_RES_Y,0);
	glEnd();

	glDisable(GL_TEXTURE_2D);

	// green: tip
	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
	for (int i = 0; i < bc; i++) cross( blobs[i].pos_x/2, blobs[i].pos_y/2 );

	// red: centroid(?)
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	for (int i = 0; i < bc; i++) cross( blobs[i].ctr_x/2, blobs[i].ctr_y/2 );

	// yellow: axis(?)
	/*glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
	for (int i = 0; i < bc; i++) cross( (blobs[i].pos_x+blobs[i].axis_x)/2, (blobs[i].pos_y+blobs[i].axis_y)/2 );*/

	// blue: bbox
	glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
	for (int i = 0; i < bc; i++) box( blobs[i].bb_pos_x/2, blobs[i].bb_pos_y/2, (blobs[i].bb_pos_x+blobs[i].bb_size_x)/2, (blobs[i].bb_pos_y+blobs[i].bb_size_y)/2 );

	// white: id
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	char id_buf[64];
	for (int i = 0; i < bc; i++) {
		snprintf(id_buf,64,"%d",blobs[i].blob_id);
		output(blobs[i].ctr_x/2, blobs[i].ctr_y/2,id_buf);
	}

	output(20,20,buffer);
	// redraw
	glutSwapBuffers();
}