summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_PT/camera.cpp
diff options
context:
space:
mode:
authorPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-09-17 16:32:04 +0000
committerPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-09-17 16:32:04 +0000
commitcc3bc1c6d14de535f87e6601ed562b505d902fce (patch)
tree215fff88ae282a197b80b9db926430380c36c946 /FTNoIR_Tracker_PT/camera.cpp
parentf5df7884cf82b87fce50d3ff68c6a4bfa85064e9 (diff)
added pointtracker
created VC9 solution and project files for available projects git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@143 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FTNoIR_Tracker_PT/camera.cpp')
-rw-r--r--FTNoIR_Tracker_PT/camera.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/FTNoIR_Tracker_PT/camera.cpp b/FTNoIR_Tracker_PT/camera.cpp
new file mode 100644
index 00000000..a0bae694
--- /dev/null
+++ b/FTNoIR_Tracker_PT/camera.cpp
@@ -0,0 +1,62 @@
+#include "camera.h"
+
+using namespace cv;
+
+// ----------------------------------------------------------------------------
+Camera::Camera()
+ : dt_valid(0), dt_mean(0), cap(NULL)
+{}
+
+Camera::~Camera()
+{
+ if (cap) cvReleaseCapture(&cap);
+}
+
+void Camera::set_index(int index)
+{
+ if (cap) cvReleaseCapture(&cap);
+
+ cap = cvCreateCameraCapture(index);
+
+ // extract camera info
+ if (cap)
+ {
+ cam_info.res_x = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH);
+ cam_info.res_y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
+ }
+
+ // reset fps calculation
+ dt_mean = 0;
+}
+
+cv::Mat Camera::get_frame(float dt)
+{
+ cv::Mat frame;
+ if (cap && cvGrabFrame(cap) != 0)
+ {
+ // retrieve frame
+ IplImage* _img = cvRetrieveFrame(cap, 0);
+ if(_img)
+ {
+ if(_img->origin == IPL_ORIGIN_TL)
+ frame = Mat(_img);
+ else
+ {
+ Mat temp(_img);
+ flip(temp, frame, 0);
+ }
+ }
+ }
+
+ // measure fps of valid frames
+ const float dt_smoothing_const = 0.9;
+ dt_valid += dt;
+ if (!frame.empty())
+ {
+ dt_mean = dt_smoothing_const * dt_mean + (1.0 - dt_smoothing_const) * dt_valid;
+ cam_info.fps = 1.0 / dt_mean;
+ dt_valid = 0;
+ }
+
+ return frame;
+} \ No newline at end of file