コード例 #1
0
 void KinectSDKGrabber::PreRun()
 {
     HRESULT hr = CreateFirstConnected();
     if (FAILED(hr))
     {
         throw HPEException("KinectSDKGrabber::PreRun() - CreateFirstConnected() failed");
     }
 }
コード例 #2
0
/// <summary>
/// Handle windows messages for the class instance
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
LRESULT CALLBACK KinectEasyGrabber::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
        {
            // Bind application window handle
            m_hWnd = hWnd;

            // Init Direct2D
            D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

            // Create and initialize a new Direct2D image renderer (take a look at ImageRenderer.h)
            // We'll use this to draw the data we receive from the Kinect to the screen
            m_pDrawKinectEasyGrabber = new ImageRenderer();
            HRESULT hr = m_pDrawKinectEasyGrabber->Initialize(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), m_pD2DFactory, m_colorWidth, m_colorHeight, m_colorWidth * sizeof(long));
            if (FAILED(hr))
            {
                SetStatusMessage(L"Failed to initialize the Direct2D draw device.");
            }

            // Look for a connected Kinect, and create it if found
            CreateFirstConnected();
        }
        break;

        // If the titlebar X is clicked, destroy app
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            // Quit the main message pump
            PostQuitMessage(0);
            break;

        // Handle button press
        case WM_COMMAND:
            // If it was for the near mode control and a clicked event, change near mode
            if (IDC_CHECK_NEARMODE == LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
            {
                // Toggle out internal state for near mode
                m_bNearMode = !m_bNearMode;

                if (NULL != m_pNuiSensor)
                {
                    // Set near mode based on our internal state
                    m_pNuiSensor->NuiImageStreamSetImageFrameFlags(m_pDepthStreamHandle, m_bNearMode ? NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE : 0);
                }
            }
            break;
    }

    return FALSE;
}
コード例 #3
0
ファイル: ColorBasics.cpp プロジェクト: emmanouil/MOOOK
/// <summary>
/// Handle windows messages for the class instance
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
LRESULT CALLBACK CColorBasics::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
        {
            // Bind application window handle
            m_hWnd = hWnd;

            // Init Direct2D
            D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

            // Create and initialize a new Direct2D image renderer (take a look at ImageRenderer.h)
            // We'll use this to draw the data we receive from the Kinect to the screen
            m_pDrawColor = new ImageRenderer();
            HRESULT hr = m_pDrawColor->Initialize(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), m_pD2DFactory, cColorWidth, cColorHeight, cColorWidth * sizeof(long));
            if (FAILED(hr))
            {
                SetStatusMessage(L"Failed to initialize the Direct2D draw device.");
            }

            // Look for a connected Kinect, and create it if found
            CreateFirstConnected();
        }
        break;

        // If the titlebar X is clicked, destroy app
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            // Quit the main message pump
            PostQuitMessage(0);
            break;

        // Handle button press
        case WM_COMMAND:
            // If it was for the screenshot control and a button clicked event, save a screenshot next frame 
            if (IDC_BUTTON_SCREENSHOT == LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
            {
                m_bSaveScreenshot = true;
            }
            break;
    }

    return FALSE;
}
コード例 #4
0
KinectReader::KinectReader( unsigned int min_depth, unsigned int max_depth, float dist ):
    m_pKinectAudioStream(NULL),
    m_pSpeechStream(NULL),
    m_pSpeechRecognizer(NULL),
    m_pSpeechContext(NULL),
    m_pSpeechGrammar(NULL),
    m_hSpeechEvent(INVALID_HANDLE_VALUE)
{
	m_depth = new float[640*480];
	memset(m_depth, 0, 640*480*sizeof(float));
	m_pNuiSensor = NULL;
	CreateFirstConnected();
	_min_depth = min_depth;
	_max_depth = max_depth;
	_active_depth = dist;
}
コード例 #5
0
/// <summary>
/// Handle windows messages for the class instance
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
LRESULT CALLBACK CSkeletonBasics::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
        {
            // Bind application window handle
            m_hWnd = hWnd;

            // Init Direct2D
            D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

            // Look for a connected Kinect, and create it if found
            CreateFirstConnected();
        }
        break;

        // If the titlebar X is clicked, destroy app
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            // Quit the main message pump
            PostQuitMessage(0);
            break;

        // Handle button press
        case WM_COMMAND:
            // If it was for the near mode control and a clicked event, change near mode
            if (IDC_CHECK_SEATED == LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
            {
                // Toggle out internal state for near mode
                m_bSeatedMode = !m_bSeatedMode;

                if (NULL != m_pNuiSensor)
                {
                    // Set near mode for sensor based on our internal state
                    m_pNuiSensor->NuiSkeletonTrackingEnable(m_hNextSkeletonEvent, m_bSeatedMode ? NUI_SKELETON_TRACKING_FLAG_ENABLE_SEATED_SUPPORT : 0);
                }
            }
            break;
    }

    return FALSE;
}
コード例 #6
0
/// <summary>
/// Update the sensor and status based on the input changeg flags
/// <param name="changedFlags">Sensor chooser flag indicating kinect sensor change status</param>
/// </summary>
void CBackgroundRemovalBasics::UpdateSensorAndStatus(DWORD changedFlags)
{
    switch(changedFlags)
    {
    case NUISENSORCHOOSER_SENSOR_CHANGED_FLAG:
        {
            // Free the previous sensor and try to get a new one
            SafeRelease(m_pNuiSensor);
            HRESULT hr = CreateFirstConnected();
            if (SUCCEEDED(hr))
            {
                CreateBackgroundRemovedColorStream();
            }
        }

    case NUISENSORCHOOSER_STATUS_CHANGED_FLAG:
        UpdateNscControlStatus();
        break;
    }
}
コード例 #7
0
ファイル: DataCollection.cpp プロジェクト: eaglesky/ARLK
/// <summary>
/// Handle windows messages for the class instance
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
LRESULT CALLBACK CDataCollection::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int chour,cmin,csec;
	double dTimeInSeconds;
	WORD wDelayCharNum;
	TCHAR DelayTime[3];
	TCHAR ConstraintBuf[10];
	BROWSEINFO   bf;   
    LPITEMIDLIST   lpitem;   
	WCHAR comboItem[MAX_PATH];
