1 /* 2 Copyright (c) 2019 Ferhat Kurtulmuş 3 Boost Software License - Version 1.0 - August 17th, 2003 4 Permission is hereby granted, free of charge, to any person or organization 5 obtaining a copy of the software and accompanying documentation covered by 6 this license (the "Software") to use, reproduce, display, distribute, 7 execute, and transmit the Software, and to prepare derivative works of the 8 Software, and to permit third-parties to whom the Software is furnished to 9 do so, all subject to the following: 10 The copyright notices in the Software and this entire statement, including 11 the above license grant, this restriction and the following disclaimer, 12 must be included in all copies of the Software, in whole or in part, and 13 all derivative works of the Software, unless such copies or derivative 14 works are solely in the form of machine-executable object code generated by 15 a source language processor. 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 19 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 20 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 DEALINGS IN THE SOFTWARE. 23 */ 24 25 module opencvd.contrib.face; 26 27 import std..string; 28 29 import opencvd.cvcore; 30 31 private extern (C) { 32 LBPHFaceRecognizer CreateLBPHFaceRecognizer(); 33 void LBPHFaceRecognizer_Train(LBPHFaceRecognizer fr, Mats images, IntVector labels); 34 void LBPHFaceRecognizer_Update(LBPHFaceRecognizer fr, Mats images, IntVector labels); 35 int LBPHFaceRecognizer_Predict(LBPHFaceRecognizer fr, Mat sample); 36 PredictResponse LBPHFaceRecognizer_PredictExtended(LBPHFaceRecognizer fr, Mat sample); 37 void LBPHFaceRecognizer_SetThreshold(LBPHFaceRecognizer fr, double threshold); 38 void LBPHFaceRecognizer_SetRadius(LBPHFaceRecognizer fr, int radius); 39 void LBPHFaceRecognizer_SetNeighbors(LBPHFaceRecognizer fr, int neighbors); 40 void LBPHFaceRecognizer_SaveFile(LBPHFaceRecognizer fr, const char* filename); 41 void LBPHFaceRecognizer_LoadFile(LBPHFaceRecognizer fr, const char* filename); 42 int LBPHFaceRecognizer_GetNeighbors(LBPHFaceRecognizer fr); 43 } 44 45 struct PredictResponse { 46 int label; 47 double confidence; 48 }; 49 50 struct _LBPHFaceRecognizer { 51 void* p; 52 53 void train(Mats images, IntVector labels){ 54 LBPHFaceRecognizer_Train(&this, images, labels); 55 } 56 57 void update(Mats images, IntVector labels){ 58 LBPHFaceRecognizer_Update(&this, images, labels); 59 } 60 61 int predict(Mat sample){ 62 return LBPHFaceRecognizer_Predict(&this, sample); 63 } 64 65 PredictResponse predictExtended(Mat sample){ 66 return LBPHFaceRecognizer_PredictExtended(&this, sample); 67 } 68 69 void setThreshold(double threshold){ 70 LBPHFaceRecognizer_SetThreshold(&this, threshold); 71 } 72 73 void setRadius(int radius){ 74 LBPHFaceRecognizer_SetRadius(&this, radius); 75 } 76 77 void setNeighbors(int neighbors){ 78 LBPHFaceRecognizer_SetNeighbors(&this, neighbors); 79 } 80 81 void saveFile(string filename){ 82 LBPHFaceRecognizer_SaveFile(&this, toStringz(filename)); 83 } 84 85 void loadFile(string filename){ 86 LBPHFaceRecognizer_LoadFile(&this, toStringz(filename)); 87 } 88 89 int getNeighbors(){ 90 return LBPHFaceRecognizer_GetNeighbors(&this); 91 } 92 } 93 94 alias LBPHFaceRecognizer = _LBPHFaceRecognizer*; 95 96 LBPHFaceRecognizer newLBPHFaceRecognizer(){ 97 return CreateLBPHFaceRecognizer(); 98 }