| 163 | } |
| 164 | |
| 165 | bool IPLCanny::processInputData(IPLData* data, int, bool useOpenCV) |
| 166 | { |
| 167 | IPLImage* image = data->toImage(); |
| 168 | |
| 169 | // delete previous result |
| 170 | delete _result; |
| 171 | _result = NULL; |
| 172 | delete _binaryImage; |
| 173 | _binaryImage = NULL; |
| 174 | |
| 175 | int width = image->width(); |
| 176 | int height = image->height(); |
| 177 | |
| 178 | _result = new IPLImage( image->type(), width, height ); |
| 179 | _binaryImage = new IPLImage( IPL_IMAGE_BW, width, height ); |
| 180 | |
| 181 | // get properties |
| 182 | int window = getProcessPropertyInt("window"); |
| 183 | double sigma = getProcessPropertyDouble("sigma"); |
| 184 | double lowThreshold = getProcessPropertyDouble("lowThreshold"); |
| 185 | double highThreshold = getProcessPropertyDouble("highThreshold"); |
| 186 | |
| 187 | std::stringstream s; |
| 188 | s << "Window: "; |
| 189 | s << window; |
| 190 | addInformation(s.str()); |
| 191 | |
| 192 | //! @todo currently only the opencv implementation works |
| 193 | if(useOpenCV || true) |
| 194 | { |
| 195 | notifyProgressEventHandler(-1); |
| 196 | cv::Mat input; |
| 197 | cv::Mat output; |
| 198 | cvtColor(image->toCvMat(), input, CV_BGR2GRAY); |
| 199 | cv::GaussianBlur(input, input, cv::Size(window, window), sigma); |
| 200 | cv::Canny(input, output, lowThreshold*255, highThreshold*255, window); |
| 201 | |
| 202 | delete _result; |
| 203 | _result = new IPLImage(output); |
| 204 | |
| 205 | return true; |
| 206 | } |
| 207 | |
| 208 | return false; |
| 209 | |
| 210 | // Create a Gaussian 1D filter |
| 211 | int N = ceil( sigma * sqrt( 2.0*log( 1.0/0.015 ) ) + 1.0 ); |
| 212 | double ssq = sigma*sigma; |
| 213 | double* gau = new double [window]; |
| 214 | double* dgau = new double [window]; |
| 215 | for( int k = -N; k <= N; ++k ) |
| 216 | { |
| 217 | gau[k+N] = gauss ( (double)k, ssq ); |
| 218 | dgau[k+N] = dGauss ( (double)k, 0, ssq ); |
| 219 | } |
| 220 | |
| 221 | // Create a directional derivative of 2D Gaussian (along X-axis) |
| 222 | // Since the result is symmetric along X, we can get the derivative along |