void URealSenseTask::EnableHandDetection(bool enable)
{
	if (!collector->IsValid()){
		UE_LOG(RealSensePluginLog, Warning, TEXT("RealSense unavailable."));
		return;
	}

	//local pointer
	PXCSenseManager* pp = collector->psm;

	pxcStatus status = pxcStatus::PXC_STATUS_NO_ERROR;
	/* Set Module */
	if (!enable){
		collector->handModule->Release();
		// Hand Module Configuration
		PXCHandConfiguration* config = collector->handModule->CreateActiveConfiguration();
		config->DisableAllAlerts();

		config->ApplyChanges();
		config->Update();

		collector->handConfig = config;

		HandsEnabled = false;
		return;
	}
	if (enable)
	{
		status = pp->EnableHand();
		collector->handModule = pp->QueryHand();
	}

	PXCHandModule* handModule = collector->handModule;

	if (handModule == NULL || status != pxcStatus::PXC_STATUS_NO_ERROR)
	{
		UE_LOG(RealSensePluginLog, Log, TEXT("Failed to pair the hand module with I/O"));
		return;
	}

	if (pp->Init(collector) >= PXC_STATUS_NO_ERROR)
	{
		collector->handData = collector->handModule->CreateOutput();
	}

	// Hand Module Configuration
	PXCHandConfiguration* config = handModule->CreateActiveConfiguration();
	config->EnableNormalizedJoints(true);
	if (true) config->SetTrackingMode(PXCHandData::TRACKING_MODE_FULL_HAND);
	config->EnableAllAlerts();
	//config->EnableSegmentationImage(true);

	config->ApplyChanges();
	config->Update();

	collector->handConfig = config;

	HandsEnabled = true;
}
Exemple #2
0
void ITA_ForcesApp::setupRS()
{
	mHasHand = false;
	mIsRunning = false;

	mRS = PXCSenseManager::CreateInstance();
	if (mRS == nullptr)
	{
		console() << "Unable to Create SenseManager" << endl;
		return;
	}
	else
	{
		console() << "Created SenseManager" << endl;
		auto stat = mRS->EnableStream(PXCCapture::STREAM_TYPE_COLOR, RGB_SIZE.x, RGB_SIZE.y, 60);
		if (stat >= PXC_STATUS_NO_ERROR) {
			console() << "Color Stream Enabled" << endl;
		}
		stat = mRS->EnableStream(PXCCapture::STREAM_TYPE_DEPTH, Z_SIZE.x, Z_SIZE.y, 60);
		if (stat >= PXC_STATUS_NO_ERROR) {
			console() << "Depth Stream Enabled" << endl;
		}

		stat = mRS->EnableHand();

		if ((stat >= PXC_STATUS_NO_ERROR))//&& (handModule != nullptr))
		{
			stat = mRS->Init();
			auto handModule = mRS->QueryHand();

			if (stat >= PXC_STATUS_NO_ERROR)
			{
				auto depthSize = mRS->QueryCaptureManager()->QueryImageSize(PXCCapture::STREAM_TYPE_DEPTH);
				console() << "DepthSize: " << to_string(depthSize.width) << " " << to_string(depthSize.height) << endl;

				auto colorSize = mRS->QueryCaptureManager()->QueryImageSize(PXCCapture::STREAM_TYPE_COLOR);
				console() << "ColorSize: " << to_string(colorSize.width) << " " << to_string(colorSize.height) << endl;

				mHandData = handModule->CreateOutput();
				auto cfg = handModule->CreateActiveConfiguration();
				if (cfg != nullptr)
				{
					stat = cfg->SetTrackingMode(PXCHandData::TRACKING_MODE_CURSOR);
					if (stat >= PXC_STATUS_NO_ERROR)
						stat = cfg->EnableAllAlerts();
					if (stat >= PXC_STATUS_NO_ERROR)
						stat = cfg->EnableAllGestures(false);
					if (stat >= PXC_STATUS_NO_ERROR)
						stat = cfg->ApplyChanges();
					if (stat >= PXC_STATUS_NO_ERROR)
						cfg->Update();
					if (stat >= PXC_STATUS_NO_ERROR)
					{
						console() << "Hand Tracking Enabled" << endl;
						cfg->Release();
						mRS->QueryCaptureManager()->QueryDevice()->SetMirrorMode(PXCCapture::Device::MIRROR_MODE_HORIZONTAL);
						mIsRunning = true;
					}
				}
				else {
					console() << "Unable to Configure Hand Tracking" << endl;
				}
				mMapper = mRS->QueryCaptureManager()->QueryDevice()->CreateProjection();
				if (mMapper==nullptr) {
					CI_LOG_W("Unable to get coordinate mapper");
				}
			}
			else
				console() << "Unable to Start SenseManager" << endl;
		}
	}
}
int main(char* args,char* argsc) {

	pxcStatus status = PXC_STATUS_ALLOC_FAILED;

	PXCSenseManager *session =  PXCSenseManager::CreateInstance();
	if(!session) {
		printf("Instance create failed\n");
		return 10;
	}

	status = session->EnableHand(nullptr);

	if(status = PXC_STATUS_NO_ERROR) {
		printf("Hand data unavailable\n");
		return 20;
	}

	session->Init();

	if(status = PXC_STATUS_NO_ERROR) {
		printf("init failed\n");
		return 30;
	}

	PXCHandModule* handTracker = session->QueryHand();
	

	if(status = PXC_STATUS_NO_ERROR) {
		printf("no hand tracking support\n");
		return 40;
	}

	PXCHandConfiguration* handConfig = handTracker->CreateActiveConfiguration();
	handConfig->EnableAllGestures();
	handConfig->ApplyChanges();

	PXCHandData* handData = handTracker->CreateOutput();
	bool running = true;

	status = session->EnableStream(PXCCapture::StreamType::STREAM_TYPE_DEPTH,1920,1080,30.0);

	if (status = PXC_STATUS_NO_ERROR) {
		printf("Unknown error when enabling stream.");
		return 50;
	}

	while(running) {
		//printf("Acquire frame. ");
		status = session->AcquireFrame(true);
		//printf("Got frame.\n");
		if(status >= PXC_STATUS_NO_ERROR) {
			printf("He's dead Jim.\n");
			return 50;
		}

		handData->Update();
		//printf("Got %i gestures for %i hands.\n", handData->QueryFiredGesturesNumber(),handData->QueryNumberOfHands());
		for(int i=0; i<handData->QueryFiredGesturesNumber(); i++) {
			PXCHandData::GestureData gestureData;
			handData->QueryFiredGestureData(i,gestureData);
			
			
			wchar_t* name = (wchar_t*)gestureData.name;
			std::wstring nameStr(name);
			std::wcout << nameStr << std::endl;
			
			//printf("%s - len %d\n",nameStr.c_str(), nameStr.size());

			if(nameStr == L"v_sign") {
				running = false;
			}
		}

		PXCCapture::Sample* capture = session->QuerySample();
		PXCImage* depthImage = capture->depth;

		//std::this_thread::sleep_for(std::chrono::milliseconds(10));

		session->ReleaseFrame();
	}

	session->Release();

	return 0;
}