summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_PT/camera.cpp
diff options
context:
space:
mode:
authorPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-09-29 13:18:52 +0000
committerPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-09-29 13:18:52 +0000
commit2836141124cf065387bbc7e59ddcfa238ea0a26f (patch)
tree011851f51eb22971a411de8d888f3ba7ce397764 /FTNoIR_Tracker_PT/camera.cpp
parent71736d2d3bf639096c3c1b51565fd4c45239e44a (diff)
Updated vc9 project files.
PT: Undo of Wim's last wrong commit, some code cleanup, added preliminary resolution change support. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@184 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FTNoIR_Tracker_PT/camera.cpp')
-rw-r--r--FTNoIR_Tracker_PT/camera.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/FTNoIR_Tracker_PT/camera.cpp b/FTNoIR_Tracker_PT/camera.cpp
index c1d0149c..1a233cef 100644
--- a/FTNoIR_Tracker_PT/camera.cpp
+++ b/FTNoIR_Tracker_PT/camera.cpp
@@ -4,7 +4,7 @@ using namespace cv;
// ----------------------------------------------------------------------------
Camera::Camera()
- : dt_valid(0), dt_mean(0), cap(NULL)
+ : dt_valid(0), dt_mean(0), cap(NULL), active_index(-1)
{}
Camera::~Camera()
@@ -14,6 +14,7 @@ Camera::~Camera()
void Camera::set_index(int index)
{
+ if (index == active_index) return;
if (cap) cvReleaseCapture(&cap);
cap = cvCreateCameraCapture(index);
@@ -25,8 +26,27 @@ void Camera::set_index(int index)
cam_info.res_y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
}
- // reset fps calculation
- dt_mean = 0;
+ active_index = index;
+ dt_mean = 0; // reset fps calculation
+}
+
+bool Camera::set_fps(int fps)
+{
+ return cap && cvSetCaptureProperty(cap, CV_CAP_PROP_FPS, fps);
+}
+
+bool Camera::set_res(int x_res, int y_res)
+{
+ if (cap)
+ {
+ if (x_res == cam_info.res_x && y_res == cam_info.res_y) return true;
+ cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH, x_res);
+ cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, y_res);
+ cam_info.res_x = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH);
+ cam_info.res_y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
+ if (x_res == cam_info.res_x && y_res == cam_info.res_y) return true;
+ }
+ return false;
}
cv::Mat Camera::get_frame(float dt)
@@ -54,7 +74,7 @@ cv::Mat Camera::get_frame(float 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 + 1e-6);
+ cam_info.fps = 1.0 / dt_mean;
dt_valid = 0;
}