Project

General

Profile

BitmapToolkit Scol plugin
ArBlobDetector.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 "ArCameraParam.h"
27#include "ArBlobDetector.h"
28
29#include <vector>
30
31ArBlobDetector::ArBlobDetector(cv::SimpleBlobDetector::Params params)
32{
33 needUpdate = false;
34
35 mDetector = cv::SimpleBlobDetector::create(params);
36
37 // Run thread
38 StartThreading(boost::bind(&ArBlobDetector::GoThread, this));
39
40 //cv::namedWindow("debug");
41}
42
44{
46
47 if (!mDetector.empty())
48 mDetector.release();
49
50 mDotList.clear();
51}
52
53std::vector<cv::Point3f> ArBlobDetector::GetLastDotList()
54{
55 boost::mutex::scoped_lock l(mMutex);
56 std::vector<cv::Point3f> ldots = mDotList;
57 return ldots;
58}
59
61{
62 boost::mutex::scoped_lock l(mMutex);
63 std::vector<cv::Point3f> ldots = mDotList;
64 return cv::Size(mLastData.gray.cols, mLastData.gray.rows);
65}
66
67std::vector<cv::Point3f> ArBlobDetector::DetectBlobs(const cv::Mat input, aruco::CameraParameters camParam, bool reversedBitmap)
68{
69 std::vector<cv::Point3f> outVector;
70
71 try
72 {
73 std::vector<cv::KeyPoint> keypoints;
74 mDetector->detect(input, keypoints);
75
76 // extract the x y coordinates of the keypoints:
77 for (unsigned int i = 0; i < keypoints.size(); i++)
78 {
79 cv::Point3f dot(keypoints[i].pt.x, keypoints[i].pt.y, keypoints[i].size);
80 outVector.push_back(dot);
81 }
82 }
83 catch(cv::Exception &)
84 {
85 //error
86 }
87
88 return outVector;
89}
90
92{
93 while (IsRunning())
94 {
95 if (needUpdate)
96 {
98 manager->GetLastData(mLastData);
99 needUpdate = false;
100
101 //cv::equalizeHist(mLastData.gray, mLastData.gray);
102 // increase image contrast
103 //mLastData.gray.convertTo(mLastData.gray, -1, 1.1, 0);
104 cv::blur(mLastData.gray, mLastData.gray, cv::Size(1, 1));
105
106 std::vector<cv::Point3f> dotList = DetectBlobs(mLastData.gray, mLastData.arCamParam.camParam, mLastData.reversedBitmap);
107 {
108 boost::mutex::scoped_lock l(mMutex);
109 mDotList = dotList;
110 }
111 }
112 else
113 {
114 //prevent cpu burn
115 boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); //DO not burn too much CPU
116 }
117 }
118}
cv::Size GetLastBufferSize()
ArBlobDetector(cv::SimpleBlobDetector::Params params)
std::vector< cv::Point3f > GetLastDotList()
aruco::CameraParameters camParam
void GetLastData(LASTDATA &data)
static ArManager * GetInstance()
Definition ArManager.cpp:70
ArCameraParam arCamParam
cv::Mat gray
bool reversedBitmap
void StartThreading(std::function< void()> threadFunction)