Solved

WEB CAMERAS

Posted on 2000-05-11
11
5,257 Views
Last Modified: 2008-07-03
does anyone know how to operate web cameras from C code? Working Souce code would be excelent!

0
Comment
Question by:cmg05
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 1

Expert Comment

by:yz
ID: 2803227
Please check the part about Video Capture in MSDN, the functions and messages of capture window can help you control the preview and capture progress of camera.
For example:
capCreateCaptureWindow to create a capture window,
caoDriverConnect to connect to a camera device,
capPreviewRate and capPreviewScale to set the preview preference,
capPreview or capOverlay to begin prview,
capFileSetCaptureFile to set file name for capture.
capCaptureSequence to begin capture and store to a AVI file.

0
 
LVL 1

Expert Comment

by:yz
ID: 2803239
Are you working under Windows platform ad using VC?

http://msdn.microsoft.com/library/psdk/multimed/avicap_8xyd.htm
0
 

Author Comment

by:cmg05
ID: 2804050
Writing for a PC, on 98 using VC.

should I already have the avi class + h files the site talks off?

can I download them?

are there java equiv.?
0
 
LVL 1

Expert Comment

by:yz
ID: 2804561
Yes, these functions, actrually they are macros, are defined in vfw.h, and use vfw32.lib, these two files were already contained in VC or Platform SDK, so you can use it directly.

Why you talk about java? no idea.

If you need some example, I can show you, good luck.
0
 
LVL 3

Expert Comment

by:mitrakis
ID: 2805869
Maybe I misunderstood something...
Do you want to remotely control/operate a webcam or just grab live images from it ?

In case you're talking of a remote control, let me know.
In case you want to fiddel around with video/images/frames yz's suggestion using VFW is right.

Here's my example on a remote controlled pan/tilt camera:
http://bvlab12.fh-reutlingen.de

Best regards
-Stavi-
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cmg05
ID: 2807940
yz,  could you post some example code of using the vfw.h to capture an image? and save to a jpg?

Thanks
0
 
LVL 1

Accepted Solution

by:
yz earned 100 total points
ID: 2810147
You can use Video Capture Window to get the current frame, but it's bitmap, but can not compress it to jpeg.

The program below shows how to use Video Capture Window.

I think convert bitmap to jpeg is not hard, you may search it at codeguru, there should be an answer. sorry, I cannot help you any futher.

#include <windows.h>
#include <vfw.h>
#include "resource.h"

HINSTANCE ghInstance;
HWND ghMainWnd, ghCapWnd;
HMENU ghMainMenu;
BOOL fConnected = FALSE;

void ProcessCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
      {
      BOOL fResult;
      CAPDRIVERCAPS sCaps;

      switch (LOWORD(wParam))
            {
            // Connect to your camera, 0 means the first one,
            // if you have more than one device, change it to correct number.
            case IDM_CONNECT:
                  fResult = capDriverConnect(ghCapWnd, 0);
                  if (0 == fResult)
                        MessageBox(hwnd, "Cannot open video device", "Error", MB_OK);
                  else
                        {
                        fConnected = true;

                        capDriverGetCaps(ghCapWnd, &sCaps, sizeof(sCaps));

                        EnableMenuItem(ghMainMenu, IDM_CONNECT, MF_GRAYED);
                        EnableMenuItem(ghMainMenu, IDM_DISCONNECT, MF_ENABLED);
                        EnableMenuItem(ghMainMenu, IDM_PREVIEW, MF_ENABLED);
                        EnableMenuItem(ghMainMenu, IDM_GRAB, MF_ENABLED);
                        EnableMenuItem(ghMainMenu, IDM_CAPTURE, MF_ENABLED);
                        }
                  break;

            case IDM_DISCONNECT:
                  fResult = capDriverDisconnect(ghCapWnd);

                  EnableMenuItem(ghMainMenu, IDM_CONNECT, MF_ENABLED);
                  EnableMenuItem(ghMainMenu, IDM_DISCONNECT, MF_GRAYED);
                  EnableMenuItem(ghMainMenu, IDM_PREVIEW, MF_GRAYED);
                  EnableMenuItem(ghMainMenu, IDM_GRAB, MF_GRAYED);
                  EnableMenuItem(ghMainMenu, IDM_CAPTURE, MF_GRAYED);

                  fConnected = FALSE;
                  break;

            case IDM_VIDEOSOURCE:
                  fResult = capDlgVideoSource(ghCapWnd);
                  break;

            case IDM_VIDEOFORMAT:
                  fResult = capDlgVideoFormat(ghCapWnd);
                  break;

            case IDM_VIDEODISPLAY:
                  fResult = capDlgVideoDisplay(ghCapWnd);
                  break;

            case IDM_PREVIEW:
                  fResult = capPreviewRate(ghCapWnd, 33);
                  fResult = capPreviewScale(ghCapWnd, TRUE);
                  fResult = capPreview(ghCapWnd, TRUE);
                  break;

            // save current frame to c:\\temp\\test.bmp
            case IDM_GRAB:
                  capFileSaveDIB(ghCapWnd, "c\\test.bmp");
                  break;

            // If capture is in process, press mouse button or key will stop it by default
            case IDM_CAPTURE:
                  fResult = capFileSetCaptureFile(ghCapWnd, "c:\\temp\\test.avi");
                  fResult = capCaptureSequence(ghCapWnd);
                  break;

            case IDM_EXIT:
                  PostMessage(ghMainWnd, WM_CLOSE, 0, 0);
                  break;
            }
      
      return;
      }

