Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
classLaserSensingTrajectory.h@33:43e8bc451ef0, 2012-11-05 (annotated)
- Committer:
- mbedalvaro
- Date:
- Mon Nov 05 06:08:35 2012 +0000
- Revision:
- 33:43e8bc451ef0
- Parent:
- 32:52273c3291fe
- Child:
- 34:1244fa3f2559
added resizing functions, as well as better control on the thresholding modes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 32:52273c3291fe | 1 | #ifndef LSDTRAJECTORY_H |
mbedalvaro | 32:52273c3291fe | 2 | #define LSDTRAJECTORY_H |
mbedalvaro | 32:52273c3291fe | 3 | |
mbedalvaro | 32:52273c3291fe | 4 | #include <vector> |
mbedalvaro | 32:52273c3291fe | 5 | using namespace std; |
mbedalvaro | 32:52273c3291fe | 6 | |
mbedalvaro | 33:43e8bc451ef0 | 7 | // Thresholding mode: |
mbedalvaro | 33:43e8bc451ef0 | 8 | enum thresholdingMode {FIXED, AUTO}; |
mbedalvaro | 33:43e8bc451ef0 | 9 | |
mbedalvaro | 33:43e8bc451ef0 | 10 | |
mbedalvaro | 33:43e8bc451ef0 | 11 | //(1) fixed threshold: |
mbedalvaro | 33:43e8bc451ef0 | 12 | #define FIXED_THRESHOLD 35 |
mbedalvaro | 33:43e8bc451ef0 | 13 | |
mbedalvaro | 33:43e8bc451ef0 | 14 | //(1) Autothreshold: |
mbedalvaro | 32:52273c3291fe | 15 | // CONTRAST RATIO to compute autoThreshold: |
mbedalvaro | 32:52273c3291fe | 16 | // MIN_CONTRAST_RATIO is the minimum contrast between max and min intensity necessary to "accept" a black and white zone: |
mbedalvaro | 32:52273c3291fe | 17 | #define MIN_CONTRAST_RATIO 1.8//1.7 // 3 seems good when lookup table does not work |
mbedalvaro | 32:52273c3291fe | 18 | // THRESHOLD_FACTOR is where the threshold is actually placed between the min and max detected (with good contrast): |
mbedalvaro | 32:52273c3291fe | 19 | #define THRESHOLD_FACTOR 0.5 //0.75 // 2/3 or 1/2 are good values |
mbedalvaro | 32:52273c3291fe | 20 | #define MIN_ACCEPTABLE_INTENSITY 16 // if maxI< this then we consider all the saccade on something black |
mbedalvaro | 32:52273c3291fe | 21 | |
mbedalvaro | 33:43e8bc451ef0 | 22 | |
mbedalvaro | 33:43e8bc451ef0 | 23 | |
mbedalvaro | 32:52273c3291fe | 24 | struct laserSensingPoint { |
mbedalvaro | 32:52273c3291fe | 25 | // Position and color (after rendering) |
mbedalvaro | 32:52273c3291fe | 26 | unsigned short x, y; // position of the point (after rendering - its integer, because it is in "laser projector pixels") |
mbedalvaro | 32:52273c3291fe | 27 | // char color; // per point laser color (not used yet) |
mbedalvaro | 32:52273c3291fe | 28 | // Detection: |
mbedalvaro | 32:52273c3291fe | 29 | unsigned char intensity; // detected intensity (in fact, this will be the REFLECTIVITY RATIO if using LUT table, and it's between 0 and 1, but we will multiply by 255 to avoid using a float. |
mbedalvaro | 32:52273c3291fe | 30 | signed char lightZone; // the thresholded light zone (allow for negative values for simply computing "negative" forces - although this is not necessarily the best option) |
mbedalvaro | 32:52273c3291fe | 31 | }; |
mbedalvaro | 32:52273c3291fe | 32 | |
mbedalvaro | 32:52273c3291fe | 33 | |
mbedalvaro | 32:52273c3291fe | 34 | class LaserSensingTrajectory { |
mbedalvaro | 32:52273c3291fe | 35 | |
mbedalvaro | 32:52273c3291fe | 36 | public: |
mbedalvaro | 32:52273c3291fe | 37 | |
mbedalvaro | 32:52273c3291fe | 38 | LaserSensingTrajectory(); |
mbedalvaro | 32:52273c3291fe | 39 | ~LaserSensingTrajectory(); |
mbedalvaro | 32:52273c3291fe | 40 | |
mbedalvaro | 32:52273c3291fe | 41 | // METHODS: |
mbedalvaro | 32:52273c3291fe | 42 | void processSensedData(); |
mbedalvaro | 32:52273c3291fe | 43 | void setDelayMirrors(int); // in general, the delay will depend on the number of points being DISPLAYED (in other terms, on the size of lsdTrajectory). |
mbedalvaro | 32:52273c3291fe | 44 | void addDelayMirrors(int add_delay); |
mbedalvaro | 32:52273c3291fe | 45 | |
mbedalvaro | 33:43e8bc451ef0 | 46 | void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);}; |
mbedalvaro | 33:43e8bc451ef0 | 47 | void setFixedThreshold(unsigned char value) {fixedThreshold=value;}; |
mbedalvaro | 32:52273c3291fe | 48 | void setMinContrastRatio(float value) {min_contrast_ratio=value;}; |
mbedalvaro | 32:52273c3291fe | 49 | void setThresholdFactor(float value) {threshold_factor=value;}; |
mbedalvaro | 33:43e8bc451ef0 | 50 | void setMinAcceptableIntensity(unsigned char value) {min_acceptable_intensity=value;}; |
mbedalvaro | 32:52273c3291fe | 51 | void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;}; |
mbedalvaro | 32:52273c3291fe | 52 | void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;}; |
mbedalvaro | 32:52273c3291fe | 53 | |
mbedalvaro | 32:52273c3291fe | 54 | // DATA: |
mbedalvaro | 32:52273c3291fe | 55 | vector <laserSensingPoint> lsdTrajectory; |
mbedalvaro | 32:52273c3291fe | 56 | unsigned char displayColor; // per blob color |
mbedalvaro | 32:52273c3291fe | 57 | |
mbedalvaro | 32:52273c3291fe | 58 | // software adjustement of mirror delay: |
mbedalvaro | 32:52273c3291fe | 59 | unsigned char delayMirrorSamples; // this is required because it will affect the way the blob behaves - it |
mbedalvaro | 32:52273c3291fe | 60 | //could be in the laser renderer, but by putting it here we can have more per-blob fine tunning |
mbedalvaro | 32:52273c3291fe | 61 | |
mbedalvaro | 33:43e8bc451ef0 | 62 | // parameters for thresholding and thresholding mode: |
mbedalvaro | 33:43e8bc451ef0 | 63 | thresholdingMode modeThreshold; |
mbedalvaro | 32:52273c3291fe | 64 | float min_contrast_ratio, threshold_factor, min_acceptable_intensity; |
mbedalvaro | 33:43e8bc451ef0 | 65 | unsigned char autoThreshold, fixedThreshold; // 0 to 255 |
mbedalvaro | 32:52273c3291fe | 66 | |
mbedalvaro | 32:52273c3291fe | 67 | // Statistics and tests: |
mbedalvaro | 32:52273c3291fe | 68 | //float lightRatio; |
mbedalvaro | 32:52273c3291fe | 69 | unsigned char maxI, minI; // Max and Min intensity RATIOS (normalized between 0 and 255) |
mbedalvaro | 32:52273c3291fe | 70 | bool lightTouched; // true if something went over the autoThreshold for the whole loop |
mbedalvaro | 32:52273c3291fe | 71 | // char coko; |
mbedalvaro | 32:52273c3291fe | 72 | }; |
mbedalvaro | 32:52273c3291fe | 73 | |
mbedalvaro | 32:52273c3291fe | 74 | #endif |
mbedalvaro | 32:52273c3291fe | 75 | |
mbedalvaro | 32:52273c3291fe | 76 |