//	WCHAR fileSavedMessage[50];

    switch (message)
    {
        case WM_INITDIALOG:
        {
			LOGFONT lf;
            // Bind application window handle
            m_hWnd = hWnd;

            // Init Direct2D
            D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

            // Create and initialize a new Direct2D image renderer (take a look at ImageRenderer.h)
            // We'll use this to draw the data we receive from the Kinect to the screen
            m_pDrawColor = new ImageRenderer();
			//m_pDrawDepth = new ImageRenderer();

            HRESULT hr = m_pDrawColor->Initialize(GetDlgItem(m_hWnd, IDC_COLOR), m_pD2DFactory, cColorWidth, cColorHeight, cColorWidth * sizeof(long));
            if (FAILED(hr))
            {
                SetStatusMessage(L"Failed to initialize the Direct2D draw device.");
            }

            // Look for a connected Kinect, and create it if found
            CreateFirstConnected();

			if(!SetCurrentDirectory(L"..\\output"))
				CreateDirectory(L"..\\output",NULL);
			
			//Set the font for recording time display
			GetObject( (HFONT) GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf );
			lf.lfHeight *= 3;
			SendDlgItemMessage( hWnd, IDC_SEC, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0 );
			SendDlgItemMessage( hWnd, IDC_MIN, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0 );
			SendDlgItemMessage( hWnd, IDC_HOUR, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0 );
			SendDlgItemMessage( hWnd, IDC_FRAME_SHOW, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0 );
			SendDlgItemMessage( hWnd, IDC_SEP, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0 );
			SendDlgItemMessage( hWnd, IDC_TIME_COUNT, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0 );

			SetWindowText(GetDlgItem(hWnd,IDC_DELAY),L"0");

			StringCchPrintfW(comboItem, _countof(comboItem), L"No constraints");
			SendDlgItemMessage(hWnd, IDC_MODE, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(comboItem));
			StringCchPrintfW(comboItem, _countof(comboItem), L"Time length(s)");
			SendDlgItemMessage(hWnd, IDC_MODE, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(comboItem));
			StringCchPrintfW(comboItem, _countof(comboItem), L"Frame number");
			SendDlgItemMessage(hWnd, IDC_MODE, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(comboItem));

			SendDlgItemMessage(hWnd, IDC_MODE, CB_SETCURSEL,0, 0);
			m_iRecordingModeIndex=DEFAULT_MODE;
			
		
			lastframetime=GetTickCount();
        }
        break;

        // If the titlebar X is clicked, destroy app
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            // Quit the main message pump
		
		
            PostQuitMessage(0);
            break;

        case WM_TIMER:                      //Handle timer message
			if(m_bSaveSkeStart){
			switch (wParam)  
			{  
			case TIMER_SEC:  
			
				currenttime=GetTickCount();
				dTimeInSeconds=(currenttime-starttime)/1000.0;
				csec=((currenttime-starttime)/1000)%60;
				cmin=((currenttime-starttime)/60000)%60;
				chour=((currenttime-starttime)/3600000)%24;
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_SEC),csec, FALSE );
                ::SetDlgItemInt(hWnd, static_cast<int>(IDC_MIN),cmin, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_HOUR),chour, FALSE );

				
				break ;  
		
			} 
			}
			else if (m_bIsInDelay){
				m_iDelayTime--;
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_TIME_COUNT),m_iDelayTime, FALSE );
				if(m_iDelayTime==0)
				{
					//DEBUG("Start!\n");
					
				    USES_CONVERSION;
				    const char* ascName = T2A(skefname);
					
					m_pSkeData->SaveStart(ascName,m_iFrameConstraint,m_dwTimeConstraint);
					m_bIsInDelay = false;
					m_bSaveSkeStart = true;
					starttime = GetTickCount();
					
				}
				else{
					m_bIsInDelay = true;
				}
			}
			break;

        // Handle button press
        case WM_COMMAND:
            
			

			// If it was for the start control and a button clicked event, start saving the skeleton frame
			if(IDC_START== LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
			{
                TCHAR timeString[MAX_PATH];
				WORD wSavePathNum;
                
			    m_dwTimeConstraint = 0;
				m_iFrameConstraint = 0;
				
				GetTimeFormatEx(NULL,TIME_FORCE24HOURFORMAT, NULL, L"hh'-'mm'-'ss", timeString, _countof(timeString));
				wSavePathNum=(WORD) SendDlgItemMessage(hWnd,IDC_SAVE_PATH, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0);
				if(wSavePathNum==0)
				{
                    StringCchPrintfW(skefname, _countof(skefname), L"..\\output\\KinectSkeletonVideo-%s.skd",timeString);
				}
				else{
					StringCchPrintfW(skefname, _countof(skefname), L"%s\\KinectSkeletonVideo-%s.skd",m_SkeFilePath,timeString);
				}

				//hskf=CreateFile(skefname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
				//SetFilePointer(hskf,sizeof(SKEFILEHEADER)+sizeof(SKEINFORHEADER),NULL,FILE_CURRENT);
				wDelayCharNum=(WORD) SendDlgItemMessage(hWnd,IDC_DELAY, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); 
				if (wDelayCharNum >= 3) 
				{ 
					MessageBox(hWnd, L"Too many characters!The number of characters should not be more than 3!", 
						L"Error", 
						MB_OK); 
					break;
				} 
				else if (wDelayCharNum == 0) 
				{ 
					MessageBox(hWnd, L"No characters entered.", 
						L"Error", 
						MB_OK);
					break;
				} 
				SendDlgItemMessage(hWnd,IDC_DELAY,EM_GETLINE, 
					(WPARAM) 0,       // line 0 
					(LPARAM) DelayTime);

				m_iDelayTime=::StrToInt(DelayTime);
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_TIME_COUNT),m_iDelayTime, FALSE );
				

                SendDlgItemMessage(hWnd,IDC_CONSTRAINT,EM_GETLINE, 
						(WPARAM) 0,       // line 0 
						(LPARAM) ConstraintBuf);

				if(m_iRecordingModeIndex==TIME_MODE)
				{
					m_dwTimeConstraint=::StrToInt(ConstraintBuf);
				}
				else if(m_iRecordingModeIndex==FRAME_MODE)
				{
					m_iFrameConstraint=::StrToInt(ConstraintBuf);
				}

				::SetDlgItemInt(hWnd, static_cast<int>(IDC_SEC),0, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_MIN),0, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_HOUR),0, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_FRAME_SHOW),0, FALSE );
				 
				if(m_iDelayTime==0)
				{
					//DEBUG("Start!\n");
					m_pSkeData->SaveStart((const char*)skefname,m_iFrameConstraint,m_dwTimeConstraint);
					m_bSaveSkeStart = true;
					

				} else {
				   
					m_bIsInDelay = true;
				}
				SetTimer (hWnd, TIMER_SEC, 1000, NULL) ;
			}

			// If it was for the stop control and a button clicked event, stop saving the skeleton frame
			if(IDC_STOP== LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
			{
				if(m_bSaveSkeStart)
				{
					KillTimer (hWnd, TIMER_SEC) ;
					m_bSaveSkeStart=false;
				    m_pSkeData->SaveEnd();
					//DEBUG("Stop!\n");
				}
				else if(m_bIsInDelay){
					KillTimer (hWnd, TIMER_SEC) ;
					::SetDlgItemInt(hWnd, static_cast<int>(IDC_TIME_COUNT),0, FALSE );
                   // CloseHandle(hskf);
					DeleteFile(skefname);
					
				}
				
					
			}

			if(IDC_BROWSE== LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
			{
				memset(&bf,0,sizeof(BROWSEINFO));   
                bf.hwndOwner=hWnd;   
                bf.lpszTitle=L"Choose the directory";   
                bf.ulFlags=BIF_RETURNONLYFSDIRS;    
                lpitem=SHBrowseForFolder(&bf);
				SHGetPathFromIDList(lpitem,m_SkeFilePath); 
				SetDlgItemText(hWnd,IDC_SAVE_PATH,m_SkeFilePath);
				

			}

			// If it was for the reset time control and a button clicked event, reset the time displayed to 0:0:0
			if(IDC_Reset== LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
			{
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_SEC),0, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_MIN),0, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_HOUR),0, FALSE );
				::SetDlgItemInt(hWnd, static_cast<int>(IDC_FRAME_SHOW),0, FALSE );
			}

			// If there is a change of selection in the combobox
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				 m_iRecordingModeIndex = SendMessage((HWND) lParam, (UINT) CB_GETCURSEL, 
					(WPARAM) 0, (LPARAM) 0);
				// DEBUG("Current mode:%d\n",m_iRecordingModeIndex);
				 if(m_iRecordingModeIndex==TIME_MODE)
				 {
					 SetWindowText(GetDlgItem(hWnd,IDC_CONSTRAINT),L"5");
				 }
				 else if(m_iRecordingModeIndex==FRAME_MODE)
				 {
					 SetWindowText(GetDlgItem(hWnd,IDC_CONSTRAINT),L"100");
				 }
				 else{
					 SetWindowText(GetDlgItem(hWnd,IDC_CONSTRAINT),L"");
				 }
			}
			
            break;
    }

    return FALSE;
}
コード例 #8
0
/// <summary>
/// Handle windows messages for the class instance
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
LRESULT CALLBACK CBackgroundRemovalBasics::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_INITDIALOG:
        {
            HRESULT hr;
            // Bind application window handle
            m_hWnd = hWnd;

            // Create NuiSensorChooser UI control
            RECT rc;
            GetClientRect(m_hWnd, &rc);

            POINT ptCenterTop;
            ptCenterTop.x = (rc.right - rc.left)/2;
            ptCenterTop.y = 0;

            // Create the sensor chooser UI control to show sensor status
            m_pSensorChooserUI = new NuiSensorChooserUI(m_hWnd, IDC_SENSORCHOOSER, ptCenterTop);

            // Set the sensor status callback
            NuiSetDeviceStatusCallback(StatusChangeCallback, reinterpret_cast<void*>(m_hWnd));
            // Init the sensor chooser to find a valid sensor
            m_pSensorChooser = new NuiSensorChooser();

            // Init Direct2D
            D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

            // Create and initialize a new Direct2D image renderer (take a look at ImageRenderer.h)
            // We'll use this to draw the data we receive from the Kinect to the screen
            m_pDrawBackgroundRemovalBasics = new ImageRenderer();

            hr = m_pDrawBackgroundRemovalBasics->Initialize(GetDlgItem(m_hWnd, IDC_VIDEOVIEW),
                m_pD2DFactory, m_colorWidth, m_colorHeight, m_colorWidth * cBytesPerPixel);
            if (FAILED(hr))
            {
                SetStatusMessage(L"Failed to initialize the Direct2D draw device.");
            }

            // Look for a connected Kinect, and create it if found
            hr = CreateFirstConnected();
            if (FAILED(hr))
            {
                return FALSE;
            }

            // Create the sream that does background removal and player segmentation
            hr = CreateBackgroundRemovedColorStream();
            if (FAILED(hr))
            {
                return FALSE;
            }
        }
        break;

        // If the titlebar X is clicked, destroy app
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            // Quit the main message pump
            PostQuitMessage(0);
            break;

        // Handle button press
        case WM_COMMAND:
            // If it was for the near mode control and a clicked event, change near mode
            if (IDC_CHECK_NEARMODE == LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
            {
                // Toggle out internal state for near mode
                m_bNearMode = !m_bNearMode;

                if (NULL != m_pNuiSensor)
                {
                    // Set near mode based on our internal state
                    m_pNuiSensor->NuiImageStreamSetImageFrameFlags(m_pDepthStreamHandle, m_bNearMode ? NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE : 0);
                }
            }
            break;

        case WM_NOTIFY:
        {
            const NMHDR* pNMHeader = reinterpret_cast<const NMHDR*>(lParam);
            if (pNMHeader->code == NSCN_REFRESH && pNMHeader->idFrom == IDC_SENSORCHOOSER)
            {
                // Handle refresh notification sent from NSC UI control
                DWORD dwChangeFlags;

                HRESULT hr = m_pSensorChooser->TryResolveConflict(&dwChangeFlags);
                if (SUCCEEDED(hr))
                {
                    UpdateSensorAndStatus(dwChangeFlags);
                }
            }

            return TRUE;
        }
        break;

        case WM_SENSORCHANGED:
        {
            if (NULL != m_pSensorChooser)
            {
                // Handle sensor status change event
                DWORD dwChangeFlags = 0;

                HRESULT hr = m_pSensorChooser->HandleNuiStatusChanged(&dwChangeFlags);
                if (SUCCEEDED(hr))
                {
                    UpdateSensorAndStatus(dwChangeFlags);
                }
            }
        }
        break;
    }

    return FALSE;
}