Commit 805f4b6c0c0861b718af0b925a70b1f4f9b8038a

Authored by Scott Klum
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 80 private:
81 81 typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type;
82 82 mutable object_detector<image_scanner_type> detector;
  83 + mutable QMutex mutex;
83 84  
84 85 void train(const TemplateList &data)
85 86 {
... ... @@ -88,7 +89,7 @@ private:
88 89  
89 90 foreach (const Template &t, data) {
90 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 94 array2d<unsigned char> image;
94 95 assign_image(image,cimg);
... ... @@ -115,18 +116,21 @@ private:
115 116 trainer.set_num_threads(max(1,QThread::idealThreadCount()));
116 117 trainer.set_c(C);
117 118 trainer.set_epsilon(epsilon);
  119 + trainer.be_verbose();
118 120  
119 121 detector = trainer.train(samples, boxes);
120 122 }
121 123  
122 124 void project(const Template &src, Template &dst) const
123   - {
  125 + {
124 126 dst = src;
125   - cv_image<bgr_pixel> cimg(src.m().clone());
  127 + cv_image<unsigned char> cimg(src.m().clone());
126 128 array2d<unsigned char> image;
127 129 assign_image(image,cimg);
128 130  
  131 + QMutexLocker locker(&mutex);
129 132 std::vector<rectangle> dets = detector(image);
  133 + locker.unlock();
130 134  
131 135 for (int i=0; i<dets.size(); i++)
132 136 dst.file.appendRect(QRectF(QPointF(dets[i].left(),dets[i].top()),QPointF(dets[i].right(),dets[i].bottom())));
... ...