diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-22 01:52:44 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-22 01:52:44 +0200 |
commit | f50036627c4175ad307552fa40a78042934139f2 (patch) | |
tree | 833157ac98c24a363e099eede7b2b04e9945fb37 /FTNoIR_Tracker_PT/camera.cpp | |
parent | 245f909db8ab5549ae2e08e39178a4c7463419ef (diff) |
fix camera name & crash bug
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
Diffstat (limited to 'FTNoIR_Tracker_PT/camera.cpp')
-rw-r--r-- | FTNoIR_Tracker_PT/camera.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/FTNoIR_Tracker_PT/camera.cpp b/FTNoIR_Tracker_PT/camera.cpp index 14f7a6be..0ef617c3 100644 --- a/FTNoIR_Tracker_PT/camera.cpp +++ b/FTNoIR_Tracker_PT/camera.cpp @@ -6,6 +6,7 @@ */
#include "camera.h"
+#include <string>
#include <QDebug>
using namespace cv;
@@ -48,7 +49,9 @@ void get_camera_device_names(std::vector<std::string>& device_names) { hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
- device_names.push_back(std::string(reinterpret_cast<char const*>(varName.bstrVal)));
+ auto wstr = std::wstring(varName.bstrVal);
+ auto str = std::string(wstr.begin(), wstr.end());
+ device_names.push_back(str);
}
VariantClear(&varName);
@@ -71,8 +74,6 @@ void get_camera_device_names(std::vector<std::string>& device_names) { sprintf(buf, "/dev/video%d", i);
if (access(buf, R_OK | W_OK) == 0) {
device_names.push_back(std::string(buf));
- } else {
- continue;
}
}
# endif
@@ -162,10 +163,6 @@ void CVCamera::start() cam_info.res_x = cap->get(CV_CAP_PROP_FRAME_WIDTH);
cam_info.res_y = cap->get(CV_CAP_PROP_FRAME_HEIGHT);
}
- else {
- delete cap;
- cap = NULL;
- }
}
void CVCamera::stop()
@@ -180,7 +177,7 @@ void CVCamera::stop() bool CVCamera::_get_frame(Mat* frame)
{
- if (cap)
+ if (cap && cap->isOpened())
{
Mat img;
/*
@@ -188,9 +185,12 @@ bool CVCamera::_get_frame(Mat* frame) * frames and then some every once in a while
* -sh
*/
- while (!cap->read(img))\
+ while (!cap->read(img))
;;
+ if (img.empty())
+ return false;
+
*frame = img;
return true;
}
|