1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
int largeurCamera = 320;
int hauteurCamera = 240;
void MainWindow::openFlux()
{
HRESULT hr;
MSG msg;
destRect.top = 0;
destRect.bottom = hauteurImg;
// First Camera Setup
capture0 = cvCreateCameraCapture(0);
cvSetCaptureProperty(capture0, CV_CAP_PROP_FRAME_WIDTH, largeurCamera); // frame width
cvSetCaptureProperty(capture0, CV_CAP_PROP_FRAME_HEIGHT, hauteurCamera); // frame height
// Second Camera Setup
capture1 = cvCreateCameraCapture(1);
cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_WIDTH, largeurCamera); // frame width
cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_HEIGHT, hauteurCamera); // frame height
// Crea Fenetre
HINSTANCE hInstance = (HINSTANCE)::GetModuleHandle(NULL);
HWND hWnd = CreateWindow(L"test", L"test2", /*WS_EX_TOPMOST | WS_POPUP*/ WS_POPUPWINDOW, 0, 0, 1680, 1050, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd,1);
// Injection create3D();
_d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface
D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use
d3dpp.Windowed = FALSE; // program fullscreen
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.hDeviceWindow = winId(); // set the window to be used by Direct3D
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; // set the back buffer format to 32 bit // or D3DFMT_R8G8B8
d3dpp.BackBufferWidth = largeurImg;
d3dpp.BackBufferHeight = hauteurImg;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
d3dpp.BackBufferCount = 1;
// create a device class using this information and information from the d3dpp stuct
hr = _d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
winId(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&_d3ddev);
if (SUCCEEDED(hr)){
//3D VISION uses a single surface 2x images wide and image high
// create the surface
hr = _d3ddev->CreateOffscreenPlainSurface(largeurImg*2, hauteurImg+1, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
}
// Fin create3D()
// Injection set3D()
D3DLOCKED_RECT lock;
if (SUCCEEDED(hr)){
hr = surface->LockRect(&lock,NULL,0);
}
// write stereo signature in the last raw of the stereo image
LPNVSTEREOIMAGEHEADER pSIH = (LPNVSTEREOIMAGEHEADER)(((unsigned char *) lock.pBits) + (lock.Pitch * (hauteurImg)));
// Update the signature header values
pSIH->dwSignature = NVSTEREO_IMAGE_SIGNATURE;
pSIH->dwBPP = 32;
//pSIH->dwFlags = SIH_SWAP_EYES; // Src image has left on left and right on right, thats why this flag is not needed.
pSIH->dwFlags = SIH_SCALE_TO_FIT;
pSIH->dwWidth = largeurImg *2;
pSIH->dwHeight = hauteurImg;
if (SUCCEEDED(hr)){
// Unlock surface
hr = surface->UnlockRect();
}
// Fin set3D()
// this struct holds Windows event messages
while(TRUE)
{
// wait for the next message in the queue, store the result in 'msg'
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// translate keystroke messages into the right format
TranslateMessage(&msg);
// send the message to the WindowProc function
DispatchMessage(&msg);
}
// If the message is WM_QUIT, exit the while loop
if(msg.message == WM_QUIT)
break;
// Injection getImages()
destRect.left = largeurImg;
destRect.right = largeurImg*2;
// Chargement des deux frames dans une seule IPLIMAGE puis une seule instruction D3DXLoadSurfaceFromMemory
frameFromCamera1 = cvQueryFrame(capture1);
frameFromCamera0 = cvQueryFrame(capture0);
qTime.start();
hr = D3DXLoadSurfaceFromMemory(surface, NULL, &destRect, frameFromCamera1->imageData, D3DFMT_R8G8B8, frameFromCamera1->widthStep, NULL, &srcRect, D3DX_DEFAULT, 0);
cout << "D3DXLoadSurfaceFromMemory : " << qTime.elapsed() << endl;
destRect.left = 0;
destRect.right = largeurImg;
qTime.restart();
hr = D3DXLoadSurfaceFromMemory(surface, NULL, &destRect, frameFromCamera0->imageData, D3DFMT_R8G8B8, frameFromCamera0->widthStep, NULL, &srcRect, D3DX_DEFAULT, 0);
cout << "D3DXLoadSurfaceFromMemory 2 : " << qTime.elapsed() << endl;
// Fin getImages
// Injection paintEvent();
hr = _d3ddev->BeginScene(); // begins the 3D scene
destRect.bottom = hauteurImg;
destRect.right = largeurImg;
// Get the Backbuffer then Stretch the Surface on it.
hr = _d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &_backBuf);
hr = _d3ddev->StretchRect(surface, NULL, _backBuf, &destRect, D3DTEXF_NONE);
_backBuf->Release();
hr = EndScene();
hr = _d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame
} // Fin While TRUE
_d3ddev->Release(); // close and release the 3D device
_d3d->Release(); // close and release Direct3D
cvDestroyAllWindows();
} |
Partager