LRESULT CALLBACK MainWndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
      {
      switch (iMsg)
            {
            case WM_CREATE:
                  break;

            case WM_COMMAND:
                  ProcessCommand(hwnd, wParam, lParam);
                  break;

            case WM_DESTROY:
                  if (fConnected)
                        {
                        capDriverDisconnect(ghCapWnd);
                        fConnected = FALSE;
                        }
                  PostQuitMessage(0);
                  break;

            default:
                  return DefWindowProc(hwnd, iMsg, wParam, lParam);
            }
      return 0;
      }

BOOL InitApplication (HINSTANCE hInstance)
      {
      WNDCLASSEX wc;
      BOOL fSuccess;

      ghInstance = hInstance;

      wc.cbSize        = sizeof (wc) ;
    wc.style         = 0;
    wc.lpfnWndProc   = MainWndProc ;
    wc.cbClsExtra    = 0 ;
    wc.cbWndExtra    = 0 ;
    wc.hInstance     = hInstance ;
    wc.hIcon           = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName = "TestCapture";
    wc.hIconSm       = LoadIcon (NULL, IDI_APPLICATION);

    fSuccess = RegisterClassEx (&wc);

      return fSuccess;
      }

BOOL InitInstance (HINSTANCE hInstance, int iCmdShow)
      {
      RECT rect;

      ghMainWnd = CreateWindowEx (0, "TestCapture", "Test Capture Application", WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE | WS_CAPTION,
                  CW_USEDEFAULT, CW_USEDEFAULT, 400, 350, NULL, NULL, hInstance, NULL);

      ghMainMenu = GetMenu(ghMainWnd);

      GetClientRect(ghMainWnd, &rect);

      ghCapWnd = capCreateCaptureWindow("Test Capture Window", WS_CHILD | WS_VISIBLE, rect.left + 5, rect.top + 5, rect.right - 10, rect.bottom - 10, ghMainWnd, 1);

    ShowWindow (ghMainWnd, iCmdShow);
    UpdateWindow (ghMainWnd);

      return true;
      }

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
      {
      MSG msg;

      if (!InitApplication(hInstance) || !InitInstance(hInstance, iCmdShow))
            return false;

      while(GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg) ;
        DispatchMessage (&msg) ;
        }

      return 1;
      }
0
 
LVL 3

Expert Comment

by:mitrakis
ID: 2811227
If it's useful to have complete source code regarding capturing, grabbing and usage of VfW in general I'd suggest to visit the following site:

http://i.am/shrinkwrapvb

Although it's VB code I'm sure it can help you solve the problem...somehow.
Not to forget that there's an OCX available to include it into C++ projects.

Best regards
-Stavi-
0
 

Author Comment

by:cmg05
ID: 2815203
Awsum!

Thanks man!

You got me out of a Jam.
0
 
LVL 3

Expert Comment

by:mitrakis
ID: 2829264
Hi cmg05,

did you solve the JPG saving ?
I would greatly appreciate it if you drop me a note on this.

I would be thankful forever, if you even send me your working project...

mailto: s.mitrakis@caa.de

Best regards
-Stavi-
0
 

Expert Comment

by:anu_g_shakthi
ID: 13761544
Hi,
I have a Sony Handycam (DCR-TRV340E); I would like to know how to control/operate this camera through remote. Basically I want to do this through RF. Kindly suggest.

Regards
Ganesh
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now