GPUImageHoughTransformLineDetector.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #import "GPUImageFilterGroup.h"
  2. #import "GPUImageThresholdEdgeDetectionFilter.h"
  3. #import "GPUImageParallelCoordinateLineTransformFilter.h"
  4. #import "GPUImageThresholdedNonMaximumSuppressionFilter.h"
  5. #import "GPUImageCannyEdgeDetectionFilter.h"
  6. // This applies a Hough transform to detect lines in a scene. It starts with a thresholded Sobel edge detection pass,
  7. // then takes those edge points in and applies a Hough transform to convert them to lines. The intersection of these lines
  8. // is then determined via blending and accumulation, and a non-maximum suppression filter is applied to find local maxima.
  9. // These local maxima are then converted back into lines in normal space and returned via a callback block.
  10. //
  11. // Rather than using one of the standard Hough transform types, this filter uses parallel coordinate space which is far more efficient
  12. // to rasterize on a GPU.
  13. //
  14. // This approach is based entirely on the PC lines process developed by the Graph@FIT research group at the Brno University of Technology
  15. // and described in their publications:
  16. //
  17. // M. Dubská, J. Havel, and A. Herout. Real-Time Detection of Lines using Parallel Coordinates and OpenGL. Proceedings of SCCG 2011, Bratislava, SK, p. 7.
  18. // http://medusa.fit.vutbr.cz/public/data/papers/2011-SCCG-Dubska-Real-Time-Line-Detection-Using-PC-and-OpenGL.pdf
  19. // M. Dubská, J. Havel, and A. Herout. PClines — Line detection using parallel coordinates. 2011 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), p. 1489- 1494.
  20. // http://medusa.fit.vutbr.cz/public/data/papers/2011-CVPR-Dubska-PClines.pdf
  21. //#define DEBUGLINEDETECTION
  22. @interface GPUImageHoughTransformLineDetector : GPUImageFilterGroup
  23. {
  24. GPUImageOutput<GPUImageInput> *thresholdEdgeDetectionFilter;
  25. // GPUImageThresholdEdgeDetectionFilter *thresholdEdgeDetectionFilter;
  26. GPUImageParallelCoordinateLineTransformFilter *parallelCoordinateLineTransformFilter;
  27. GPUImageThresholdedNonMaximumSuppressionFilter *nonMaximumSuppressionFilter;
  28. GLfloat *linesArray;
  29. GLubyte *rawImagePixels;
  30. }
  31. // A threshold value for which a point is detected as belonging to an edge for determining lines. Default is 0.9.
  32. @property(readwrite, nonatomic) CGFloat edgeThreshold;
  33. // A threshold value for which a local maximum is detected as belonging to a line in parallel coordinate space. Default is 0.20.
  34. @property(readwrite, nonatomic) CGFloat lineDetectionThreshold;
  35. // This block is called on the detection of lines, usually on every processed frame. A C array containing normalized slopes and intercepts in m, b pairs (y=mx+b) is passed in, along with a count of the number of lines detected and the current timestamp of the video frame
  36. @property(nonatomic, copy) void(^linesDetectedBlock)(GLfloat* lineArray, NSUInteger linesDetected, CMTime frameTime);
  37. // These images are only enabled when built with DEBUGLINEDETECTION defined, and are used to examine the intermediate states of the Hough transform
  38. @property(nonatomic, readonly, strong) NSMutableArray *intermediateImages;
  39. @end