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.xfeatures2d; 26 27 import opencvd.cvcore; 28 29 /* !!! WARNING !!! 30 * Your opencv must be compiled with this cmake parameter to use this 31 * module: -DOPENCV_ENABLE_NONFREE:BOOL=ON 32 * Otherwise you will encounter crashes!!! 33 */ 34 35 private extern (C){ 36 SIFT SIFT_Create(); 37 void SIFT_Close(SIFT f); 38 KeyPoints SIFT_Detect(SIFT f, Mat src); 39 KeyPoints SIFT_DetectAndCompute(SIFT f, Mat src, Mat mask, Mat desc); 40 41 SURF SURF_Create(); 42 void SURF_Close(SURF f); 43 KeyPoints SURF_Detect(SURF f, Mat src); 44 KeyPoints SURF_DetectAndCompute(SURF f, Mat src, Mat mask, Mat desc); 45 SURF SURF_CreateWithParams(double hessianThreshold, int nOctaves, int nOctaveLayers, bool extended, bool upright); 46 bool SURF_GetExtended(SURF s); 47 double SURF_GetHessianThreshold(SURF s); 48 int SURF_GetNOctaveLayers(SURF s); 49 int SURF_GetNOctaves(SURF s); 50 bool SURF_GetUpright(SURF s); 51 void SURF_SetExtended(SURF s, bool extended); 52 void SURF_SetHessianThreshold (SURF s, double hessianThreshold); 53 void SURF_SetNOctaveLayers (SURF s, int nOctaveLayers); 54 void SURF_SetNOctaves (SURF s, int nOctaves); 55 void SURF_SetUpright (SURF s, bool upright); 56 KeyPoints SURF_DetectAndCompute2(SURF s, Mat image, Mat mask, Mat descriptors, bool useProvidedKeypoints); 57 } 58 59 struct SIFT { 60 void* p; 61 62 void close(){ 63 SIFT_Close(this); 64 } 65 66 static SIFT opCall(){ 67 return SIFT_Create(); 68 } 69 70 KeyPoint[] detect(Mat src){ 71 KeyPoints kpts = SIFT_Detect(this, src); 72 KeyPoint[] ret = kpts.keypoints[0..kpts.length].dup; 73 KeyPoints_Close(kpts); 74 return ret; 75 } 76 77 KeyPoint[] detectAndCompute(Mat src, Mat mask, Mat desc){ 78 KeyPoints kpts = SIFT_DetectAndCompute(this, src, mask, desc); 79 KeyPoint[] ret = kpts.keypoints[0..kpts.length].dup; 80 KeyPoints_Close(kpts); 81 return ret; 82 } 83 } 84 85 SIFT newSIFT(){ 86 return SIFT_Create(); 87 } 88 89 void Destroy(SIFT s){ 90 SIFT_Close(s); 91 } 92 93 struct SURF { 94 void* p; 95 96 void close(){ 97 SURF_Close(this); 98 } 99 100 static SURF opCall(){ 101 return SURF_Create(); 102 } 103 104 static SURF opCall(double hessianThreshold=100, int nOctaves=4, int nOctaveLayers=3, bool extended=false, bool upright=false){ 105 return SURF_CreateWithParams(hessianThreshold, nOctaves, nOctaveLayers, extended, upright); 106 } 107 108 bool getExtended(){ 109 return SURF_GetExtended(this); 110 } 111 112 double getHessianThreshold(){ 113 return SURF_GetHessianThreshold(this); 114 } 115 116 int getNOctaveLayers(){ 117 return SURF_GetNOctaveLayers(this); 118 } 119 120 int getNOctaves(){ 121 return SURF_GetNOctaves(this); 122 } 123 124 bool getUpright(){ 125 return SURF_GetUpright(this); 126 } 127 128 void setExtended(bool extended){ 129 SURF_SetExtended(this, extended); 130 } 131 132 void setHessianThreshold (double hessianThreshold){ 133 SURF_SetHessianThreshold (this, hessianThreshold); 134 } 135 136 void setNOctaveLayers (int nOctaveLayers){ 137 SURF_SetNOctaveLayers (this, nOctaveLayers); 138 } 139 140 void setNOctaves (int nOctaves){ 141 SURF_SetNOctaves (this, nOctaves); 142 } 143 144 void setUpright (bool upright){ 145 SURF_SetUpright (this, upright); 146 } 147 148 KeyPoint[] detect(Mat src){ 149 KeyPoints kpts = SURF_Detect(this, src); 150 KeyPoint[] ret = kpts.keypoints[0..kpts.length].dup; 151 KeyPoints_Close(kpts); 152 return ret; 153 } 154 155 KeyPoint[] detectAndCompute(Mat src, Mat mask, Mat desc, bool useProvidedKeypoints = false){ 156 KeyPoints kpts = SURF_DetectAndCompute2(this, src, mask, desc, useProvidedKeypoints); 157 KeyPoint[] ret = kpts.keypoints[0..kpts.length].dup; 158 KeyPoints_Close(kpts); 159 return ret; 160 } 161 } 162 163 SURF newSURF(){ 164 return SURF_Create(); 165 } 166 SURF newSURFWithParams(double hessianThreshold=100, int nOctaves=4, int nOctaveLayers=3, bool extended=false, bool upright=false){ 167 return SURF_CreateWithParams(hessianThreshold, nOctaves, nOctaveLayers, extended, upright); 168 } 169 170 void Destroy(SURF s){ 171 SURF_Close(s); 172 }