Commit 8c55324cbe93dbbf8768a9ac040b9a105269ffbd
Merge pull request #278 from biometrics/janusAugment
Attempt to enroll all images with a face bounding box
Showing
2 changed files
with
31 additions
and
13 deletions
openbr/janus.cpp
| @@ -51,23 +51,41 @@ janus_error janus_allocate_template(janus_template *template_) | @@ -51,23 +51,41 @@ janus_error janus_allocate_template(janus_template *template_) | ||
| 51 | janus_error janus_augment(const janus_image image, const janus_attribute_list attributes, janus_template template_) | 51 | janus_error janus_augment(const janus_image image, const janus_attribute_list attributes, janus_template template_) |
| 52 | { | 52 | { |
| 53 | Template t; | 53 | Template t; |
| 54 | - t.append(cv::Mat(image.height, | ||
| 55 | - image.width, | ||
| 56 | - image.color_space == JANUS_GRAY8 ? CV_8UC1 : CV_8UC3, | ||
| 57 | - image.data)); | ||
| 58 | for (size_t i=0; i<attributes.size; i++) | 54 | for (size_t i=0; i<attributes.size; i++) |
| 59 | t.file.set(janus_attribute_to_string(attributes.attributes[i]), attributes.values[i]); | 55 | t.file.set(janus_attribute_to_string(attributes.attributes[i]), attributes.values[i]); |
| 60 | 56 | ||
| 61 | - if (!t.file.contains("RIGHT_EYE_X") || | ||
| 62 | - !t.file.contains("RIGHT_EYE_Y") || | ||
| 63 | - !t.file.contains("LEFT_EYE_X") || | ||
| 64 | - !t.file.contains("LEFT_EYE_Y")) | 57 | + if (!t.file.contains("FACE_X") || |
| 58 | + !t.file.contains("FACE_Y") || | ||
| 59 | + !t.file.contains("FACE_WIDTH") || | ||
| 60 | + !t.file.contains("FACE_HEIGHT")) | ||
| 65 | return JANUS_MISSING_ATTRIBUTES; | 61 | return JANUS_MISSING_ATTRIBUTES; |
| 66 | 62 | ||
| 67 | - t.file.set("Affine_0", QPointF(t.file.get<float>("RIGHT_EYE_X"), t.file.get<float>("RIGHT_EYE_Y"))); | ||
| 68 | - t.file.set("Affine_1", QPointF(t.file.get<float>("LEFT_EYE_X"), t.file.get<float>("LEFT_EYE_Y"))); | ||
| 69 | - t.file.appendPoint(t.file.get<QPointF>("Affine_1")); | ||
| 70 | - t.file.appendPoint(t.file.get<QPointF>("Affine_0")); | 63 | + QRectF rect(t.file.get<float>("FACE_X"), |
| 64 | + t.file.get<float>("FACE_Y"), | ||
| 65 | + t.file.get<float>("FACE_WIDTH"), | ||
| 66 | + t.file.get<float>("FACE_HEIGHT")); | ||
| 67 | + | ||
| 68 | + if (rect.x() < 0) rect.setX(0); | ||
| 69 | + if (rect.y() < 0) rect.setY(0); | ||
| 70 | + if (rect.x() + rect.width() > image.width) rect.setWidth(image.width - rect.x()); | ||
| 71 | + if (rect.y() + rect.height() > image.height) rect.setHeight(image.height - rect.y()); | ||
| 72 | + | ||
| 73 | + cv::Mat input(image.height, | ||
| 74 | + image.width, | ||
| 75 | + image.color_space == JANUS_GRAY8 ? CV_8UC1 : CV_8UC3, | ||
| 76 | + image.data); | ||
| 77 | + | ||
| 78 | + input = input(cv::Rect(rect.x(), rect.y(), rect.width(), rect.height())).clone(); | ||
| 79 | + t.append(input); | ||
| 80 | + if (t.file.contains("RIGHT_EYE_X") && | ||
| 81 | + t.file.contains("RIGHT_EYE_Y") && | ||
| 82 | + t.file.contains("LEFT_EYE_X") && | ||
| 83 | + t.file.contains("LEFT_EYE_Y")) { | ||
| 84 | + t.file.set("Affine_0", QPointF(t.file.get<float>("RIGHT_EYE_X") - rect.x(), t.file.get<float>("RIGHT_EYE_Y") - rect.y())); | ||
| 85 | + t.file.set("Affine_1", QPointF(t.file.get<float>("LEFT_EYE_X") - rect.x(), t.file.get<float>("LEFT_EYE_Y") - rect.y())); | ||
| 86 | + t.file.appendPoint(t.file.get<QPointF>("Affine_0")); | ||
| 87 | + t.file.appendPoint(t.file.get<QPointF>("Affine_1")); | ||
| 88 | + } | ||
| 71 | Template u; | 89 | Template u; |
| 72 | transform->project(t, u); | 90 | transform->project(t, u); |
| 73 | template_->append(u); | 91 | template_->append(u); |