int configKinect(){ XnStatus rc = XN_STATUS_OK; xn::EnumerationErrors errors; // Initialize OpenNI rc = g_Context.InitFromXmlFile(SAMPLE_XML_PATH, g_ScriptNode, &errors); CHECK_ERRORS(rc, errors, "InitFromXmlFile"); CHECK_RC(rc, "InitFromXmlFile"); rc = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator); CHECK_RC(rc, "Find depth generator"); rc = g_Context.FindExistingNode(XN_NODE_TYPE_GESTURE, g_GestureGenerator); CHECK_RC(rc, "Find gesture generator"); XnCallbackHandle hGestureIntermediateStageCompleted, hGestureProgress, hGestureReadyForNextIntermediateStage; g_GestureGenerator.RegisterToGestureIntermediateStageCompleted(GestureIntermediateStageCompletedHandler, NULL, hGestureIntermediateStageCompleted); g_GestureGenerator.RegisterToGestureReadyForNextIntermediateStage(GestureReadyForNextIntermediateStageHandler, NULL, hGestureReadyForNextIntermediateStage); g_GestureGenerator.RegisterGestureCallbacks(NULL, GestureProgressHandler, NULL, hGestureProgress); // Create NITE objects g_pSessionManager = new XnVSessionManager; rc = g_pSessionManager->Initialize(&g_Context, "Click,Wave", "RaiseHand"); CHECK_RC(rc, "SessionManager::Initialize"); g_pSessionManager->RegisterSession(NULL, SessionStarting, SessionEnding, FocusProgress); pointHandler = new PointHandler(20, g_DepthGenerator); g_pFlowRouter = new XnVFlowRouter; g_pFlowRouter->SetActive(pointHandler); g_pSessionManager->AddListener(g_pFlowRouter); pointHandler->RegisterNoPoints(NULL, NoHands); // Initialization done. Start generating rc = g_Context.StartGeneratingAll(); CHECK_RC(rc, "StartGenerating"); return rc; }
int main(int argc, char* argv[]) { // Start VideoCapture capture (CV_CAP_OPENNI); if(!capture.isOpened()) { int error = -1; return 1; } namedWindow( "Color Image", 1 ); //namedWindow( "Depth Map", 1); Mat view; bool blink = false; // NITE + openni XnStatus rc = XN_STATUS_OK; Context context; rc = context.Init(); rc = g_GestureGenerator.Create(context); rc = g_HandsGenerator.Create(context); XnCallbackHandle hcb1,hcb2; g_GestureGenerator.RegisterGestureCallbacks(Gesture_Recognized, Gesture_Process, NULL, hcb1); g_HandsGenerator.RegisterHandCallbacks(handCreate, handUpdate, handDestroy, NULL, hcb2); rc = context.StartGeneratingAll(); rc = g_GestureGenerator.AddGesture(GESTURE_TO_USE, NULL); double d = 1.0; double angle = 0.0; double angleZ = 0.0; Mat result; Mat orig = imread("crocus.jpg"); result.create(750, 750, CV_8UC3); double centerX = orig.cols/2; double centerY = orig.rows/2; warpPerspective(orig, orig, getScaleMatrix(1.0), orig.size(), INTER_CUBIC, BORDER_TRANSPARENT); while( capture.isOpened() ) { rc = context.WaitAndUpdateAll(); d = getZoom(); angle = getAngle(); angleZ = getAngle3D(); if (abs(d - oldZoom) > 0.009) { //printf("angle = %f \n",angle); oldAngle += angle; //create the transformation to be passed to warp Mat openCVTransform = getRotationMatrix2D(Point2f(centerX, centerY), oldAngle, d); //warp image to apply transformation result.setTo(Scalar(0)); warpAffine(orig, result, openCVTransform, result.size(), INTER_CUBIC, BORDER_TRANSPARENT); oldZoom = d; } imshow("Result", result); Mat bgrImage; capture.grab(); capture.retrieve( bgrImage, CV_CAP_OPENNI_BGR_IMAGE ); if (hand1ID != -1) { circle(bgrImage,Point(hand1.back().X + bgrImage.rows/2, bgrImage.cols/2 - hand1.back().Y),2,CV_RGB(0,255,0),3); } if (hand2ID != -1) { circle(bgrImage,Point(hand2.back().X + bgrImage.rows/2, bgrImage.cols/2 - hand2.back().Y),2,CV_RGB(0,255,0),3); } flip(bgrImage,bgrImage,1); imshow("Color Image", bgrImage); result.create(750, 750, CV_8UC3); if(waitKey(33) == 'q') { break; } } context.Shutdown(); return 0; }
int main(int argc, char ** argv) { XnStatus rc = XN_STATUS_OK; xn::EnumerationErrors errors; // Initialize OpenNI rc = g_Context.InitFromXmlFile(SAMPLE_XML_PATH, g_ScriptNode, &errors); CHECK_ERRORS(rc, errors, "InitFromXmlFile"); CHECK_RC(rc, "InitFromXmlFile"); rc = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator); CHECK_RC(rc, "Find depth generator"); rc = g_Context.FindExistingNode(XN_NODE_TYPE_HANDS, g_HandsGenerator); CHECK_RC(rc, "Find hands generator"); rc = g_Context.FindExistingNode(XN_NODE_TYPE_GESTURE, g_GestureGenerator); CHECK_RC(rc, "Find gesture generator"); XnCallbackHandle h; if (g_HandsGenerator.IsCapabilitySupported(XN_CAPABILITY_HAND_TOUCHING_FOV_EDGE)) { g_HandsGenerator.GetHandTouchingFOVEdgeCap().RegisterToHandTouchingFOVEdge(TouchingCallback, NULL, h); } XnCallbackHandle hGestureIntermediateStageCompleted, hGestureProgress, hGestureReadyForNextIntermediateStage; g_GestureGenerator.RegisterToGestureIntermediateStageCompleted(GestureIntermediateStageCompletedHandler, NULL, hGestureIntermediateStageCompleted); g_GestureGenerator.RegisterToGestureReadyForNextIntermediateStage(GestureReadyForNextIntermediateStageHandler, NULL, hGestureReadyForNextIntermediateStage); g_GestureGenerator.RegisterGestureCallbacks(NULL, GestureProgressHandler, NULL, hGestureProgress); // Create NITE objects g_pSessionManager = new XnVSessionManager; rc = g_pSessionManager->Initialize(&g_Context, "Click,Wave", "RaiseHand"); CHECK_RC(rc, "SessionManager::Initialize"); g_pSessionManager->RegisterSession(NULL, SessionStarting, SessionEnding, FocusProgress); g_pDrawer = new XnVPointDrawer(20, g_DepthGenerator); g_pFlowRouter = new XnVFlowRouter; g_pFlowRouter->SetActive(g_pDrawer); g_pSessionManager->AddListener(g_pFlowRouter); g_pDrawer->RegisterNoPoints(NULL, NoHands); g_pDrawer->SetDepthMap(g_bDrawDepthMap); // Initialization done. Start generating rc = g_Context.StartGeneratingAll(); CHECK_RC(rc, "StartGenerating"); // Mainloop #ifdef USE_GLUT glInit(&argc, argv); glutMainLoop(); #elif defined(USE_GLES) if (!opengles_init(GL_WIN_SIZE_X, GL_WIN_SIZE_Y, &display, &surface, &context)) { printf("Error initializing opengles\n"); CleanupExit(); } glDisable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); while ((!_kbhit()) && (!g_bQuit)) { glutDisplay(); eglSwapBuffers(display, surface); } opengles_shutdown(display, surface, context); CleanupExit(); #endif }