8 #ifndef TCPSERVERPOOL_H_ 9 #define TCPSERVERPOOL_H_ 14 #include <QtCore/QThread> 15 #include <QtCore/QSemaphore> 24 QSemaphore * sharedSemaphore,
25 int maxSemaphoreResources,
26 QObject * parent = 0) :
34 UASSERT(maxSemaphoreResources > 0);
41 UINFO(
"Thread %p detecting...", (
void *)this->thread());
52 UINFO(
"Thread %p adding object %d (%s)...", (
void *)this->thread(),
id, filePath.toStdString().c_str());
60 UINFO(
"Thread %p removing object %d...", (
void *)this->thread(),
id);
85 qRegisterMetaType<cv::Mat>(
"cv::Mat");
87 threadPool_.resize(threads);
88 for(
int i=0; i<threads; ++i)
91 UINFO(
"TcpServer set on port: %d (IP=%s)",
95 threadPool_[i] =
new QThread(
this);
98 tcpServer->moveToThread(threadPool_[i]);
99 worker->moveToThread(threadPool_[i]);
100 connect(threadPool_[i], SIGNAL(finished()), tcpServer, SLOT(deleteLater()));
101 connect(threadPool_[i], SIGNAL(finished()), worker, SLOT(deleteLater()));
105 QObject::connect(tcpServer, SIGNAL(detectObject(
const cv::Mat &)), worker, SLOT(
detect(
const cv::Mat &)));
106 QObject::connect(tcpServer, SIGNAL(addObject(
const cv::Mat &,
int,
const QString &)), worker, SLOT(
addObjectAndUpdate(
const cv::Mat &,
int,
const QString &)));
108 threadPool_[i]->start();
114 for(
int i=0; i<threadPool_.size(); ++i)
116 threadPool_[i]->quit();
117 threadPool_[i]->wait();
QSemaphore sharedSemaphore_
QSemaphore * sharedSemaphore_
void addObjectAndUpdate(const cv::Mat &image, int id=0, const QString &filePath=QString())
QHostAddress getHostAddress() const
#define UASSERT(condition)
void detect(const cv::Mat &image)
int maxSemaphoreResources_
void addObjectAndUpdate(const cv::Mat &image, int id, const QString &filePath)
TcpServerPool(find_object::FindObject *sharedFindObject, int threads, int port)
QVector< QThread * > threadPool_
ULogger class and convenient macros.
void objectsFound(const find_object::DetectionInfo &)
void removeObjectAndUpdate(int id)
FindObjectWorker(find_object::FindObject *sharedFindObject, QSemaphore *sharedSemaphore, int maxSemaphoreResources, QObject *parent=0)
find_object::FindObject * sharedFindObject_
void removeObjectAndUpdate(int id)
bool detect(const cv::Mat &image, find_object::DetectionInfo &info) const