Project

General

Profile

BitmapToolkit Scol plugin
ArDetector.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25#include "ArManager.h"
26#include "ArDetector.h"
27
28#include <vector>
29
30//aruco::DFCMarkerTracker()
31ArDetector::ArDetector() : aruco::MarkerDetector(), btopenutils::Thread()
32{
33 needUpdate = false;
34 mSlowUpdateDetected = false;
35
36 aruco::MarkerDetector::Params params;
37 params.setDetectionMode(aruco::DM_NORMAL, 0.05f);
38 //params.setAutoSizeSpeedUp(true);
39 params.setCornerRefinementMethod(aruco::CORNER_LINES);
40 params.detectEnclosedMarkers(false);
41 //params.trackingMinDetections = 3;
42
43 /*
44 //DFC tracker
45 aruco::MarkerDetector &detector = getDetector();
46 detector.setParameters(params);
47 detector.setDictionary(aruco::Dictionary::ARUCO, 0.2f);
48 */
49
50 //Classic detector
51 setParameters(params);
52 setDictionary(aruco::Dictionary::ARUCO, 0.2f);
53
54 // Run thread
55 StartThreading(boost::bind(&ArDetector::GoThread, this));
56}
57
62
64{
65 while (IsRunning())
66 {
67 if (needUpdate)
68 {
70 manager->GetLastData(mLastData);
71 needUpdate = false;
72
73 //cv::undistort(mLastData.gray, mLastData.gray, mLastData.camParam.CameraMatrix, mLastData.camParam.Distorsion);
74
75 /*float scale = 1.0f;
76
77 int maxsize = std::max(mLastData.camParam.CamSize.width, mLastData.camParam.CamSize.height);
78 if (maxsize > 640)
79 scale = 640.0f / (float)maxsize;
80
81 cv::Size nsize;
82 nsize.width = (int)((float)mLastData.gray.cols * scale);
83 nsize.height = (int)((float)mLastData.gray.rows * scale);
84
85 mLastData.camParam.resize(nsize);
86
87 if (scale != 1.0f)
88 cv::resize(mLastData.gray, mLastData.gray, mLastData.camParam.CamSize, 0, 0, cv::INTER_LINEAR);
89 */
90
91 // List of dectected markers
92 std::vector<aruco::Marker> detectedMarkers;
93
94 //simple aruco detection
95 try
96 {
97 /*
98 //DFC tracker
99 setParams(mLastData.arCamParam.camParam, -1);
100 estimatePose();
101 std::map<int, cv::Ptr<TrackerImpl>> trackers = track(mLastData.gray);
102
103 detectedMarkers.clear();
104 for (auto m : trackers)
105 {
106 detectedMarkers.push_back(m.second->getMarker());
107 }
108 */
109
110 //Classic detector
111 detectedMarkers = detect(mLastData.gray, mLastData.arCamParam.camParam, -1);
112 }
113 catch (cv::Exception &e)
114 {
115 MMechostr(MSKDEBUG, "ArDetector::GoThread() : detect > %s", e.what());
116 }
117 manager->updateFiducialMarkers(detectedMarkers, mLastData);
118 }
119 else
120 {
121 //prevent cpu burn
122 boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); //DO not burn too much CPU
123 }
124 }
125}
aruco::CameraParameters camParam
void GoThread()
bool needUpdate
Definition ArDetector.h:50
void GetLastData(LASTDATA &data)
static ArManager * GetInstance()
Definition ArManager.cpp:70
void updateFiducialMarkers(std::vector< aruco::Marker > detectedMarkers, LASTDATA lastd)
ArCameraParam arCamParam
cv::Mat gray
Create a thread type. .
void StartThreading(std::function< void()> threadFunction)