BitmapToolkit Scol plugin
ArFeaturedDetector.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 "sService.h"
26
27#include "ArManager.h"
28#include "ArCameraParam.h"
29#include "ArFeaturedDetector.h"
30
31#include <vector>
32
34{
35 needUpdate = false;
36
37 // Run thread
39}
40
45
47{
48 while (IsRunning())
49 {
50 if (needUpdate)
51 {
53 manager->GetLastData(mLastData);
54 needUpdate = false;
55
56 //small denoising
57 if (mLastData.gray.rows != 480 || mLastData.gray.cols != 640)
58 {
59 cv::Size nsize;
60 if (mLastData.gray.rows >= mLastData.gray.cols)
61 {
62 nsize.width = (int)(((float)mLastData.gray.cols * 480.0f) / (float)mLastData.gray.rows);
63 nsize.height = 480;
64 }
65 else
66 {
67 nsize.width = 640;
68 nsize.height = (int)(((float)mLastData.gray.rows * 640.0f) / (float)mLastData.gray.cols);
69 }
70 cv::resize(mLastData.gray, mLastData.gray, nsize, 0, 0, cv::INTER_CUBIC);
71 }
72
73 cv::equalizeHist(mLastData.gray, mLastData.gray);
74 ArManager::MarkerList::iterator imarker;
75
76 // Detect all markers seen on gray
77 {
78 //read only
79 boost::shared_lock< boost::shared_mutex > lockList(manager->listMutex);
80
81 //detect last visible markers
82 ArMarker* lastVisible = 0;
83 for (imarker = manager->markerList.begin(); imarker != manager->markerList.end(); ++imarker)
84 {
85 if (((*imarker)->GetType() == ArMarker::AR_FFT_MARKER) && (*imarker)->IsVisible())
86 lastVisible = (*imarker);
87 }
88
89 for (imarker = manager->markerList.begin(); imarker != manager->markerList.end(); ++imarker)
90 {
91 //threaded detection
92 if ((*imarker)->GetType() == ArMarker::AR_FFT_MARKER)
93 {
94 ArFeaturedMarker* fftmarker = static_cast<ArFeaturedMarker*> (*imarker);
95 if (lastVisible == (*imarker) || (lastVisible == 0))
96 fftmarker->Update(mLastData.gray, mLastData.image, mLastData.arCamParam.camParam, mLastData.reversedBitmap);
97 else
98 fftmarker->SetVisible(false);
99 }
100 }
101 }
102 }
103 else
104 {
105 //prevent cpu burn
106 boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); //DO not burn too much CPU
107 }
108 }
109}
aruco::CameraParameters camParam
void GetLastData(LASTDATA &data)
MarkerList markerList
Definition ArManager.h:51
static ArManager * GetInstance()
Definition ArManager.cpp:70
boost::shared_mutex listMutex
Definition ArManager.h:50
@ AR_FFT_MARKER
Definition ArMarker.h:43
void SetVisible(bool visible)
Definition ArMarker.cpp:100
ArCameraParam arCamParam
cv::Mat image
cv::Mat gray
bool reversedBitmap
Create a thread type. .
void StartThreading(std::function< void()> threadFunction)