15 #include "webcamVideoOpenCV.h"
19 #include "pStatTimer.h"
21 TypeHandle WebcamVideoCursorOpenCV::_type_handle;
28 WebcamVideoCursorOpenCV::
30 _size_x = src->_size_x;
31 _size_y = src->_size_y;
35 _can_seek_fast =
false;
40 _capture = cvCaptureFromCAM(src->_camera_index);
41 if (_capture != NULL) {
42 _size_x = (int)cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
43 _size_y = (int)cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
53 WebcamVideoCursorOpenCV::
54 ~WebcamVideoCursorOpenCV() {
55 if (_capture != NULL) {
56 cvReleaseCapture(&_capture);
72 PT(
Buffer) buffer = get_standard_buffer();
73 unsigned char *dest = buffer->_block;
74 int num_components = get_num_components();
75 nassertr(num_components == 3, NULL);
76 int dest_x_pitch = num_components;
77 int dest_y_pitch = _size_x * dest_x_pitch;
79 const
unsigned char *r, *g, *b;
81 if (get_frame_data(r, g, b, x_pitch, y_pitch)) {
82 if (num_components == 3 && x_pitch == 3) {
84 int copy_bytes = _size_x * dest_x_pitch;
85 nassertr(copy_bytes <= dest_y_pitch && copy_bytes <= abs(y_pitch), NULL);
87 for (
int y = 0; y < _size_y; ++y) {
88 memcpy(dest, r, copy_bytes);
97 for (
int y = 0; y < _size_y; ++y) {
100 for (
int x = 0; x < _size_x; ++x) {
102 dest[dx + 1] = g[sx];
103 dest[dx + 2] = b[sx];
107 dest += dest_y_pitch;
139 bool WebcamVideoCursorOpenCV::
140 get_frame_data(
const unsigned char *&r,
141 const unsigned char *&g,
142 const unsigned char *&b,
143 int &x_pitch,
int &y_pitch) {
144 nassertr(ready(),
false);
146 IplImage *image = cvQueryFrame(_capture);
151 r = (
const unsigned char *)image->imageData;
155 y_pitch = image->widthStep;
157 if (image->dataOrder == 1) {
161 g = r + image->height * y_pitch;
162 b = g + image->height * y_pitch;
165 if (image->origin == 0) {
170 r += (image->height - 1) * y_pitch;
171 g += (image->height - 1) * y_pitch;
172 b += (image->height - 1) * y_pitch;
A MovieVideo is actually any source that provides a sequence of video frames.
TypeHandle is the identifier used to differentiate C++ class types.