int main(int argc, char *argv[]) {
	char *query;				/* the query used to find the video stream */
	lsl_streaminfo result,info;	/* the streaminfo returned by the resolve call, and the one associated with the inlet */
	lsl_inlet inlet;			/* a stream inlet to get samples from */
	int errcode;				/* error code (lsl_lost_error or timeouts) */
	int width,height,channels;	/* image parameters */
	IplImage* img;				/* OpenCV image struct */
	char *name;					/* name of the stream that we resolved */

	query = argc>1 ? argv[1] : default_query;
	while (1) {
		/* resolve the stream of interest (result array, array capacity: 1 element, predicate is our query, resolve at least 1 stream, wait forever if necessary) */
		printf("Now waiting for a stream with %s...",query);
		lsl_resolve_bypred(&result,1,query,1,LSL_FOREVER);
		printf("done.\n");

		/* make an inlet to read data from the stream (buffer max. 1 seconds of data, no preference regarding chunking, automatic recovery disabled) */
		inlet = lsl_create_inlet(result, 1, LSL_NO_PREFERENCE, 0);

		/* get the stream meta-data */
		info = lsl_get_fullinfo(inlet,LSL_FOREVER,&errcode);
		name = lsl_get_name(info);
		width = atoi(lsl_child_value_n(lsl_child(lsl_get_desc(info),"encoding"),"width"));
		height = atoi(lsl_child_value_n(lsl_child(lsl_get_desc(info),"encoding"),"height"));
		channels = atoi(lsl_child_value_n(lsl_child(lsl_get_desc(info),"encoding"),"color_channels"));

		/* allocate an OpenCV image*/
		img = cvCreateImage(cvSize(width,height),IPL_DEPTH_8S,channels);

		/* create a window */
		cvNamedWindow(name, CV_WINDOW_AUTOSIZE);
		cvMoveWindow(name, 100, 100);

		while (true) {
			/* get a new sample */
			lsl_pull_sample_c(inlet,img->imageData,width*height*channels,LSL_FOREVER,&errcode);
			if (errcode)
				break;
			/* display */
			cvShowImage(name, img);
			if ((char)cvWaitKey(1)==27)
				return 0;
		}
		cvReleaseImage(&img);
		cvDestroyWindow(name);
		lsl_destroy_inlet(inlet);
		lsl_destroy_streaminfo(info);
		lsl_destroy_streaminfo(result);
	}
	
    return 0;
}
void __fastcall TMainCaptureForm::BitBtnPlayClick(TObject *Sender)
{

	if(outlet) {
		lsl_destroy_outlet(outlet);
		outlet = NULL;
	}
	double requestedFrameRate = edtRequestedFrameRate->Text.ToDouble();
	lsl_streaminfo info = lsl_create_streaminfo("VideoStream_0","VideoStream_0",1,requestedFrameRate,cft_int32,"");
	lsl_xml_ptr desc = lsl_get_desc(info);
	lsl_xml_ptr chn = lsl_append_child(desc, "channels");
	lsl_append_child_value(chn, "name","frame");
	lsl_append_child_value(chn,"unit","number");

	lsl_xml_ptr sync = lsl_append_child(desc, "synchronization");
	lsl_append_child_value(sync, "can_drop_samples", "true");

	outlet = lsl_create_outlet(info,0,360);


	cbVideoInputDevice->Enabled = false;
	cbVideoInput->Enabled = false;
	cbVideoInputFormat->Enabled = false;
	SpatialDivisorEdit->Enabled = false;
	cbRecord->Enabled =false;

	Start(CaptureWorkerForm, edOutput0->Text, bmpQueue, hMutex, outlet, requestedFrameRate);
	frameThread = new TFrameThread(this, bmpQueue, hMutex, false);

	BitBtnStop->Enabled=true;
	BitBtnPlay->Enabled=false;

	edtFrameRate->Text = FormatFloat ("0.00", CaptureWorkerForm->VideoGrabber->CurrentFrameRate);


	double ratio = requestedFrameRate/CaptureWorkerForm->VideoGrabber->CurrentFrameRate;
	if(ratio > 1.02 || ratio < .98) {
		edtFrameRate->Text = FormatFloat ("0.00", CaptureWorkerForm->VideoGrabber->CurrentFrameRate);
		Application->MessageBoxA(L"Camera 0 unable to display requested frame rate.", L"Error", MB_OK);
		btStopClick(this);
		return;
	}

}
示例#3
0
int _tmainxx(int argc, _TCHAR* argv[])
{
	int nChannels = 9;
   //	char *channels[] = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"};
	int t,c;					/* time point and channel index */
	lsl_streaminfo info;		/* out stream declaration object */
	lsl_xml_ptr desc, chn;		/* some xml element pointers */
	lsl_outlet outlet;			/* stream outlet */
	double starttime;			/* used for send timing */
	float cursample[9];			/* the current sample */

	/* declare a new streaminfo (8 channels, 100 Hz, float-formatted, some pseudo device id */
	info = lsl_create_streaminfo("BioSemi","EEG",nChannels,100,cft_float32,"325wqer4354");

	/* add some meta-data fields to it */
	desc = lsl_get_desc(info);
	lsl_append_child_value(desc,"manufacturer","BioSemi");
 /*	for (c=0;c<8;c++) {
		chn = lsl_append_child(desc,"channels");
		lsl_append_child_value(chn,"name",channels[c]);
		lsl_append_child_value(chn,"unit","microvolts");
		lsl_append_child_value(chn,"type","EEG");
	}
   */
	/* make a new outlet */
	outlet = lsl_create_outlet(info,0,360);

	/* send data forever */
	printf("Now sending data...\n");
	starttime = ((double)clock())/CLOCKS_PER_SEC;
	for(t=0;;t++) {
		for (c=0;c<nChannels;c++)
			cursample[c] = (float)((rand()%1500)/500.0-1.5);
		lsl_push_sample_f(outlet,cursample);
		while (((double)clock())/CLOCKS_PER_SEC < starttime + t*0.01);
	}

	/* we never get here, buy anyway */
	lsl_destroy_outlet(outlet);
	return 0;
}
示例#4
0
int main(int argc, char* argv[]) {
	int t,c;					/* time point and channel index */
	lsl_streaminfo info;		/* out stream declaration object */
	lsl_xml_ptr desc, chn, chns;/* some xml element pointers */ 
	lsl_outlet outlet;			/* stream outlet */
	double starttime;			/* used for send timing */
	float cursample[8];			/* the current sample */

	/* declare a new streaminfo (name: BioSemi, content type: EEG, 8 channels, 100 Hz, float values, some made-up device id (can also be empty) */
	info = lsl_create_streaminfo("BioSemi","EEG",8,100,cft_float32,"325wqer4354");

	/* add some meta-data fields to it */
	/* (for more standard fields, see https://github.com/sccn/xdf/wiki/Meta-Data) */
	desc = lsl_get_desc(info);
	lsl_append_child_value(desc,"manufacturer","BioSemi");
	chns = lsl_append_child(desc,"channels");
	for (c=0;c<8;c++) {
		chn = lsl_append_child(chns,"channel");
		lsl_append_child_value(chn,"label",channels[c]);
		lsl_append_child_value(chn,"unit","microvolts");
		lsl_append_child_value(chn,"type","EEG");
	}

	/* make a new outlet (chunking: default, buffering: 360 seconds) */
	outlet = lsl_create_outlet(info,0,360);

	/* send data forever (note: this loop is keeping the CPU busy, normally one would sleep or yield here) */
	printf("Now sending data...\n");
	starttime = ((double)clock())/CLOCKS_PER_SEC;
	for(t=0;;t++) {
		for (c=0;c<8;c++)
			cursample[c] = (float)((rand()%1500)/500.0-1.5);
		lsl_push_sample_f(outlet,cursample);
		while (((double)clock())/CLOCKS_PER_SEC < starttime + t*0.01);
	}

	/* we never get here, buy anyway */
	lsl_destroy_outlet(outlet);
	return 0;
}
示例#5
0
int _tmain(int argc, _TCHAR* argv[])
{
	int nChannels = 40;
	int nMarkers = nChannels/4;
	double samplesPerSec = 440;
	char *channels[40];


	int t,c,m;					/* time point and channel index */
	lsl_streaminfo info;		/* out stream declaration object */
	lsl_xml_ptr desc, chn, chns;		/* some xml element pointers */
	lsl_outlet outlet;			/* stream outlet */
	double starttime;			/* used for send timing */
	float cursample[40];			/* the current sample */
	char chanName[256];
	/* declare a new streaminfo (8 channels, 100 Hz, float-formatted, some pseudo device id */
	info = lsl_create_streaminfo("PhaseSpace","Mocap",nChannels,samplesPerSec,cft_float32,"76sfsfdsdfa67");

	/* add some meta-data fields to it */
	desc = lsl_get_desc(info);
	lsl_append_child_value(desc,"manufacturer","Phasespace");
	chns = lsl_append_child(desc,"channels");
	for (c=0;c<nMarkers;c++) {

		chn = lsl_append_child(chns,"channel");
		sprintf(chanName, "Marker%d_X", c);
		lsl_append_child_value(chn, "label", chanName);
		lsl_append_child_value(chn,"type","PositionX");
		lsl_append_child_value(chn,"unit","meters");


		chn = lsl_append_child(chns,"channel");
		sprintf(chanName, "Marker%d_Y", c);
		lsl_append_child_value(chn, "label", chanName);
		lsl_append_child_value(chn,"type","PositionY");
		lsl_append_child_value(chn,"unit","meters");


		chn = lsl_append_child(chns,"channel");
		sprintf(chanName, "Marker%d_Z", c);
		lsl_append_child_value(chn, "label", chanName);
		lsl_append_child_value(chn,"type","PositionY");
		lsl_append_child_value(chn,"unit","meters");

	}

	/* make a new outlet */
	outlet = lsl_create_outlet(info,0,360);

	/* send data forever */
	printf("Now sending data...\n");
	starttime = ((double)clock())/CLOCKS_PER_SEC;

	float x = 0;
	float y = 0;
	float z = 0;

	for(t=0;;t++) {
		for(m=0, c=0; m<nMarkers; m++) {
			x++;
			if(t%3 == 0) y++;
			if(t%5 == 0) z++;


			cursample[c++] = sin(degToRad((x-360*m)/10.0))*.1;

			cursample[c++] = sin(degToRad((y-360*m)/10.0))*.1;

			cursample[c++] = sin(degToRad((z-360*m)/10.0))*.1;

			cursample[c++] =  (float)((rand()%1500)/500.0-1.5)*.001;


		}

		lsl_push_sample_f(outlet,cursample);

		while (((double)clock())/CLOCKS_PER_SEC < starttime + t/samplesPerSec) {
			Sleep(1);
		}
	   //	printf("here %d\n", t);
	}

	/* we never get here, but anyway */
	lsl_destroy_outlet(outlet);
	return 0;
}