void Tracker::update() { if (!AcquireFrame(false)) return; if (!labelMap) return; PXCImage *image; if (QueryGesture()->QueryBlobImage(PXCGesture::Blob::LABEL_SCENE, 0, &image) >= PXC_STATUS_NO_ERROR) { PXCImage::ImageData data; if (image->AcquireAccess(PXCImage::ACCESS_READ, &data) >= PXC_STATUS_NO_ERROR) { tex.loadData(data.planes[0], tex.getWidth(), tex.getHeight(), GL_LUMINANCE); image->ReleaseAccess(&data); } } PXCGesture::Gesture *gesture = new PXCGesture::Gesture(); if (QueryGesture()->QueryGestureData(0, PXCGesture::GeoNode::LABEL_BODY_HAND_PRIMARY, 0, gesture) >= PXC_STATUS_NO_ERROR) { string name = ""; switch (gesture->label) { case PXCGesture::Gesture::LABEL_HAND_CIRCLE: name = "CIRCLE"; break; case PXCGesture::Gesture::LABEL_HAND_WAVE: name = "WAVE"; break; case PXCGesture::Gesture::LABEL_POSE_BIG5: name = "HIGH5"; break; case PXCGesture::Gesture::LABEL_POSE_THUMB_UP: name = "THUMBUP"; break; case PXCGesture::Gesture::LABEL_POSE_THUMB_DOWN: name = "THUMBDOWN"; break; case PXCGesture::Gesture::LABEL_NAV_SWIPE_DOWN: name = "SWIPEDOWN"; break; case PXCGesture::Gesture::LABEL_NAV_SWIPE_LEFT: name = "SWIPELEFT"; break; case PXCGesture::Gesture::LABEL_NAV_SWIPE_RIGHT: name = "SWIPERIGHT"; break; case PXCGesture::Gesture::LABEL_NAV_SWIPE_UP: name = "SWIPEUP"; break; } if (name != "") { if (!timeout.isRunning()) { timeout.setParameters(easing, ofxTween::easeIn, 0, 1, 1000, 0); // ONLY SEND ONCE PER SECOND ofSendMessage("GESTURE_" + name); } } } if (timeout.isRunning()) timeout.update(); PXCGesture::GeoNode indexData; QueryGesture()->QueryNodeData(0, PXCGesture::GeoNode::LABEL_BODY_HAND_PRIMARY|PXCGesture::GeoNode::LABEL_FINGER_THUMB, &indexData); ofPoint p; p.x = ofMap(indexData.positionImage.x, 0, 320, ofGetWidth(), 0, true); p.y = ofMap(indexData.positionImage.y, 0, 240, 0, ofGetHeight(), true); p.z = indexData.radiusImage; ofNotifyEvent(GEONODE_POSITION_CHANGE, p); ReleaseFrame(); }
bool KinectCapture::Initialize() { HRESULT hr; hr = GetDefaultKinectSensor(&pKinectSensor); if (FAILED(hr)) { bInitialized = false; return bInitialized; } if (pKinectSensor) { pKinectSensor->get_CoordinateMapper(&pCoordinateMapper); hr = pKinectSensor->Open(); if (SUCCEEDED(hr)) { pKinectSensor->OpenMultiSourceFrameReader(FrameSourceTypes::FrameSourceTypes_Color | FrameSourceTypes::FrameSourceTypes_Depth | FrameSourceTypes::FrameSourceTypes_Body | FrameSourceTypes::FrameSourceTypes_BodyIndex, &pMultiSourceFrameReader); } } bInitialized = SUCCEEDED(hr); if (bInitialized) { std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now(); bool bTemp; do { bTemp = AcquireFrame(); std::chrono::duration<double> elapsedSeconds = std::chrono::system_clock::now() - start; if (elapsedSeconds.count() > 5.0) { bInitialized = false; break; } } while (!bTemp); } return bInitialized; }
/** Grab a Frame from either camera or video source * */ int GrabFrame(Experiment* exp) { if (!(exp->VidFromFile)) { /** Acquire from Physical Camera **/ if (exp->UseFrameGrabber) { /** Use BitFlow SDK to acquire from Frame Grabber **/ if (AcquireFrame(exp->fg)==T2FG_ERROR){ return EXP_ERROR; } /** Check to see if file sizes match **/ LoadFrameWithBin(exp->fg->HostBuf, exp->fromCCD); } else { /** Acqure from ImagingSource USB Cam **/ exp->lastFrameSeenOutside = exp->MyCamera->iFrameNumber; /*** Create a local copy of the image***/ LoadFrameWithBin(exp->MyCamera->iImageData, exp->fromCCD); } } else { /** Acquire from file **/ IplImage* tempImg; /** Grab the frame from the video **/ tempImg = cvQueryFrame(exp->capture); /** Stall for a little bit **/ //Sleep(50); if (tempImg == NULL) { printf("There was an error querying the frame from video!\n"); return EXP_VIDEO_RAN_OUT; } /** Create a new temp image that is grayscale and of the same size **/ IplImage* tempImgGray = cvCreateImage(cvGetSize(tempImg), IPL_DEPTH_8U, 1); /** Convert Color to GrayScale **/ cvCvtColor(tempImg, tempImgGray, CV_RGB2GRAY); /** Load the frame into the fromCCD frame object **/ /*** ANDY! THIS WILL FAIL BECAUSE THE SIZING ISN'T RIGHT **/ LoadFrameWithImage(tempImgGray, exp->fromCCD); cvReleaseImage(&tempImgGray); /* * Note: for some reason thinks crash when you go cvReleaseImage(&tempImg) * And there don't seem to be memory leaks if you leave it. So I'm going to leave it in place. * */ } exp->Worm->frameNum++; return EXP_SUCCESS; }