VidCapDll.cpp File Reference
Detailed Description
C-style DLL wrapper for VidCapture library.
- RCSfile
- VidCapDll.cpp,v
- Date
- 2004/03/01 18:31:06
- Revision
- 1.4
- Author
- mikeellison
Definition in file VidCapDll.cpp.
#include <windows.h>
#include "VidCapDll.h"
#include "CVResDll.h"
#include "CVUtil.h"
#include "VidCapture.h"
Go to the source code of this file. Compounds
Functions
- CVRES CVImgStructFromImage (CVIMAGESTRUCT **imageStructPtrPtr, CVImage *image)
- BOOL WINAPI DllMain (HINSTANCE hInst, DWORD dwReason, LPVOID lpvReserved)
- CVRES VIDCAPFUNC CVAcquireVidCap (CVVIDCAPSYSTEM *capSystem)
- CVRES VIDCAPFUNC CVReleaseVidCap (CVVIDCAPSYSTEM capSystem)
- int VIDCAPFUNC CVGetNumDevices (CVVIDCAPSYSTEM capSystem)
- bool FindDeviceCB (const char *devname, void *userParam)
- CVRES VIDCAPFUNC CVGetDeviceName (CVVIDCAPSYSTEM capSystem, int deviceNum, char *devNameBuffer, int *nameBufLen)
- CVRES VIDCAPFUNC CVDevConnect (CVVIDCAPSYSTEM capSystem, int devIndex)
- CVRES VIDCAPFUNC CVDevDisconnect (CVVIDCAPSYSTEM capSystem)
- int VIDCAPFUNC CVDevGetNumModes (CVVIDCAPSYSTEM capSystem)
- CVRES VIDCAPFUNC CVDevGetModeInfo (CVVIDCAPSYSTEM capSystem, int modeIndex, int *xRes, int *yRes, int *frameRate, int *vidFormat)
- CVRES VIDCAPFUNC CVDevGetFormatName (CVVIDCAPSYSTEM capSystem, int vidFormat, char *vidFormatNameBuf, int *vidFormatBufLen)
- CVRES VIDCAPFUNC CVDevGrabImage (CVVIDCAPSYSTEM capSystem, int modeIndex, CVIMAGETYPE imageType, CVIMAGESTRUCT **imageStructPtrPtr)
- bool DllCaptureCb (CVRES status, CVImage *capturedImage, void *userParam)
- CVRES VIDCAPFUNC CVDevStartCap (CVVIDCAPSYSTEM capSystem, int modeIndex, CVIMAGETYPE imageType, CVVIDCAPDLLCB callback, void *cbUserParam, CVCAPHANDLE *capHandlePtr)
- CVRES VIDCAPFUNC CVDevStopCap (CVVIDCAPSYSTEM capSystem, CVCAPHANDLE capHandle)
- CVRES VIDCAPFUNC CVLoadImage (const char *filename, CVIMAGESTRUCT **imageStructPtrPtr)
- CVRES VIDCAPFUNC CVSaveImage (const char *filename, CVIMAGESTRUCT *imageStructPtr, BOOL overwrite)
- void VIDCAPFUNC CVReleaseImage (CVIMAGESTRUCT *imageStructPtr)
- void VIDCAPFUNC CVGetVidCapString (char *buffer, int *bufLength)
- CVRES VIDCAPFUNC CVDevGetProperty (CVVIDCAPSYSTEM capSystem, CVCAMERAPROP property, long *curValue, long *defValue, long *minValue, long *maxValue, long *step)
- CVRES VIDCAPFUNC CVDevSetProperty (CVVIDCAPSYSTEM capSystem, CVCAMERAPROP property, long newValue)
Function Documentation
|
|
CVAcquireVidCap() acquires a video capture object and initializes it. You must call CVReleaseVidCap() when done with the handle returned on a successful call.
- Parameters:
-
| capSystem | - ref to handle. Contains new handle on success. |
- Returns:
- CVRES - CVRES_SUCCESS on successful initialization.
- See also:
- CVReleaseVidCap()
Successful - save handle and return
Didn't initialize properly - uninitialize and return error.
Definition at line 96 of file VidCapDll.cpp.
References CVPlatform::AcquireVideoCapture(), CVRES, CVRES_DLL_VIDCAP_CREATE_ERROR, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVSUCCESS, CVVIDCAPSYSTEM, CVPlatform::GetPlatform(), CVVidCapture::Init(), CVPlatform::Release(), and VIDCAPFUNC.
Referenced by main(). |
| CVRES VIDCAPFUNC CVDevGetFormatName |
( |
CVVIDCAPSYSTEM |
capSystem, |
|
|
int |
vidFormat, |
|
|
char * |
vidFormatNameBuf, |
|
|
int * |
vidFormatBufLen |
|
) |
|
|
| CVRES VIDCAPFUNC CVDevGetModeInfo |
( |
CVVIDCAPSYSTEM |
capSystem, |
|
|
int |
modeIndex, |
|
|
int * |
xRes, |
|
|
int * |
yRes, |
|
|
int * |
frameRate, |
|
|
int * |
vidFormat |
|
) |
|
|
|
|
CVDevGetModeInfo() retrieve information about the specified mode.
- Parameters:
-
| capSystem | - handle from CVAcquireVidCap() |
| modeIndex | - index of mode to use for capture |
| xRes | - ptr to receive x resolution of the camera mode |
| yRes | - ptr to receive y resolution of the camera mode |
| frameRate | - ptr to receive estimated framerate (may be null) |
| vidFormat | - ptr to receive input video mode value (VIDCAP_FORMAT) may be null. |
- Returns:
- CVRES - CVRES_SUCCESS on success
- See also:
- CVDevGetNumModes(), CVDevConnect(),
Definition at line 363 of file VidCapDll.cpp.
References CVAssert, CVFAILED, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::VIDCAP_MODE::EstFrameRate, CVVidCapture::GetModeInfo(), CVVidCapture::VIDCAP_MODE::InputFormat, VIDCAPFUNC, CVVidCapture::VIDCAP_MODE::XRes, and CVVidCapture::VIDCAP_MODE::YRes.
Referenced by main(). |
| CVRES VIDCAPFUNC CVDevGetProperty |
( |
CVVIDCAPSYSTEM |
capSystem, |
|
|
CVCAMERAPROP |
property, |
|
|
long * |
curValue, |
|
|
long * |
defValue, |
|
|
long * |
minValue, |
|
|
long * |
maxValue, |
|
|
long * |
step |
|
) |
|
|
|
|
CVDevGetProperty() retrieves the current, minimum, and maximum values for the specified property.
If the property is not supported by the camera, then it will return CVRES_DLL_VIDCAP_UNSUPPORTED_PROPERTY.
- Parameters:
-
| capSystem | - handle to *connected* capture system. |
| property | - property identifier |
| curValue | - ptr to receive current value of property. |
| defValue | - ptr to receive default value of property. |
| minValue | - ptr to receive minimum value of property. |
| maxValue | - ptr to receive maximum value of property. |
| step | - ptr to receive the minimum step distance between values. |
- See also:
- CVDevSetProperty()
This is a bit fugly, but I want to allow the class values to change while the DLL Values can't. Also, some properties probably shouldn't be messed with by the DLL (e.g. COLOR).
And, we've got the added bonus that bad values can be detected here...
Definition at line 882 of file VidCapDll.cpp.
References CVVidCapture::CAMERA_PROPERTY, CVVidCapture::CAMERAPROP_BRIGHT, CVVidCapture::CAMERAPROP_CONTRAST, CVVidCapture::CAMERAPROP_GAIN, CVVidCapture::CAMERAPROP_GAMMA, CVVidCapture::CAMERAPROP_HUE, CVVidCapture::CAMERAPROP_SAT, CVVidCapture::CAMERAPROP_SHARP, CVVidCapture::CAMERAPROP_WHITEBALANCE, CVAssert, CVCAM_BRIGHT, CVCAM_CONTRAST, CVCAM_GAIN, CVCAM_GAMMA, CVCAM_HUE, CVCAM_SAT, CVCAM_SHARP, CVCAM_WHITEBALANCE, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVVidCapture::GetPropertyInfo(), and VIDCAPFUNC.
Referenced by main(). |
|
|
CVDevGrabImage() grabs a single image from a selected and connected camera.
You must free the returned pointer when done by calling CVReleaseImage() on it or you will leak massive amounts of memory.
- Parameters:
-
| capSystem | - handle from CVAcquireVidCap() |
| modeIndex | - index of mode to use for capture |
| imageType | - requested type of image |
| imageStructPtrPtr | - ptr to receive a ptr to created image struct. Call CVReleaseImage() on the returned image struct ptr when done. |
- Returns:
- CVRES - CVRES_SUCCESS on success
- See also:
- CVDevGetModeInfo()
Select mode for grab
Perform the grab
Check validity of image struct**, then set it to null in case something fails.
Definition at line 471 of file VidCapDll.cpp.
References CVAssert, CVFAILED, CVImage::CVIMAGE_TYPE, CVImgStructFromImage(), CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::Grab(), CVImage::ReleaseImage(), CVVidCapture::SetMode(), and VIDCAPFUNC. |
|
|
CVDevSetProperty() sets the specified property value for the camera.
If the property is not supported by the camera, then it will return CVRES_DLL_VIDCAP_UNSUPPORTED_PROPERTY.
- Parameters:
-
| capSystem | - handle to *connected* capture system. |
| property | - property identifier |
| newValue | - new value for the property. Should be within range given by CVGetProperty() |
- See also:
- CVDevGetProperty()
This is a bit fugly, but I want to allow the class values to change while the DLL Values can't. Also, some properties probably shouldn't be messed with by the DLL (e.g. COLOR).
And, we've got the added bonus that bad values can be detected here...
Definition at line 966 of file VidCapDll.cpp.
References CVVidCapture::CAMERA_PROPERTY, CVVidCapture::CAMERAPROP_BRIGHT, CVVidCapture::CAMERAPROP_CONTRAST, CVVidCapture::CAMERAPROP_GAIN, CVVidCapture::CAMERAPROP_GAMMA, CVVidCapture::CAMERAPROP_HUE, CVVidCapture::CAMERAPROP_SAT, CVVidCapture::CAMERAPROP_SHARP, CVVidCapture::CAMERAPROP_WHITEBALANCE, CVAssert, CVCAM_BRIGHT, CVCAM_CONTRAST, CVCAM_GAIN, CVCAM_GAMMA, CVCAM_HUE, CVCAM_SAT, CVCAM_SHARP, CVCAM_WHITEBALANCE, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVVidCapture::SetProperty(), and VIDCAPFUNC.
Referenced by main(). |
|
|
CVDevStartCap() starts a continuous capture, sending each image to the specified callback.
The CVIMAGESTRUCT* passed to the callback is *only* valid during the callback! You must copy the data out if you'll need it later. However, you should NOT call CVReleaseImage() on it - the DLL will do that for you when your callback function returns.
- Parameters:
-
| capSystem | - handle from CVAcquireVidCap() |
| modeIndex | - index of mode to use for capture |
| imageType | - type of image to capture |
| callback | - callback to receive images during capture |
| cbUserParam | - user parameter to send to callback |
| capHandlePtr | - ptr to receive capture handle. |
- Returns:
- CVRES - CVRES_SUCCESS on success
Create a capture structure for our callback
If we didn't start successfully, clean up the capture struct
Definition at line 594 of file VidCapDll.cpp.
References CVAssert, CVCAPHANDLE, CVFAILED, CVImage::CVIMAGE_TYPE, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, DllCaptureCb(), DLLCAPTURESTRUCT::HostCallback, DLLCAPTURESTRUCT::HostUserParam, CVVidCapture::StartImageCap(), and VIDCAPFUNC.
Referenced by main(). |
| CVRES VIDCAPFUNC CVGetDeviceName |
( |
CVVIDCAPSYSTEM |
capSystem, |
|
|
int |
deviceNum, |
|
|
char * |
devNameBuffer, |
|
|
int * |
nameBufLen |
|
) |
|
|
|
|
CVGetDeviceName() retrieves the name of a capture device into the provided buffer.
- Parameters:
-
| capSystem | - handle from CVAcquireVidCap() |
| deviceNum | - index of device (0 -> CVGetNumDevices() - 1) |
| devNameBuffer | - buffer to receive ASCIIZ device name. must be allocated by caller! |
| nameBufLen | - ptr to Maximum length of devNameBuffer. set to length of device name on return. |
- Returns:
- CVRES - CVRES_SUCCESS on success.
- See also:
- CVGetNumDevices(), CVDevConnect()
Definition at line 230 of file VidCapDll.cpp.
References CVAssert, CVFAILED, CVRES, CVRES_DLL_VIDCAP_DEV_NOT_FOUND, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::VIDCAP_DEVICE::DeviceString, CVVidCapture::GetDeviceInfo(), and VIDCAPFUNC.
Referenced by main(). |
| void VIDCAPFUNC CVGetVidCapString |
( |
char * |
buffer, |
|
|
int * |
bufLength |
|
) |
|
|
|
|
Internal function to create an image structure from an image class.
CVImgStructFromImage() is an internal function to convert from a CVImage* to a CVIMAGESTRUCT*.
You must call CVReleaseImage() on the created CVIMAGESTRUCT* when done.
- Parameters:
-
| imageStructPtrPtr | - ptr to receive a ptr to created image struct. Call CVReleaseImage() on the returned image struct ptr when done. |
| image | - image class object to convert |
- Returns:
- CVRES - CVRES_SUCCESS on success
Bail if we couldn't allocate pixel data
Copy image
Definition at line 821 of file VidCapDll.cpp.
References CVIMAGESTRUCT::BytesPerPixel, CVIMAGETYPE, CVRES, CVRES_INVALID_PARAMETER, CVRES_OUT_OF_MEMORY, CVRES_SUCCESS, CVImage::GetBytesPerPixel(), CVImage::GetImageType(), CVImage::GetNumChannels(), CVImage::GetRawDataPtr(), CVImage::Height(), CVIMAGESTRUCT::ImageDataSize, CVIMAGESTRUCT::ImageHeight, CVIMAGESTRUCT::ImageType, CVIMAGESTRUCT::ImageWidth, kCVIMAGESTRUCTVER, CVIMAGESTRUCT::NumChannels, CVIMAGESTRUCT::PixelDataPtr, CVIMAGESTRUCT::Version, and CVImage::Width().
Referenced by CVDevGrabImage(), and CVLoadImage(). |
| CVRES VIDCAPFUNC CVLoadImage |
( |
const char * |
filename, |
|
|
CVIMAGESTRUCT ** |
imageStructPtrPtr |
|
) |
|
|
| void VIDCAPFUNC CVReleaseImage |
( |
CVIMAGESTRUCT * |
imageStructPtr |
) |
|
|
| CVRES VIDCAPFUNC CVSaveImage |
( |
const char * |
filename, |
|
|
CVIMAGESTRUCT * |
imageStructPtr, |
|
|
BOOL |
overwrite |
|
) |
|
|
|
|
CVSaveImage() saves an image from a CVIMAGESTRUCT* to disk.
- Parameters:
-
| filename | - pointer to ASCIIZ filename of .ppm/.pgm file. |
| imageStructPtr | - ptr to image struct |
| overwrite | - TRUE to overwrite existing files, FALSE otherwise. |
- See also:
- CVLoadImage()
Check image data size in struct
Invalid image size...
Create a CVImage to contain the passed in image for saving...
Double check bytes per pixel before performing copy
Copy data into CVImage
Save it, free up the CVImage, and exit
Definition at line 718 of file VidCapDll.cpp.
References CVIMAGESTRUCT::BytesPerPixel, CVImage::CreateImage(), CVFAILED, CVImage::CVIMAGE_TYPE, CVRES, CVRES_DLL_VIDCAP_INVALID_IMAGE_STRUCT, CVRES_INVALID_PARAMETER, CVImage::GetBytesPerPixel(), CVImage::GetRawDataPtr(), CVIMAGESTRUCT::ImageDataSize, CVIMAGESTRUCT::ImageHeight, CVIMAGESTRUCT::ImageType, CVIMAGESTRUCT::ImageWidth, CVIMAGESTRUCT::PixelDataPtr, CVImage::ReleaseImage(), CVImage::Save(), and VIDCAPFUNC. |
| bool DllCaptureCb |
( |
CVRES |
status, |
|
|
CVImage * |
capturedImage, |
|
|
void * |
userParam |
|
) |
|
|
|
|
DllCaptureCb() is a passthrough for the capture callback from CVVidCapture() to the host program.
It converts the CVImage* to a CVIMAGESTRUCT*, then calls the host.
If we have an image, convert it to an image struct
No image to pass - just call callback and return result.
Unlike the image grabs, we don't waste time copying the memory out. Just fill in the struct, then point to the CVImage's pixel data.
Definition at line 535 of file VidCapDll.cpp.
References CVIMAGESTRUCT::BytesPerPixel, CVIMAGETYPE, CVSUCCESS, CVImage::GetBytesPerPixel(), CVImage::GetImageType(), CVImage::GetNumChannels(), CVImage::GetRawDataPtr(), CVImage::Height(), DLLCAPTURESTRUCT::HostCallback, DLLCAPTURESTRUCT::HostUserParam, CVIMAGESTRUCT::ImageDataSize, CVIMAGESTRUCT::ImageHeight, CVIMAGESTRUCT::ImageType, CVIMAGESTRUCT::ImageWidth, kCVIMAGESTRUCTVER, CVIMAGESTRUCT::NumChannels, CVIMAGESTRUCT::PixelDataPtr, CVIMAGESTRUCT::Version, and CVImage::Width().
Referenced by CVDevStartCap(). |
| BOOL WINAPI DllMain |
( |
HINSTANCE |
hInst, |
|
|
DWORD |
dwReason, |
|
|
LPVOID |
lpvReserved |
|
) |
|
|
|
|
DLLMain() - DLL entry point... Do we need to set aside thread storage? Hopefully not for now. To make things work between threads/apps we just create an entirely new CVVidCapture instance for each caller and then use that as a handle.
Process starting....
Process exiting...
Definition at line 64 of file VidCapDll.cpp.
References kVIDCAPTURE_STRING. |
| bool FindDeviceCB |
( |
const char * |
devname, |
|
|
void * |
userParam |
|
) |
|
|
|
|
FindDeviceCB is a callback for CVVidCapture::EnumDevices. It counts devices until it finds the requested one, then saves the device name.
This method isn't particularly efficient - later we should store a list but refresh it periodically or on the appropriate WM_DEVICECHANGE message.
Definition at line 199 of file VidCapDll.cpp.
References CVFINDDEVINFO::CurDev, CVFINDDEVINFO::DevName, and CVFINDDEVINFO::ReqDev. |
|