00001 /*!@file AppMedia/app-parse-need-for-speed.C */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Vgames/app-parse-need-for-speed.C $ 00035 // $Id: app-parse-need-for-speed.C 9412 2008-03-10 23:10:15Z farhan $ 00036 // 00037 00038 #ifndef APPMEDIA_APP_PARSE_NEED_FOR_SPEED_C_DEFINED 00039 #define APPMEDIA_APP_PARSE_NEED_FOR_SPEED_C_DEFINED 00040 00041 #include "Component/ModelManager.H" 00042 #include "GUI/XWinManaged.H" 00043 #include "Image/ColorOps.H" 00044 #include "Image/CutPaste.H" 00045 #include "Image/DrawOps.H" 00046 #include "Image/Image.H" 00047 #include "Image/MathOps.H" 00048 #include "Image/Pixels.H" 00049 #include "Image/Point2D.H" 00050 #include "Image/ShapeOps.H" 00051 #include "Media/FrameSeries.H" 00052 #include "Raster/GenericFrame.H" 00053 #include "Raster/Raster.H" 00054 #include "Util/log.H" 00055 #include "Util/sformat.H" 00056 #include "Video/VideoFrame.H" 00057 00058 #include <algorithm> 00059 #include <iostream> 00060 #include <limits> 00061 #include <sstream> 00062 #include <sys/types.h> 00063 #include <unistd.h> 00064 #include <vector> 00065 00066 namespace 00067 { 00068 const float ILAB_data[] = 00069 { 00070 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */ 00071 /* 0*/ 48.4333, 49.0800, 49.3356, 49.4956, 49.5689, 49.3133, 49.7711, 50.9822, 52.1600, 53.1111, 52.0156, 51.1156, 50.2400, 50.8200, 51.6133, 51.5867, 51.2689, 50.7444, 50.6156, 51.1044, 51.8956, 52.7200, 53.3378, 52.9844, 52.4444, 51.9844, 52.0133, 52.2911, 52.3733, 52.7111, 52.5489, 00072 /* 1*/ 52.5111, 54.9711, 59.1000, 63.9200, 64.9622, 61.8600, 58.4089, 60.7356, 66.3578, 71.2311, 65.9600, 58.8400, 53.8511, 54.1244, 55.9044, 55.6889, 56.3089, 57.8289, 60.0644, 60.2533, 58.3800, 56.7956, 56.1733, 57.6267, 60.4822, 64.1933, 66.6622, 67.4444, 65.4889, 62.3800, 58.6622, 00073 /* 2*/ 54.3889, 68.1889, 93.3978, 118.2267, 122.4600, 105.1467, 81.1644, 77.7956, 90.3133, 102.3489, 88.1378, 67.1156, 53.9622, 53.8644, 56.1978, 56.0267, 63.8000, 78.3778, 91.2422, 87.1156, 71.0578, 56.7022, 53.8800, 65.6667, 85.8867, 108.3978, 122.4089, 125.7444, 114.4556, 94.9889, 72.6356, 00074 /* 3*/ 54.9667, 83.5844, 137.8822, 188.7444, 196.6711, 162.1733, 111.2578, 97.3667, 114.3000, 130.3044, 105.4644, 72.6778, 53.4444, 53.6711, 54.4711, 55.3222, 76.8933, 114.2178, 142.3844, 129.7756, 89.9022, 54.9511, 50.7622, 79.1178, 124.3378, 168.9667, 188.8956, 194.2489, 179.7644, 147.2956, 102.4622, 00075 /* 4*/ 51.4667, 81.8533, 143.4422, 204.3200, 211.9111, 166.2133, 114.2267, 103.7778, 126.9000, 138.0867, 104.6156, 70.1267, 52.0911, 54.0044, 53.7867, 59.4911, 93.1756, 144.8978, 176.4533, 156.5089, 100.1178, 54.2311, 53.0222, 93.2067, 145.8711, 181.1289, 185.9978, 192.4844, 187.9933, 175.8511, 131.1022, 00076 /* 5*/ 47.0111, 70.3511, 121.0111, 173.1911, 174.1400, 124.9733, 92.3622, 98.9933, 132.3467, 135.0200, 95.5022, 63.6178, 49.8333, 54.1267, 57.5733, 70.6022, 108.0533, 156.7000, 178.2889, 158.7978, 100.0467, 56.8844, 60.2044, 104.5667, 151.7889, 159.0689, 136.7156, 138.8178, 153.1689, 170.6311, 137.7067, 00077 /* 6*/ 46.2111, 68.6511, 112.1489, 153.5889, 141.2867, 94.1333, 77.1533, 98.1156, 136.3778, 131.2578, 89.6756, 59.0489, 48.2822, 55.6000, 68.1800, 86.4444, 118.8133, 151.9044, 164.3333, 152.7756, 101.4000, 63.1822, 65.8844, 112.1867, 164.5111, 172.5111, 152.6511, 148.6244, 154.8600, 161.3489, 125.1444, 00078 /* 7*/ 47.8578, 77.0867, 120.6667, 154.1400, 126.7178, 81.8933, 73.9333, 103.4978, 140.9444, 126.4800, 86.0667, 55.7044, 47.4444, 58.7956, 81.6733, 107.3667, 136.2467, 154.9978, 162.3356, 153.2244, 107.9600, 70.8711, 71.4733, 119.7533, 182.7689, 205.7222, 205.4222, 200.1467, 189.3978, 161.7556, 112.4533, 00079 /* 8*/ 51.4400, 87.2689, 132.7156, 156.9067, 117.8622, 76.0422, 75.3733, 110.0467, 142.8711, 119.3556, 81.2511, 51.9444, 47.3467, 64.4200, 97.9400, 138.3378, 171.6378, 188.6356, 188.2244, 167.9311, 116.5333, 77.5000, 81.3622, 127.2889, 180.2578, 194.3467, 199.0133, 199.3067, 195.2222, 163.0556, 109.9578, 00080 /* 9*/ 59.7222, 102.5089, 148.2911, 158.9911, 111.5644, 72.9933, 78.9200, 118.1244, 146.8622, 121.1156, 85.6289, 56.2511, 53.9467, 77.3111, 117.9622, 164.1378, 191.1822, 204.5133, 201.6533, 179.5311, 122.4556, 83.4733, 91.4467, 132.2400, 162.7311, 148.0244, 143.7489, 154.1644, 173.2800, 156.3200, 107.4422, 00081 /*10*/ 81.8156, 138.5022, 184.0378, 180.9667, 123.1311, 77.9511, 84.7600, 130.7800, 171.3133, 163.0644, 132.5089, 95.4644, 84.0778, 101.5111, 135.1467, 158.5400, 159.6089, 166.9133, 171.9000, 169.1778, 124.3667, 88.9022, 97.4422, 140.5889, 172.5333, 159.0600, 151.1622, 153.5778, 163.3933, 139.4689, 94.1644, 00082 /*11*/ 105.3844, 175.3178, 215.2556, 207.7689, 145.9644, 89.9533, 90.5356, 139.9689, 197.5311, 212.1822, 194.8533, 152.5778, 123.8311, 121.8444, 139.5533, 131.9222, 108.4378, 106.0000, 124.0911, 146.1200, 118.7422, 89.9378, 98.6889, 149.1978, 197.7689, 205.7800, 199.2978, 181.7022, 155.9800, 113.1044, 76.0333, 00083 /*12*/ 100.2644, 157.4200, 190.8422, 183.6756, 135.4400, 89.1533, 85.1356, 121.9822, 172.9933, 196.3422, 186.6378, 152.1311, 122.9800, 111.4511, 118.0644, 101.8133, 79.3400, 74.5956, 91.9222, 114.5000, 99.5111, 81.1933, 88.6200, 130.3089, 176.3467, 193.2733, 186.6333, 158.9200, 121.7111, 84.7711, 64.0889, 00084 /*13*/ 75.4733, 99.9489, 114.4267, 112.2156, 91.8467, 72.3156, 69.9289, 85.4356, 107.5556, 119.5311, 115.3867, 99.7778, 86.7800, 80.7067, 82.5578, 74.1933, 64.8844, 62.6444, 70.3844, 80.2178, 74.4422, 67.5511, 71.3000, 89.6489, 110.0756, 117.9800, 112.6311, 98.1022, 80.2378, 66.4156, 59.9956, 00085 /*14*/ 59.9978, 64.2289, 66.9422, 66.5244, 62.7578, 59.9511, 59.8489, 62.6467, 66.1444, 67.6711, 66.6644, 64.1911, 62.2111, 61.3933, 61.5822, 59.8067, 58.4244, 58.2689, 59.9400, 61.7733, 60.6444, 59.9000, 61.0044, 64.3222, 67.0956, 67.5667, 65.9978, 63.7756, 61.4133, 60.0622, 59.0400 00086 }; 00087 00088 const float digit0_data[] = 00089 { 00090 /**/ 18.9858, 18.5589, 18.3984, 18.0650, 17.9390, 17.3354, 16.9878, 17.0041, 00091 /**/ 11.7276, 11.2012, 12.6362, 16.8984, 20.5955, 19.7927, 15.0691, 11.0976, 00092 /**/ 10.9329, 11.9695, 24.1667, 49.5874, 66.6728, 62.8130, 38.2398, 15.2215, 00093 /**/ 13.2561, 21.8069, 58.6159, 114.0366, 147.7012, 137.9329, 87.8943, 33.2154, 00094 /**/ 19.2114, 42.3354, 93.3191, 147.2581, 178.3882, 168.2317, 121.1260, 53.9004, 00095 /**/ 29.8293, 67.5528, 107.9350, 123.3455, 132.2378, 131.4797, 115.4431, 62.2663, 00096 /**/ 40.8841, 83.6463, 107.8780, 93.3841, 89.2561, 99.7337, 104.0874, 62.3354, 00097 /**/ 48.4106, 87.8455, 99.1077, 78.5041, 78.6037, 96.1159, 99.4878, 57.9593, 00098 /**/ 52.9045, 87.6077, 89.6321, 73.1850, 81.8699, 100.9614, 95.5752, 52.1667, 00099 /**/ 56.9858, 89.9411, 95.4289, 90.2053, 102.0447, 111.2012, 88.7520, 44.9451, 00100 /**/ 62.3333, 103.9309, 132.7724, 139.7764, 137.4614, 115.8049, 74.0366, 40.6829, 00101 /**/ 57.4817, 109.1016, 164.0325, 179.6707, 151.9472, 91.7439, 45.8780, 38.6118, 00102 /**/ 38.0386, 79.1870, 130.8963, 146.5793, 112.9654, 51.5325, 21.9695, 30.2785, 00103 /**/ 18.7358, 34.5346, 56.8801, 63.4289, 47.1443, 21.6321, 12.4309, 17.2154, 00104 /**/ 12.7520, 14.3293, 16.7927, 17.2703, 14.6443, 11.9512, 11.4533, 11.5447 00105 }; 00106 00107 const float digit1_data[] = 00108 { 00109 /**/ 20.7563, 20.6311, 20.4518, 20.2995, 20.3046, 20.0846, 19.8477, 19.5601, 00110 /**/ 11.6734, 12.8088, 16.8443, 19.6904, 17.9729, 13.4365, 11.2690, 10.7547, 00111 /**/ 12.1049, 24.4890, 53.1421, 68.7597, 56.2707, 27.4416, 11.6971, 9.8799, 00112 /**/ 14.3689, 41.3316, 103.9086, 139.8494, 115.9255, 52.8460, 14.5127, 10.3892, 00113 /**/ 13.5584, 39.9645, 109.9628, 157.9052, 136.3164, 64.1117, 16.0000, 10.5228, 00114 /**/ 11.5042, 29.8900, 85.2927, 133.0118, 117.7699, 57.0271, 15.2504, 9.8816, 00115 /**/ 11.4755, 28.9865, 75.3621, 117.4755, 99.0338, 46.6379, 13.6988, 9.9729, 00116 /**/ 12.2809, 36.2267, 83.7648, 117.2318, 86.4704, 36.5178, 11.5922, 10.4450, 00117 /**/ 14.3773, 46.1591, 96.2470, 117.8731, 75.5804, 27.8731, 10.2876, 11.7073, 00118 /**/ 18.3824, 55.8629, 105.4569, 114.7327, 65.8934, 21.9763, 9.9255, 13.8832, 00119 /**/ 27.6041, 64.2115, 108.0017, 106.1861, 55.8748, 17.3570, 10.7496, 20.7868, 00120 /**/ 38.8629, 67.6785, 100.1489, 88.9797, 43.3723, 13.8951, 12.0508, 28.5381, 00121 /**/ 35.3249, 52.3401, 71.3113, 60.2589, 29.3350, 12.3621, 12.3706, 25.6870, 00122 /**/ 20.8020, 26.6751, 33.8020, 29.0508, 17.5347, 11.6413, 12.0541, 17.4501, 00123 /**/ 15.5330, 16.1269, 16.9712, 15.8257, 14.3130, 13.4535, 13.7563, 14.7817 00124 }; 00125 00126 const float digit2_data[] = 00127 { 00128 /**/ 14.8670, 15.2640, 15.4700, 15.1798, 14.8090, 13.9307, 13.7266, 13.7566, 00129 /**/ 8.0300, 8.6180, 9.9288, 13.3427, 16.1479, 14.2978, 10.0169, 7.7472, 00130 /**/ 7.7809, 9.7884, 24.1779, 51.2884, 68.2022, 59.5506, 32.6592, 11.1685, 00131 /**/ 10.4251, 18.3858, 57.9382, 117.3820, 150.7659, 134.4326, 79.0506, 24.5693, 00132 /**/ 17.1199, 37.9888, 87.7547, 143.1554, 171.2135, 158.8539, 106.4551, 40.4419, 00133 /**/ 23.4607, 52.4738, 88.7715, 111.0712, 122.0843, 122.2865, 96.5524, 45.6461, 00134 /**/ 19.9382, 39.4700, 59.4251, 70.7266, 83.8820, 92.2097, 75.5618, 37.0075, 00135 /**/ 12.2453, 17.2659, 32.9045, 58.2303, 82.1142, 83.4906, 54.1629, 22.0543, 00136 /**/ 9.9719, 16.5075, 39.1779, 68.0000, 80.1816, 62.7453, 29.5206, 11.5787, 00137 /**/ 19.4925, 43.4906, 73.8352, 84.9831, 68.8708, 35.7622, 13.3109, 9.5487, 00138 /**/ 54.8277, 101.4513, 136.4625, 133.4139, 95.3071, 45.1180, 18.0169, 17.3745, 00139 /**/ 92.8390, 155.0206, 194.8801, 194.9438, 149.7828, 80.6105, 32.5599, 28.7734, 00140 /**/ 82.7828, 134.5431, 169.7303, 173.8258, 137.3745, 77.3390, 31.6929, 27.4663, 00141 /**/ 38.6873, 61.0375, 76.1910, 78.0843, 62.2884, 36.0169, 17.1704, 15.5843, 00142 /**/ 13.4625, 17.3427, 19.8146, 19.8858, 17.2004, 12.7228, 10.6273, 10.4888 00143 }; 00144 00145 const float digit3_data[] = 00146 { 00147 /**/ 16.9937, 16.5577, 16.2264, 16.3249, 16.5577, 16.9623, 17.3166, 17.4088, 00148 /**/ 9.8302, 10.0419, 12.2516, 16.7925, 20.1237, 20.0126, 17.0356, 12.9182, 00149 /**/ 10.7296, 16.3899, 38.5346, 69.3543, 88.8910, 86.2914, 63.2180, 31.7652, 00150 /**/ 13.6268, 26.3417, 72.9602, 138.2537, 180.0377, 178.0524, 129.6751, 59.8344, 00151 /**/ 13.6709, 23.0021, 66.0419, 136.6960, 188.1845, 190.5639, 137.1090, 59.6981, 00152 /**/ 11.7400, 13.9036, 42.3899, 101.9245, 148.3941, 144.1971, 92.5325, 35.0273, 00153 /**/ 10.0314, 12.3270, 45.7317, 107.7002, 143.6981, 117.7547, 57.0671, 17.6226, 00154 /**/ 9.6331, 14.2935, 54.3899, 123.0147, 155.0713, 123.1237, 55.2159, 15.5765, 00155 /**/ 16.2662, 20.0273, 43.9895, 100.5702, 137.0377, 130.6205, 72.0922, 23.4612, 00156 /**/ 37.0922, 42.4549, 42.5031, 73.2998, 107.0084, 123.4990, 81.0252, 33.1572, 00157 /**/ 67.8616, 85.1195, 79.6813, 91.9078, 109.3711, 114.7254, 78.2264, 41.4004, 00158 /**/ 82.2935, 117.5304, 132.6981, 142.1950, 134.8784, 104.9979, 64.3585, 44.3711, 00159 /**/ 58.9078, 98.3270, 131.1069, 141.3396, 118.3229, 72.0210, 37.5241, 33.2096, 00160 /**/ 25.9644, 47.4948, 68.6771, 73.7233, 57.4067, 30.8574, 16.7421, 17.7945, 00161 /**/ 13.5556, 17.6918, 21.9057, 22.6604, 19.1279, 14.2872, 12.8616, 13.3627 00162 }; 00163 00164 const float digit4_data[] = 00165 { 00166 /**/ 14.2562, 14.5274, 14.8856, 14.8134, 15.0274, 15.1020, 15.2960, 15.7662, 00167 /**/ 7.1891, 7.3159, 7.8930, 8.4328, 9.7537, 10.9055, 9.6990, 8.7363, 00168 /**/ 7.8333, 7.0249, 9.7910, 21.0149, 35.1965, 38.0547, 23.0299, 10.7040, 00169 /**/ 10.0498, 8.3507, 16.4726, 47.6841, 78.9826, 78.3433, 41.3532, 13.4403, 00170 /**/ 10.6791, 13.5697, 37.4478, 81.3085, 104.2687, 83.5995, 36.8134, 11.6418, 00171 /**/ 10.9055, 24.7836, 68.5920, 111.2736, 106.6343, 64.2985, 21.1119, 9.1617, 00172 /**/ 18.5398, 47.0299, 97.0100, 125.8657, 107.7761, 65.4204, 23.2985, 11.7537, 00173 /**/ 34.8507, 75.0224, 119.3010, 131.6891, 118.3010, 87.2139, 41.0547, 17.9254, 00174 /**/ 63.1517, 115.0323, 152.2711, 153.4428, 136.6841, 101.4527, 49.2562, 19.9701, 00175 /**/ 90.4279, 155.9552, 195.9627, 194.1244, 162.0771, 106.2537, 44.4925, 18.3483, 00176 /**/ 80.0100, 132.6169, 176.6816, 190.1990, 165.8930, 100.8856, 37.7662, 19.4229, 00177 /**/ 48.8234, 64.8159, 98.7289, 131.3582, 135.5920, 83.8507, 33.0796, 22.4403, 00178 /**/ 25.6766, 20.9925, 35.5597, 63.3259, 80.5174, 53.1617, 23.4428, 17.5721, 00179 /**/ 11.4502, 7.5224, 10.7687, 21.6294, 30.9080, 21.8955, 12.2662, 10.1219, 00180 /**/ 8.0746, 7.7985, 8.5373, 10.5522, 11.9428, 9.8483, 8.6169, 8.2761 00181 }; 00182 00183 const float digit5_data[] = 00184 { 00185 /**/ 17.4672, 16.7822, 15.7743, 15.1916, 15.4908, 15.5696, 15.7480, 15.1391, 00186 /**/ 9.4672, 9.8478, 11.5643, 15.8976, 19.2966, 19.0184, 15.7664, 10.9160, 00187 /**/ 10.3701, 17.0630, 40.6430, 71.2362, 89.0052, 84.3832, 60.1732, 28.3491, 00188 /**/ 13.7349, 32.8950, 88.7690, 150.7113, 180.0210, 166.0525, 115.0157, 51.0236, 00189 /**/ 17.3438, 49.6535, 116.7874, 171.1260, 181.3780, 152.3701, 99.0341, 44.3727, 00190 /**/ 20.8793, 62.8609, 131.4462, 164.2677, 147.4541, 101.0630, 51.0446, 23.2415, 00191 /**/ 22.9239, 71.6719, 149.9265, 190.5328, 175.9843, 120.9081, 53.7087, 19.7848, 00192 /**/ 24.8084, 72.0157, 145.4357, 194.3596, 196.3360, 156.8976, 85.1365, 30.5144, 00193 /**/ 26.9160, 58.0210, 97.8766, 130.9764, 147.5328, 143.1260, 97.5538, 42.4121, 00194 /**/ 35.3570, 53.0289, 62.8136, 76.0262, 98.4803, 116.8793, 92.9370, 48.0420, 00195 /**/ 55.4226, 75.2336, 82.9055, 88.0551, 102.7664, 109.9449, 84.2021, 48.9003, 00196 /**/ 68.4672, 97.9633, 124.5879, 135.6824, 133.8005, 107.6562, 67.8268, 44.2861, 00197 /**/ 50.1417, 81.0262, 120.1076, 137.3360, 123.3963, 79.1286, 39.5486, 29.8766, 00198 /**/ 22.3806, 39.1549, 63.1969, 73.3596, 62.6299, 35.2441, 16.8661, 15.2073, 00199 /**/ 12.4698, 15.6903, 20.9528, 22.8871, 20.2257, 14.0761, 11.2730, 11.2362 00200 }; 00201 00202 const float digit6_data[] = 00203 { 00204 /**/ 19.6437, 20.1782, 20.9080, 21.6063, 22.3621, 23.2644, 22.9626, 22.6408, 00205 /**/ 11.6954, 11.0661, 11.8793, 17.6609, 28.8592, 35.5575, 27.6178, 17.3190, 00206 /**/ 12.2098, 10.0086, 13.8075, 33.5661, 62.2385, 73.3190, 48.8994, 21.6810, 00207 /**/ 13.9310, 11.4339, 24.4339, 63.2960, 99.4598, 97.0431, 54.8592, 20.4224, 00208 /**/ 14.1753, 17.0776, 47.1638, 97.0920, 120.7011, 92.6293, 42.0632, 15.1121, 00209 /**/ 13.5575, 31.7126, 89.7644, 145.1523, 145.9713, 91.5747, 32.3534, 13.1351, 00210 /**/ 18.3103, 56.2040, 137.7213, 196.5862, 186.7902, 117.4397, 41.3046, 16.6408, 00211 /**/ 34.0460, 84.3707, 155.3534, 196.4655, 190.1092, 138.9626, 65.0144, 26.4540, 00212 /**/ 55.0805, 101.1523, 133.8247, 145.9109, 146.0977, 132.4713, 82.8793, 38.5891, 00213 /**/ 72.6983, 106.6264, 105.1724, 99.1351, 104.9167, 115.5489, 85.0259, 43.7672, 00214 /**/ 88.6494, 116.5690, 106.1408, 96.0603, 101.2040, 107.3506, 78.1466, 41.9425, 00215 /**/ 91.5144, 124.5920, 136.3908, 135.2011, 126.2529, 98.6149, 58.2328, 34.8391, 00216 /**/ 67.4598, 104.3678, 136.8678, 144.4310, 121.8822, 73.0460, 33.8333, 25.8046, 00217 /**/ 31.5489, 52.0115, 72.9224, 77.9195, 62.7960, 35.2960, 17.5632, 16.3764, 00218 /**/ 14.8017, 17.8017, 21.5287, 22.2126, 19.3333, 15.2328, 13.2672, 13.8678 00219 }; 00220 00221 const float digit7_data[] = 00222 { 00223 /**/ 19.7602, 20.0585, 19.6111, 19.2836, 19.1901, 18.9035, 18.8977, 18.3947, 00224 /**/ 11.3655, 12.6462, 16.1959, 20.9269, 23.9620, 23.9298, 20.6520, 15.4591, 00225 /**/ 12.7047, 22.6842, 46.2690, 70.4971, 85.3860, 85.4561, 69.1754, 42.6023, 00226 /**/ 18.3918, 45.2602, 99.4298, 146.6930, 174.0409, 174.4591, 143.3684, 87.0175, 00227 /**/ 24.0146, 59.6491, 120.6520, 164.0439, 190.2719, 192.9064, 163.0614, 100.4327, 00228 /**/ 26.1257, 52.5585, 90.5702, 111.8918, 129.5643, 139.1959, 119.9269, 71.2661, 00229 /**/ 20.4298, 31.9678, 51.3801, 70.8275, 93.6462, 105.3538, 81.6199, 40.7135, 00230 /**/ 13.3509, 15.6842, 34.7105, 70.4474, 101.6404, 96.9649, 57.1491, 22.7749, 00231 /**/ 10.7982, 15.6462, 45.6813, 91.4737, 112.4298, 81.9912, 34.5906, 14.2602, 00232 /**/ 12.3538, 30.7544, 75.2047, 113.8860, 104.0205, 55.4064, 18.2895, 12.2632, 00233 /**/ 26.5497, 55.8450, 100.4883, 116.8889, 79.8830, 29.9971, 10.6023, 14.6520, 00234 /**/ 47.9532, 75.2222, 102.8480, 92.1959, 49.1579, 15.2982, 9.0234, 19.6257, 00235 /**/ 47.6462, 65.3860, 76.6608, 56.6667, 25.7018, 9.4211, 8.7661, 19.1228, 00236 /**/ 25.3041, 32.0234, 35.0029, 25.2953, 13.5994, 8.1725, 8.3304, 12.9064, 00237 /**/ 12.6345, 13.2047, 13.3392, 11.9035, 10.4094, 9.5380, 9.9971, 10.9357 00238 }; 00239 00240 const float digit8_data[] = 00241 { 00242 /**/ 15.9933, 16.0269, 16.0269, 15.5387, 15.2424, 15.3199, 15.9495, 16.5859, 00243 /**/ 8.9091, 8.7071, 9.5455, 12.2424, 15.7879, 16.1582, 13.2256, 10.4882, 00244 /**/ 8.9293, 8.7542, 17.9764, 41.7104, 63.5455, 63.6296, 41.9966, 16.6229, 00245 /**/ 12.0135, 15.2525, 43.3603, 99.4108, 143.5522, 142.8586, 97.9731, 36.4714, 00246 /**/ 16.3266, 31.1852, 77.6229, 140.3535, 183.2256, 182.2357, 134.8418, 57.8249, 00247 /**/ 18.8148, 48.7845, 109.1077, 164.7845, 192.8889, 184.6970, 136.3468, 62.1347, 00248 /**/ 17.8519, 57.0673, 133.9697, 199.4310, 219.4074, 193.2828, 123.8956, 50.1785, 00249 /**/ 22.9057, 68.8788, 148.1481, 210.1785, 220.6566, 187.0034, 107.3670, 40.0438, 00250 /**/ 40.8451, 89.4007, 141.0943, 170.5084, 177.0808, 159.5859, 101.4646, 44.4512, 00251 /**/ 59.0606, 101.5118, 124.3131, 127.0202, 138.8451, 142.9158, 107.3569, 54.9226, 00252 /**/ 70.7542, 107.3973, 128.5556, 133.2997, 148.2795, 143.8990, 104.8384, 54.2963, 00253 /**/ 73.5859, 111.7643, 151.3737, 173.0303, 176.6128, 139.5118, 82.6128, 40.7542, 00254 /**/ 52.8855, 87.4343, 133.5017, 159.4613, 150.0438, 100.1077, 47.2761, 25.0572, 00255 /**/ 23.6229, 40.9024, 65.8283, 78.2391, 69.6768, 42.7071, 19.6296, 14.1987, 00256 /**/ 12.0000, 14.9697, 19.3535, 21.1818, 19.4545, 14.7138, 11.8215, 11.9630 00257 }; 00258 00259 const float digit9_data[] = 00260 { 00261 /**/ 15.8852, 15.9519, 15.8407, 15.2185, 15.0259, 15.2667, 16.0259, 17.1630, 00262 /**/ 9.1815, 8.7333, 9.3222, 12.5519, 15.2963, 14.7778, 11.5741, 9.8741, 00263 /**/ 10.0037, 11.8778, 26.8370, 53.5593, 70.6148, 62.6259, 36.0889, 14.2926, 00264 /**/ 14.7630, 25.4037, 67.5667, 124.2667, 155.8000, 138.0704, 83.8926, 28.9185, 00265 /**/ 26.3741, 53.9185, 106.3556, 153.8889, 177.2296, 163.3556, 115.7296, 47.6444, 00266 /**/ 38.5370, 81.2148, 126.6630, 142.4370, 146.9667, 141.5333, 115.4778, 56.6815, 00267 /**/ 36.9593, 89.9778, 146.3963, 164.2074, 160.8926, 139.5889, 100.6037, 47.8889, 00268 /**/ 26.1667, 78.4593, 157.2778, 204.8444, 204.6000, 154.4963, 81.1444, 30.4074, 00269 /**/ 14.9593, 48.1000, 126.2037, 191.1778, 194.7630, 133.3852, 53.6667, 17.5407, 00270 /**/ 10.7481, 31.6667, 94.1741, 149.9593, 144.4148, 85.7852, 27.7296, 13.0296, 00271 /**/ 25.6556, 50.4259, 97.5630, 124.3593, 97.2296, 44.7000, 14.4407, 15.2222, 00272 /**/ 49.1370, 72.4481, 100.9667, 98.2259, 57.6963, 20.5296, 10.2704, 18.3037, 00273 /**/ 46.0000, 57.6000, 68.3074, 58.2037, 29.4037, 11.5852, 9.1296, 15.4037, 00274 /**/ 23.6185, 25.8148, 27.3444, 22.9593, 13.7889, 8.9630, 8.6481, 11.1444, 00275 /**/ 12.8667, 12.9556, 12.9370, 11.7741, 10.5407, 9.6148, 9.9852, 10.9630 00276 }; 00277 00278 struct racestats 00279 { 00280 racestats() : lag(0.0), position(0.0), n(0) {} 00281 00282 std::string info() const 00283 { 00284 return sformat("lag = %+.2f, position = %.2f, in %d frames", 00285 lag / n, 1.0 + position / n, n); 00286 } 00287 00288 double lag; 00289 double position; 00290 int n; 00291 }; 00292 } 00293 00294 int main(const int argc, const char** argv) 00295 { 00296 ModelManager manager("parse-need-for-speed"); 00297 00298 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00299 manager.addSubComponent(ifs); 00300 00301 if (manager.parseCommandLine(argc, argv, "dodisplay", 1, 1) == false) 00302 return 1; 00303 00304 manager.start(); 00305 00306 const Dims zoomdims(121,69); 00307 00308 const int rows[] = { 86, 104, 122, 140 }; 00309 const int cols[] = { 562, 554, 544, 536, 528 }; 00310 const Dims digitdims(8,15); 00311 const int ilabcol = 539; 00312 const Dims ilabdims(31,15); 00313 00314 const Image<float> ILAB(&ILAB_data[0], ilabdims); 00315 const Image<float> digits[10] = 00316 { 00317 Image<float>(&digit0_data[0], digitdims), 00318 Image<float>(&digit1_data[0], digitdims), 00319 Image<float>(&digit2_data[0], digitdims), 00320 Image<float>(&digit3_data[0], digitdims), 00321 Image<float>(&digit4_data[0], digitdims), 00322 Image<float>(&digit5_data[0], digitdims), 00323 Image<float>(&digit6_data[0], digitdims), 00324 Image<float>(&digit7_data[0], digitdims), 00325 Image<float>(&digit8_data[0], digitdims), 00326 Image<float>(&digit9_data[0], digitdims) 00327 }; 00328 00329 const bool dodisplay = manager.getExtraArgAs<bool>(0); 00330 00331 XWinManaged* fullwin = 0; 00332 XWinManaged* zoomwin = 0; 00333 00334 if (dodisplay) 00335 { 00336 fullwin = new XWinManaged(Dims(640,480), -1, -1, "full"); 00337 zoomwin = new XWinManaged(Dims(zoomdims.w() * 4, zoomdims.h() * 2), 00338 -1, -1, "zoom"); 00339 } 00340 00341 const double ilabthresh = 0.75; 00342 00343 const double confthresh = 0.84; 00344 00345 std::vector<racestats> stats; 00346 00347 int ngap = 0; 00348 00349 ifs->startStream(); 00350 00351 while (true) 00352 { 00353 ifs->updateNext(); 00354 00355 const Image<PixRGB<byte> > rgb = ifs->readRGB(); 00356 if (!rgb.initialized()) 00357 { 00358 LINFO("input exhausted; quitting"); 00359 break; 00360 } 00361 00362 const Image<float> im = luminance(Image<PixRGB<float> >(rgb)); 00363 00364 const Image<PixRGB<byte> > im2 = crop(rgb, Point2D<int>(453, 86), zoomdims); 00365 00366 Image<PixRGB<byte> > guesses(im2.getDims() * 2, ZEROS); 00367 const PixRGB<byte> confcol(255, 255, 0); 00368 const PixRGB<byte> shakycol(128, 128, 128); 00369 const PixRGB<byte> bgcol(0, 0, 0); 00370 00371 std::string labels[4]; 00372 double lags[4]; 00373 int position = -1; 00374 00375 double worstcorr = 1.0; 00376 00377 bool seenilab = false; 00378 00379 for (int row = 0; row < 4; ++row) 00380 { 00381 const Image<float> ilabpatch = crop(im, Point2D<int>(ilabcol, rows[row]), 00382 ilabdims); 00383 00384 const double ilabcorr = sqrt(corrcoef(ILAB, ilabpatch)); 00385 00386 if (ilabcorr > ilabthresh) 00387 { 00388 labels[row] = sformat("ilab (ilabcorr=%.4f)", ilabcorr); 00389 lags[row] = 0.0; 00390 00391 if (dodisplay) 00392 { 00393 writeText(guesses, Point2D<int>(1, 6+row*36), 00394 sformat("ILAB (conf=%.4f)", ilabcorr).c_str(), 00395 ilabcorr >= confthresh ? confcol : shakycol, bgcol); 00396 } 00397 00398 if (ilabcorr < worstcorr) 00399 worstcorr = ilabcorr; 00400 00401 seenilab = true; 00402 position = row; 00403 } 00404 else 00405 { 00406 double val = 0; 00407 00408 double totalcorr = 0.0; 00409 00410 for (int col = 4; col >= 0; --col) 00411 { 00412 const Image<float> patch = crop(im, Point2D<int>(cols[col], rows[row]), 00413 digitdims); 00414 00415 const double patchmean = mean(patch); 00416 00417 double maxcorr = -1.0; 00418 int bestdigit = -1; 00419 00420 if (patchmean < 25.0) 00421 LINFO("row %d, col %d patch mean = %.4f", row, col, patchmean); 00422 else 00423 for (int d = 0; d <= 9; ++d) 00424 { 00425 const double c = sqrt(corrcoef(patch, digits[d])); 00426 if (c > maxcorr) 00427 { 00428 maxcorr = c; 00429 bestdigit = d; 00430 } 00431 } 00432 00433 int guessdigit = bestdigit; 00434 00435 if (maxcorr < 0.7) 00436 guessdigit = 0; 00437 00438 for (int p = 0; p < col; ++p) 00439 guessdigit *= 10; 00440 00441 val = val + guessdigit; 00442 00443 if (col <= 2) 00444 totalcorr += maxcorr; 00445 } 00446 00447 totalcorr /= 3.0; 00448 00449 val /= 100.0; 00450 00451 if (!seenilab) 00452 val *= -1.0; 00453 00454 labels[row] = sformat("%+.2f (ilabcorr=%.4f, 3corr=%.4f)", 00455 val, ilabcorr, totalcorr); 00456 lags[row] = val; 00457 00458 if (dodisplay) 00459 writeText(guesses, Point2D<int>(1, 6+row*36), 00460 sformat("%+.2f (conf=%.4f)", 00461 val, totalcorr).c_str(), 00462 totalcorr >= confthresh ? confcol : shakycol, bgcol); 00463 00464 if (totalcorr < worstcorr) 00465 worstcorr = totalcorr; 00466 } 00467 } 00468 00469 if (dodisplay) 00470 { 00471 fullwin->drawImage(rgb, 0, 0); 00472 Image<PixRGB<byte> > zoomimg = 00473 concatX(intXY(im2, true), guesses); 00474 00475 writeText(zoomimg, Point2D<int>(1,1), 00476 sformat("%06d", ifs->frame()).c_str(), 00477 PixRGB<byte>(0,255,255), PixRGB<byte>(0,0,0), 00478 SimpleFont::FIXED(6), true); 00479 zoomwin->drawImage(zoomimg, 0, 0); 00480 00481 std::cout << sformat("frame %06d", ifs->frame()) << ":\n"; 00482 00483 for (int l = 0; l < 4; ++l) 00484 std::cout << sformat("\t%s", labels[l].c_str()) 00485 << std::endl; 00486 00487 if (worstcorr < confthresh) 00488 std::cout << sformat("\tTRASHY!!! worst corr = %.4f", worstcorr) 00489 << std::endl; 00490 else 00491 std::cout << sformat("\tworst corr = %.4f", worstcorr) 00492 << std::endl; 00493 } 00494 00495 if (worstcorr >= confthresh) 00496 { 00497 const double currentlag = 00498 (lags[0] + lags[1] + lags[2] + lags[3]) / 4.0; 00499 00500 if (ngap > 40 || stats.size() == 0) 00501 stats.push_back(racestats()); 00502 00503 stats.back().lag += currentlag; 00504 stats.back().position += position; 00505 stats.back().n++; 00506 00507 std::cout << sformat("%6d %+8.2f %3d %% worstcorr = %.2f stats[%"ZU"]: %s (gap=%d)\n", 00508 ifs->frame(), currentlag, position, worstcorr, 00509 stats.size(), 00510 stats.back().info().c_str(), ngap); 00511 00512 ngap = 0; 00513 } 00514 else 00515 { 00516 std::cout << sformat("%6d %8s %3s %% worstcorr = %.2f\n", 00517 ifs->frame(), "NaN", "NaN", worstcorr); 00518 ++ngap; 00519 } 00520 00521 } 00522 } 00523 00524 // ###################################################################### 00525 /* So things look consistent in everyone's emacs... */ 00526 /* Local Variables: */ 00527 /* mode: c++ */ 00528 /* indent-tabs-mode: nil */ 00529 /* End: */ 00530 00531 #endif // APPMEDIA_APP_PARSE_NEED_FOR_SPEED_C_DEFINED