From aa0549fd18134f5d8fc4046ab32b46352ad379a3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 23 Nov 2014 15:12:20 +0100 Subject: pt: avoid crash on startup/close with opencv/highgui/libv4l --- ftnoir_tracker_pt/camera.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'ftnoir_tracker_pt/camera.cpp') diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index b0cb32c9..432e0158 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -144,16 +144,18 @@ bool Camera::get_frame(float dt, cv::Mat* frame) void CVCamera::start() { + if (cap) + delete cap; cap = new VideoCapture(desired_index); - // extract camera info + _set_res(); + _set_fps(); + // extract camera info if (cap->isOpened()) - { - _set_fps(); - _set_res(); - active = true; - active_index = desired_index; - cam_info.res_x = cap->get(CV_CAP_PROP_FRAME_WIDTH); - cam_info.res_y = cap->get(CV_CAP_PROP_FRAME_HEIGHT); + { + active = true; + active_index = desired_index; + cam_info.res_x = 0; + cam_info.res_y = 0; } else { delete cap; cap = nullptr; @@ -166,8 +168,9 @@ void CVCamera::stop() { cap->release(); delete cap; + cap = nullptr; } - active = false; + active = false; } bool CVCamera::_get_frame(Mat* frame) -- cgit v1.2.3