void ShimmerInterfaceApp::update()
{
	if (shimmer->isStarted())
	{
		shimmer->run(); 
		if (shimmer->hasData())
		{
		
			//should really have written some kind of function for this... 
			std::vector<ci::osc::Message> msgVec = shimmer->getOSC(); 
			for (int i = 0; i < msgVec.size(); i++)
				sender.sendMessage(msgVec[i]);

			msgVec.clear();
			msgVec = shimmer->getOSCAccelToSCBusX();
			cout << "sooo x-values? wut?: " << msgVec.size() << std::endl;
			for (int i = 0; i < msgVec.size(); i++)
				serverSender.sendMessage(msgVec[i]);

			msgVec.clear();
			msgVec = shimmer->getOSCAccelToSCBusY();
			for (int i = 0; i < msgVec.size(); i++)
				serverSender.sendMessage(msgVec[i]);

			msgVec.clear();
			msgVec = shimmer->getOSCAccelToSCBusZ();
			for (int i = 0; i < msgVec.size(); i++)
				serverSender.sendMessage(msgVec[i]);
		}
	}
}
void SerialCommunicationApp::update()
{
	if (serialInitiallized()){
        if(serial.getNumBytesAvailable() > 0){
            console() << "Bytes available: " << serial.getNumBytesAvailable() << std::endl;
            try{
                lastString = serial.readStringUntil('\n');
            } catch(SerialTimeoutExc e) {
                console() << "timeout" << endl;
            }
            console() << lastString << endl;
            int16_t temp = lastString[0];
            
            //OSC MESSAGE
            osc::Message message;
            message.addIntArg(temp);
            message.setAddress("coinTrigger");
            message.setRemoteEndpoint(host, port);
            sender.sendMessage(message);
           
            TextLayout simple;
            simple.setFont( Font( "Arial Black", 54 ) );
            simple.setColor( Color( .7, .7, .2 ) );
            simple.addLine( lastString );
            simple.setLeadingOffset( 0 );
            mTexture = gl::Texture( simple.render( true, false ) );
            bTextureComplete = true;
            serial.flush();
        }
    }
    serial.flush();
}
void SerialCommunicationApp::keyDown(KeyEvent event)
{
    //DEBUG 
    int16_t temp = 0;

    switch (event.getChar()) {
        case '1':
            temp = 49;
            break;
        case '2':
            temp = 50;
            break;
        case '3':
            temp = 51;
            break;
    }
    
    if (temp > 48 && temp < 52) {
        osc::Message message;
        //message.addStringArg(lastString);
        message.addIntArg(temp);
        message.setAddress("coinTrigger");
        message.setRemoteEndpoint(host, port);
        sender.sendMessage(message);
        TextLayout simple;
        simple.setFont( Font( "Arial Black", 54 ) );
        simple.setColor( Color( .7, .7, .2 ) );
        simple.addLine( to_string(event.getChar()) );
        simple.setLeadingOffset( 0 );
        mTexture = gl::Texture( simple.render( true, false ) );
        bTextureComplete = true;
    }
}
void SerialCommunicationApp::setup()
{

	lastString = "";
    bTextureComplete = false;
    
	//SERIAL SETUP
	const vector<Serial::Device> &devices( Serial::getDevices() );
	for( vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		console() << "Device: " << deviceIt->getName() << endl;
	}
	
	try {
		Serial::Device dev = Serial::findDeviceByNameContains("tty.usbmodem");
		serial = Serial( dev, 9600);
	}
	catch( ... ) {
		console() << "There was an error initializing the serial device!" << std::endl;
		exit( -1 );
	}
	contact = 0;
	serial.flush();
    
    //OSC SETUP
    port = 12346;
    host = "127.0.0.1";
    sender.setup( host, port, true );

    
    
    
}
Ejemplo n.º 5
0
void RogalarmApp::update()
{
    setFullScreen(mFullscreen);
	
	
	if (mKinectConected) {
		lookingForUser();
		
	}
	
	osc::Message message;
	message.addFloatArg(mUserPos);
	if (mUser) {
		message.setAddress("/user/1");
	} else {
		message.setAddress("/nouser");
	}
	message.setRemoteEndpoint(mHost, mPort);
	mSender.sendMessage(message);
	
	if (!mKinectConected) {
		try {
			mKinect = Kinect( Kinect::Device() );
			mKinectConected = true;
			
		} catch( ... ){
			mKinectConected = false;
		}
	}


}
Ejemplo n.º 6
0
void MilluminApp::setup()
{
	listener.setup(5001);
	host = "127.0.0.1";
	port = 5000;
	sender.setup(host, port);
    
    
	mTex = gl::Texture(200, 100); //create our texture to publish
	mSurface = Surface8u(200, 100, false); //create a surface to manipulate
	randomizeSurface(&mSurface); //randomize our surface
	mTex.update(mSurface); //tell the texture about our changes
	
	archimedes.set(100.f, 0.6f); //set up and calculate our spiral
	archimedes.calc();
	mRot = 0.f;
	
	mScreenSyphon.setName("Cinder Screen"); // set a name for each item to be published
	mTextureSyphon.setName("Cinder Texture");
	
	mClientSyphon.setup();
    
	// in order for this to work, you must run simple server from the testapps directory
	// any other syphon item you create would work as well, just change the name
    mClientSyphon.setApplicationName("Simple Server");
    mClientSyphon.setServerName("");
	
	mClientSyphon.bind();
}
void ShimmerInterfaceApp::setup()
{
	showWin32Console();

	/*
	* Start the MATLAB engine
	*/
	if (!(ep = engOpen(NULL))) {
//		MessageBox((HWND)NULL, L"Can't start MATLAB engine",
//			L"Engwindemo.c", MB_OK);
//		exit(-1);
		cout << "Unable to start MATLAB engine... \n";
	}
	else cout << "MATLAB engine started! WUT.\n";

	//create a Shimmer wrapper to interface with the sensor
	shimmer = new ShimmerWrapper(ep, 0);

	sender.setup(SHIMMER_IPADDR, SHIMMER_PORT);
	serverSender.setup(SHIMMER_IPADDR, SC_SERVER_PORT);
}
void GesichtertauschApp::heartbeat(double mDeltaTime) {
    mWatchdogCounter += mDeltaTime;
    if (mWatchdogCounter > mWatchdogInterval) {
        mWatchdogCounter = 0.0;
        console() << "+++ heartbeat" << std::endl;
        osc::Message mMessage;
        mMessage.addIntArg(getpid());
        mMessage.setAddress("/watchdog/register");
        mMessage.setRemoteEndpoint(mWatchdogHost, mWatchdogPort);
        mWatchdogSender.sendMessage(mMessage);
    }    
}
Ejemplo n.º 9
0
void MilluminApp::update()
{
	while (listener.hasWaitingMessages()) {
		osc::Message message;
		listener.getNextMessage(&message);
		console() << "New message received" << std::endl;
		console() << "Address: " << message.getAddress() << std::endl;
		console() << "Num Arg: " << message.getNumArgs() << std::endl;
		for (int i = 0; i < message.getNumArgs(); i++) {
			console() << "-- Argument " << i << std::endl;
			console() << "---- type: " << message.getArgTypeName(i) << std::endl;
			if (message.getArgType(i) == osc::TYPE_INT32){
				try {
					console() << "------ value: "<< message.getArgAsInt32(i) << std::endl;
				}
				catch (int value) {
					console() << "------ value through exception: "<< value << std::endl;
				}
				
			}else if (message.getArgType(i) == osc::TYPE_FLOAT){
				try {
					console() << "------ value: " << message.getArgAsFloat(i) << std::endl;
				}
				catch (float val) {
					console() << "------ value trough exception: " << val << std::endl;
				}
                mRot += 1.f;
			}else if (message.getArgType(i) == osc::TYPE_STRING){
				try {
					console() << "------ value: " << message.getArgAsString(i).c_str() << std::endl;
				}
				catch (std::string str) {
					console() << "------ value: " << str << std::endl;
				}
			}
		}
	}
	osc::Message message;
	message.addFloatArg(  (cos(getElapsedSeconds()) / 2.0f + .5f)*100.f  );
	message.setAddress("/millumin/selectedLayer/opacity");
	message.setRemoteEndpoint(host, port);
	sender.sendMessage(message);
    
    
	if(getElapsedFrames() % 2 == 0) // for those of us with slower computers
		randomizeSurface(&mSurface);
	mTex.update(mSurface);
	mRot += 0.2f;
}
void GesichtertauschApp::setup() {
    
    console() << "+++ Gesichtertausch (PID " << getpid() << ")." << endl;
    
    mTime = 0.0;
    mSerialID = 0;
    FACE_COLOR_UNO = ColorA(0, 1, 1, 1);
    FACE_COLOR_DUO = ColorA(1, 0, 0, 1);
    BACKGROUND_IMAGE_COLOR = ColorA(1, 1, 1, 1);
    
    /* watchdog */
    mWatchdogHost = "localhost";
	mWatchdogPort = 8080;
	mWatchdogSender.setup(mWatchdogHost, mWatchdogPort);
    mWatchdogCounter = 0.0;
    mWatchdogInterval = 2.5;
    
    /* shader */
    try {
		mShader = gl::GlslProg( loadResource( RES_PASSTHRU_VERT ), loadResource( RES_BLUR_FRAG ) );
	}
	catch( gl::GlslProgCompileExc &exc ) {
		console() << "Shader compile error: " << std::endl;
		console() << exc.what();
	}
	catch( ... ) {
		console() << "Unable to load shader" << std::endl;
	}
    
    /* settings */
    mGui = new SimpleGUI(this);
    mGui->addParam("WINDOW_WIDTH", &WINDOW_WIDTH, 0, 2048, 640);
    mGui->addParam("WINDOW_HEIGHT", &WINDOW_HEIGHT, 0, 2048, 480);
    mGui->addParam("CAMERA_WIDTH", &CAMERA_WIDTH, 0, 2048, 640);
    mGui->addParam("CAMERA_HEIGHT", &CAMERA_HEIGHT, 0, 2048, 480);
    mGui->addParam("DETECTION_WIDTH", &DETECTION_WIDTH, 0, 2048, 320);
    mGui->addParam("DETECTION_HEIGHT", &DETECTION_HEIGHT, 0, 2048, 240);
    mGui->addParam("FULLSCREEN", &FULLSCREEN, false, 0);
    mGui->addParam("TRACKING", &TRACKING, 0, 1, 0);
    //
    mGui->addParam("FRAME_RATE", &FRAME_RATE, 1, 120, 30);
    mGui->addParam("MIN_TRACKING_DISTANCE", &MIN_TRACKING_DISTANCE, 1, 100, 50);
    mGui->addParam("TIME_BEFOR_IDLE_DEATH", &TIME_BEFOR_IDLE_DEATH, 0, 10, 0.5);
    mGui->addParam("MIN_LIFETIME_TO_VIEW", &MIN_LIFETIME_TO_VIEW, 0, 10, 1.0);
    mGui->addParam("ENABLE_SHADER", &ENABLE_SHADER, 0, 1, 0);
    mGui->addParam("FACE_COLOR_UNO", &FACE_COLOR_UNO, ColorA(0, 1, 1, 1), SimpleGUI::RGB);
    mGui->addParam("FACE_COLOR_DUO", &FACE_COLOR_DUO, ColorA(1, 1, 1, 1), SimpleGUI::RGB);
    mGui->addParam("BACKGROUND_IMAGE_COLOR", &BACKGROUND_IMAGE_COLOR, ColorA(1, 1, 1, 1), SimpleGUI::RGB);
    mGui->addParam("FACE_BORDER_SCALE", &FACE_BORDER_SCALE, 0, 3, 0.7);
    mGui->addParam("FACE_FADE_BORDER_SCALE", &FACE_FADE_BORDER_SCALE, 1, 2, 1.4);
            
    /* clean up controller window */
    mGui->getControlByName("WINDOW_WIDTH")->active=false;
    mGui->getControlByName("WINDOW_HEIGHT")->active=false;
    mGui->getControlByName("CAMERA_WIDTH")->active=false;
    mGui->getControlByName("CAMERA_HEIGHT")->active=false;
    mGui->getControlByName("DETECTION_WIDTH")->active=false;
    mGui->getControlByName("DETECTION_HEIGHT")->active=false;
    mGui->getControlByName("FULLSCREEN")->active=false;
    mGui->getControlByName("TRACKING")->active=false;
    mGui->getControlByName("BACKGROUND_IMAGE_COLOR")->active=false;
    mGui->getControlByName("BACKGROUND_IMAGE_COLOR")->active=false;
    
    mGui->load(getResourcePath(RES_SETTINGS));
    mGui->setEnabled(false);
    
    setWindowSize( WINDOW_WIDTH, WINDOW_HEIGHT );
    setFullScreen( FULLSCREEN );
    if (FULLSCREEN) {
        hideCursor();
//        switch_resolution (WINDOW_WIDTH, WINDOW_HEIGHT, 60.0);
    }
    
    mFont = Font(loadResource("pf_tempesta_seven.ttf"), 8);

    /* setting up capture device */
    mCameraTexture = gl::Texture(CAMERA_WIDTH, CAMERA_HEIGHT);
    switch (TRACKING) {
        case 0:
            mFaceDetection = new FeatureDetectionCinder();
            break;
#ifdef COMPILE_CAPTURE_FIREFLY
        case 1:
            mFaceDetection = new FeatureDetectionFireFly();
            break;
#endif
#ifdef COMPILE_CAPTURE_OPENCV
        case 2:
            mFaceDetection = new FeatureDetectionOpenCV();
            break;
#endif
        default:
            console() << "### choosing default tracking method." << endl;
            mFaceDetection = new FeatureDetectionCinder();
            break;
    }

    mGui->addParam("DETECT_FLAGS",&(mFaceDetection->DETECT_FLAGS), CV_HAAR_DO_CANNY_PRUNING, CV_HAAR_DO_ROUGH_SEARCH, CV_HAAR_DO_CANNY_PRUNING);
    mGui->addParam("DETECT_SCALE_FACTOR",&(mFaceDetection->DETECT_SCALE_FACTOR), 1.1, 5, 1.2);
    mGui->addParam("DETECT_MIN_NEIGHBORS",&(mFaceDetection->DETECT_MIN_NEIGHBORS), 1, 20, 2);

    mGui->addParam("CAMERA_EXPOSURE", &(mFaceDetection->CAMERA_EXPOSURE), 0, 255, 20);
    mGui->addParam("CAMERA_SHUTTER", &(mFaceDetection->CAMERA_SHUTTER), 0, 255, 200);
    mGui->addParam("CAMERA_BRIGHTNESS", &(mFaceDetection->CAMERA_BRIGHTNESS), 0, 255, 166);
    mGui->addParam("CAMERA_GAIN", &(mFaceDetection->CAMERA_GAIN), 0, 255, 17);

    mGui->load(getResourcePath(RES_SETTINGS)); // HACK this is quite stupid, but we have a catch 22 here ...
    mFaceDetection->setup(CAMERA_WIDTH, 
                          CAMERA_HEIGHT, 
                          DETECTION_WIDTH, 
                          DETECTION_HEIGHT,
                          0);
    mGui->dump();
    
    mGui->addSeparator();
    mFaceOut = mGui->addLabel("");
    mFPSOut = mGui->addLabel("");
}
Ejemplo n.º 11
0
void RogalarmApp::setup()
{
	mFullscreen = false;
	mUser		= false;
	mNoUserMessage    = false;
	setFullScreen(mFullscreen);
	mUserPos = 0;
	mDebug = false;	
	mKonnect = loadImage(loadResource("konnect-kinect.jpg") );
	
	try {
		mKinect = Kinect( Kinect::Device() );
		mKinectConected = true;
		
	} catch( ... ){
		mKinectConected = false;
	}
    
    
    mConfigPath = getResourcePath().c_str();
    mConfigPath += "settings.sgui.txt";
   
	
    
	mStopedTime = getElapsedSeconds();
	
	
	mTargetPosition = Vec3f::zero();
	
	mContourTexture = gl::Texture(getWindowWidth(), getWindowHeight());
	mDepthTexture = gl::Texture(getWindowWidth(), getWindowHeight());
	
	mGui = new SimpleGUI(this);
	mGui->lightColor = ColorA(1, 1, 0, 1);
	
	mGui->addLabel("CONTROLS");
	mGui->addParam("Depth Threshold", &mThreshold, 0, 255, 70);
	mGui->addParam("Min Contour Area", &mBlobMin, 10, 100, 30);
	mGui->addParam("Max Contour Area", &mBlobMax, 100, 500, 200);
	mGui->addSeparator();
	mGui->addParam("Reflection Top", &mReflectionTop, 0, 480, 0);
	mGui->addParam("Reflection Bottom", &mReflectionBottom, 0, 480, 0);
	mGui->addSeparator();
	mGui->addLabel("OPTIONS");
	mGui->addParam("Fullscreen (f)", &mFullscreen, false);
	mGui->addButton("Save Configuration")->registerClick(this, &RogalarmApp::openSaveConfigClick);
	mGui->addColumn(142, 7);
	mGui->addLabel("Contour Image");
	mGui->addParam("Contour Texture", &mContourTexture); 
	mGui->addLabel("Depth Image");
	mGui->addParam("Depth Texture", &mDepthTexture);
	
	mGui->load(mConfigPath);
	
	mHost = "10.0.1.137";
	mPort = 7110;
	mSender.setup(mHost, mPort);



}
Ejemplo n.º 12
0
void RogalarmApp::lookingForUser() {
	if( mKinect.checkNewDepthFrame() ){
		
		
		ImageSourceRef depthImage = mKinect.getDepthImage();
		
		// make a texture to display
		mDepthTexture = depthImage;
		// make a surface for opencv
		mDepthSurface = depthImage;
		
		if(mDepthSurface){
			
			// once the surface is avalable pass it to opencv
			// had trouble here with bit depth. surface comes in full color, needed to crush it down
			cv::Mat tmp( toOcv( Channel8u( mDepthSurface )  ) ), input, blurred, thresholded, thresholded2, output;
			
			if (mReflectionBottom > 0) {
				cv::Scalar black( 0, 0, 0 );
				cv::Point p1 = cv::Point(0,480 - mReflectionBottom-1);
				cv::Point p2 = cv::Point(640, 480);
				cv::rectangle(tmp, p1, p2, black, -1, 8, 0);
			}
			
			if (mReflectionTop > 0) {
				cv::Scalar black( 0, 0, 0 );
				cv::Point p1 = cv::Point(0, 0);
				cv::Point p2 = cv::Point(640, mReflectionTop);
				cv::rectangle(tmp, p1, p2, black, -1, 8, 0);
			}
			
			//tmp.copyTo(input, mBackground);
			
			cv::blur(tmp, blurred, cv::Size(10,10));
			
			// make two thresholded images one to display and one
			// to pass to find contours since its process alters the image
			cv::threshold( blurred, thresholded, mThreshold, 255, CV_THRESH_BINARY);
			cv::threshold( blurred, thresholded2, mThreshold, 255, CV_THRESH_BINARY);
			
			// 2d vector to store the found contours
			vector<vector<cv::Point> > contours;
			// find em
			cv::findContours(thresholded, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
			
			// convert theshold image to color for output
			// so we can draw blobs on it
			cv::cvtColor( thresholded2, output, CV_GRAY2RGB );
			cv::Scalar color( 0, 255, 255 );
			mUser = false;
			
			// loop the stored contours
			for (vector<vector<cv::Point> >::iterator it=contours.begin() ; it < contours.end(); it++ ){
				
				// center abd radius for current blob
				cv::Point2f center;
				float radius;
				// convert the cuntour point to a matrix 
				vector<cv::Point> pts = *it;
				cv::Mat pointsMatrix = cv::Mat(pts);
				// pass to min enclosing circle to make the blob 
				cv::minEnclosingCircle(pointsMatrix, center, radius);
				
				
				if (radius > mBlobMin && radius < mBlobMax) {
					mUserPos = 640 - center.x;
					mUser = true;
					if (mNoUserMessage == false) {
						mNoUserMessage = true;
					}
					
					cv::circle(output, center, radius, color, 3);
					
					mStopedTime = getElapsedSeconds();
					
					
					osc::Message message;
					message.addFloatArg(mUserPos);
					message.setAddress("/user/1");
					message.setRemoteEndpoint(mHost, mPort);
					mSender.sendMessage(message);
					
                    
				} else if (mNoUserMessage) {
					osc::Message message;
					message.addFloatArg(mUserPos);
					message.setAddress("/nouser");
					message.setRemoteEndpoint(mHost, mPort);
					mSender.sendMessage(message);
					
					mNoUserMessage = false;
					
				} 					
			}	
			
			cv::Scalar yellow( 0, 255, 255 );
			
			if (mReflectionBottom > 0) {
				
				cv::Point p1 = cv::Point(0, 480 - mReflectionBottom-1);
				cv::Point p2 = cv::Point(640, 480);
				cv::rectangle(output, p1, p2, yellow, -1, 8, 0);
			}
			
			if (mReflectionTop > 0) {
				cv::Scalar black( 0, 0, 0 );
				cv::Point p1 = cv::Point(0, 0);
				cv::Point p2 = cv::Point(640, mReflectionTop);
				cv::rectangle(output, p1, p2, yellow, -1, 8, 0);
			}
			
			mContourTexture = gl::Texture( fromOcv( output ) );
		}
	}
    
	if( mKinect.checkNewVideoFrame() )
		mColorTexture = mKinect.getVideoImage();
    
}