-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamara.cpp
80 lines (64 loc) · 1.43 KB
/
Camara.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Modulo: Vision artificial
*
* Descripcion: Implementacion de la clase Camara para capturar imagenes
*
* Autor: Alvaro Salmador
*
* (C) Alvaro Salmador 2007-2008. All rights reserved.
*
* $Id: Camara.cpp 404 2008-04-06 14:47:51Z Alvaro $
*/
#include "stdafx.h"
#include "Camara.h"
Camara::Camara(int index/*=CV_CAP_ANY*/)
{
IplImage* frame;
//_capture = cvCaptureFromCAM(index); //CV_CAP_ANY es 0
do
{
_capture = cvCaptureFromCAM(index++);
if (_capture)
frame = cvQueryFrame(_capture);
else
frame = NULL;
}
while(frame==NULL && index<8);
//cvReleaseImage(&frame); no hay q hacerlo sobre las de webcam
/*if (_capture)
{ no funciona
cvQueryFrame(_capture);
cvSetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
}*/
}
Camara::~Camara(void)
{
cvReleaseCapture(&_capture);
}
IplImage* Camara::queryFrame(bool bSelect)
{
if (!_capture)
return NULL;
if (bSelect)
cvNamedWindow( "Camara", CV_WINDOW_AUTOSIZE );
int wk;
IplImage* frame = NULL;
do
{
// Get one frame
frame = cvQueryFrame(_capture);
if (!frame)
{
if (bSelect)
cvDestroyWindow( "Camara" );
fprintf( stderr, "ERROR: frame is null...\n" );
return NULL;
}
if (bSelect)
cvShowImage( "Camara", frame );
wk = (cvWaitKey(10) & 255);
} while (bSelect && wk!=13 && wk!=' '); // escape seria 27
cvDestroyWindow("Camara");
return frame;
}