Commit 805f4b6c0c0861b718af0b925a70b1f4f9b8038a
1 parent
6aa2198a
Detector is not thread safe
Showing
1 changed file
with
7 additions
and
3 deletions
openbr/plugins/dlib.cpp
| @@ -80,6 +80,7 @@ class DObjectDetectTransform : public Transform | @@ -80,6 +80,7 @@ class DObjectDetectTransform : public Transform | ||
| 80 | private: | 80 | private: |
| 81 | typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type; | 81 | typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type; |
| 82 | mutable object_detector<image_scanner_type> detector; | 82 | mutable object_detector<image_scanner_type> detector; |
| 83 | + mutable QMutex mutex; | ||
| 83 | 84 | ||
| 84 | void train(const TemplateList &data) | 85 | void train(const TemplateList &data) |
| 85 | { | 86 | { |
| @@ -88,7 +89,7 @@ private: | @@ -88,7 +89,7 @@ private: | ||
| 88 | 89 | ||
| 89 | foreach (const Template &t, data) { | 90 | foreach (const Template &t, data) { |
| 90 | if (!t.file.rects().isEmpty()) { | 91 | if (!t.file.rects().isEmpty()) { |
| 91 | - cv_image<bgr_pixel> cimg(t.m().clone()); | 92 | + cv_image<unsigned char> cimg(t.m().clone()); |
| 92 | 93 | ||
| 93 | array2d<unsigned char> image; | 94 | array2d<unsigned char> image; |
| 94 | assign_image(image,cimg); | 95 | assign_image(image,cimg); |
| @@ -115,18 +116,21 @@ private: | @@ -115,18 +116,21 @@ private: | ||
| 115 | trainer.set_num_threads(max(1,QThread::idealThreadCount())); | 116 | trainer.set_num_threads(max(1,QThread::idealThreadCount())); |
| 116 | trainer.set_c(C); | 117 | trainer.set_c(C); |
| 117 | trainer.set_epsilon(epsilon); | 118 | trainer.set_epsilon(epsilon); |
| 119 | + trainer.be_verbose(); | ||
| 118 | 120 | ||
| 119 | detector = trainer.train(samples, boxes); | 121 | detector = trainer.train(samples, boxes); |
| 120 | } | 122 | } |
| 121 | 123 | ||
| 122 | void project(const Template &src, Template &dst) const | 124 | void project(const Template &src, Template &dst) const |
| 123 | - { | 125 | + { |
| 124 | dst = src; | 126 | dst = src; |
| 125 | - cv_image<bgr_pixel> cimg(src.m().clone()); | 127 | + cv_image<unsigned char> cimg(src.m().clone()); |
| 126 | array2d<unsigned char> image; | 128 | array2d<unsigned char> image; |
| 127 | assign_image(image,cimg); | 129 | assign_image(image,cimg); |
| 128 | 130 | ||
| 131 | + QMutexLocker locker(&mutex); | ||
| 129 | std::vector<rectangle> dets = detector(image); | 132 | std::vector<rectangle> dets = detector(image); |
| 133 | + locker.unlock(); | ||
| 130 | 134 | ||
| 131 | for (int i=0; i<dets.size(); i++) | 135 | for (int i=0; i<dets.size(); i++) |
| 132 | dst.file.appendRect(QRectF(QPointF(dets[i].left(),dets[i].top()),QPointF(dets[i].right(),dets[i].bottom()))); | 136 | dst.file.appendRect(QRectF(QPointF(dets[i].left(),dets[i].top()),QPointF(dets[i].right(),dets[i].bottom()))); |