Jump to content
zorro59

Get webcam images c++

Recommended Posts

void main()
{
camhwnd = capCreateCaptureWindow ("camera window", WS_CHILD , 0,0, 320, 240, GetDesktopWindow(), 0);

SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
cout<<GetLastError()<<endl;//returns 995
//SendMessage(camhwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);
ShowWindow(camhwnd,SW_SHOW);

SendMessage(camhwnd, WM_CAP_DRIVER_CONNECT,0,0);
SendMessage(camhwnd, WM_CAP_SET_SCALE, true , 0);
SendMessage(camhwnd, WM_CAP_SET_PREVIEWRATE, 10, 0);
SendMessage(camhwnd, WM_CAP_SET_PREVIEW, true , 0);

cout<<GetLastError();
for (int i=0; i<10; i++)
{
capFileSaveDIB(camhwnd, "file.bmp");
ConvertImage(L"file.bmp", L"file.jpeg", L"image/jpeg", 70);
system("PAUSE");
}
}

Codul functioneaza daca este rulat dintr-o aplicatie win32, dar cand incerc sa rulez din consola primesc error code 995 (nu se creaza fereastra). Stie cineva cum sa trec de asta/alta metoda?

Edited by zorro59
Link to comment
Share on other sites

Prima chestie.

Include si headerele.

A 2-a, foloseste int main si return 0 la final, e mai bine asa.

A 3-a, in mod normal trebuie sa aloci un handle pentru fereastra. Nu mai tin minte exact, aveam pe undeva un cod pentru asta.

Le: Incearca sa incluzi windows.h si sa adaugi AllocConsole(); inainte de primele comenzi.

Poti sa incerci sa te inspiri din codul postat aici de catre parazitul29. Si el face cam acelasi lucru. Creeaza o aplicatie consola care totusi acceseaza ferestre.

Edited by nedo
Link to comment
Share on other sites

Linkul nu merge. In legatura cu headers, nu le-am inclus pentru ca este o parte dintr-un proiect mai amplu.

LE: nici cu "run as administrator" nu merge.

LE2: am gasit codul de care spui tu, dar nu are legatura cu ceea ce vreau eu. El trebuie sa trimita un mesaj unei ferestre care exista deja, eu am nevoie sa o creez.

Edited by zorro59
Link to comment
Share on other sites


#include <iostream>
#include <windows.h>

long __stdcall WindowProcedure( HWND window, unsigned int msg, WPARAM wp, LPARAM lp )
{
switch(msg)
{
case WM_DESTROY:
std::cout << "\ndestroying window\n" ;
PostQuitMessage(0) ;
return 0L ;
case WM_LBUTTONDOWN:
std::cout << "\nmouse left button down at (" << LOWORD(lp)
<< ',' << HIWORD(lp) << ")\n" ;
// fall thru
default:
std::cout << '.' ;
return DefWindowProc( window, msg, wp, lp ) ;
}
}

int main()
{
std::cout << "hello world!\n" ;
const char* const myclass = "myclass" ;
WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, WindowProcedure,
0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION),
LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW+1),
0, myclass, LoadIcon(0,IDI_APPLICATION) } ;
if( RegisterClassEx(&wndclass) )
{
HWND window = CreateWindowEx( 0, myclass, "title",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0 ) ;
if(window)
{
ShowWindow( window, SW_SHOWDEFAULT ) ;
MSG msg ;
while( GetMessage( &msg, 0, 0, 0 ) ) DispatchMessage(&msg) ;
}
}
}

  • Upvote 1
  • Downvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...