48 #include <sys/types.h> 50 #include <sys/ioctl.h> 89 video_capability capability;
90 video_channel queryChannel;
91 video_channel selectedChannel;
92 video_window captureWindow;
93 video_picture imageProperties;
101 printf (
"Could not open device %s - %s\n",
m_sDeviceName.c_str(), strerror(errno));
108 printf (
"could not obtain device capabilities\n");
112 if ((capability.type & VID_TYPE_CAPTURE) == 0)
114 printf (
"this device cannot capture video to memory\n");
120 while (i < capability.channels)
122 queryChannel.channel = i;
125 printf (
"%d. %s\n", queryChannel.channel, queryChannel.name);
131 selectedChannel.norm = VIDEO_MODE_NTSC;
135 printf (
"Could not set channel #%d\nNot a fatal error.", selectedChannel.channel);
147 default:
return false;
151 if ((capability.type & VID_TYPE_SCALES) != 0)
155 captureWindow.width =
width;
156 captureWindow.height =
height;
157 captureWindow.chromakey = 0;
158 captureWindow.flags = 0;
159 captureWindow.clips = 0;
160 captureWindow.clipcount = 0;
165 printf (
"Could not set desired dimensions\nNot a fatal error.\n");
172 printf (
"Could not obtain capture window dimensions.\n");
174 width = captureWindow.width;
175 height = captureWindow.height;
176 printf (
"Capturing dimensions are : %d, %d\n",
width,
height);
185 imageProperties.depth = 24;
186 imageProperties.palette = VIDEO_PALETTE_RGB24;
189 printf (
"Could not set the video depth and palette.\nPerhaps not a fatal error.\n");
196 printf (
"Failed to retrieve the video depth and palette.\n");
200 if ((imageProperties.depth != 24) || (imageProperties.palette != VIDEO_PALETTE_RGB24))
202 printf (
"Format is not 24bit RGB.\n");
206 printf (
"Capture depth is 24bit RGB\n");
211 printf (
"Failed to retrieve information about MMIO space.\n");
220 printf (
"Failed to obtain MMIO space.\n");
225 printf(
"Allocating structures...\n");
227 mmaps = (
struct video_mmap*)(malloc (
memoryBuffer.frames * sizeof (
struct video_mmap)));
234 mmaps[i].width = captureWindow.width;
235 mmaps[i].height = captureWindow.height;
236 mmaps[i].format = imageProperties.palette;
240 printf(
"Requesting capture buffers...\n");
251 printf(
"Set index buffer...\n");
280 const unsigned char *frame = (
const unsigned char *) (
memoryMap +
memoryBuffer.offsets[bufferIndex]);
281 unsigned char *output = ppImages[0]->
pixels;
283 const int nBytes = ppImages[0]->
width * ppImages[0]->
height * 3;
285 for (
int i = 0; i < nBytes; i += 3)
287 output[i] = frame[i + 2];
288 output[i + 1] = frame[i + 1];
289 output[i + 2] = frame[i];
int width
The width of the image in pixels.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
unsigned char * pixels
The pointer to the the pixels.
bool CaptureImage(CByteImage **ppImages)
CVideoCaptureInterface::VideoMode m_videoMode
int height
The height of the image in pixels.
GLenum GLsizei GLsizei height
std::string m_sDeviceName
CV4LCapture(const char *pDeviceName="/dev/video0", int nChannel=0, CVideoCaptureInterface::VideoMode videoMode=CVideoCaptureInterface::e640x480)