Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WEB CAMERAS

Posted on 2000-05-11
11
Medium Priority
?
5,333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 

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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

610 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