blob: 5083572214831a58093991ef57c541fca64b5089 [file] [log] [blame]
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for FingerDetector."""
import numpy as np
from optofidelity.detection import Trace
from optofidelity.detection._finger_detector import FingerDetector
from optofidelity.detection.events import FingerEvent
from optofidelity.util import nputil
from .test_detector import DetectorTest
sample_preprocessed_data = [
(286.1778,0.7284), (285.4823,0.7293), (285.5310,0.7159), (286.3694,0.7077),
(286.7331,0.7228), (286.5953,0.7349), (286.2269,0.7309), (286.3460,0.7110),
(286.9374,0.7053), (287.1429,0.7411), (286.9698,0.7347), (286.4139,0.7292),
(286.5790,0.7076), (287.5208,0.7100), (287.5392,0.7507), (287.0833,0.7312),
(286.8409,0.7142), (287.3004,0.7023), (288.0400,0.7037), (287.5226,0.7330),
(286.7452,0.7299), (287.1664,0.7035), (287.3409,0.6998), (288.0744,0.7073),
(287.4070,0.7260), (286.5412,0.7323), (286.8412,0.7042), (287.3561,0.7009),
(287.6319,0.7211), (286.9028,0.7324), (286.3191,0.7293), (286.3946,0.6988),
(286.9683,0.6980), (286.7648,0.7406), (286.1185,0.7318), (286.2881,0.7296),
(286.3157,0.7038), (286.8863,0.7039), (286.5052,0.7474), (285.9408,0.7310),
(285.5293,0.7058), (285.5585,0.7004), (286.2796,0.7044), (285.6877,0.7367),
(285.4274,0.7332), (285.4072,0.6956), (285.5177,0.6668), (286.2473,0.6507),
(285.6110,0.6494), (285.0155,0.6370), (285.6662,0.6009), (286.0740,0.5633),
(286.7667,0.5661), (285.9357,0.5374), (285.8135,0.5142), (287.4686,0.4671),
(287.4612,0.4296), (287.7477,0.4709), (286.8561,0.4114), (286.8304,0.3685),
(291.9507,0.3427), (289.7832,0.3135), (288.6987,0.3621), (285.5731,0.2986),
(292.2068,0.2376), (289.5270,0.2376), (273.4036,0.2283), (277.1338,0.2440),
(279.3160,0.2260), (286.1212,0.1784), (265.5403,0.1597), (266.7439,0.2106),
(249.9811,0.1719), (273.0901,0.1637), (224.5335,0.1222), (204.3151,0.1270),
(261.0832,0.2120), (190.1529,0.1417), (209.1250,0.1212), (225.5012,0.1219),
(203.8313,0.1343), (253.4992,0.2123), (197.6477,0.1340), (228.4833,0.1230),
(214.4141,0.1223), (234.8571,0.1480), (216.3145,0.1850), (194.2070,0.1318),
(241.9500,0.1167), (210.4902,0.1184), (263.0908,0.1956), (186.1525,0.1488),
(215.6369,0.1374), (239.3957,0.1139), (203.7780,0.1140), (261.3628,0.2177),
(188.8001,0.1445), (204.2077,0.1288), (211.9863,0.1105), (199.9374,0.1139),
(276.5257,0.2335), (191.3367,0.1460), (247.1812,0.1263), (212.1005,0.1135),
(199.2108,0.1122), (257.7888,0.2151), (195.0750,0.1534), (267.0337,0.1239),
(221.2128,0.1113), (240.5383,0.1549), (252.7400,0.1822), (199.5616,0.1511),
(285.0712,0.1207), (206.4451,0.1045), (264.6504,0.1905), (191.8754,0.1453),
(274.0288,0.1487), (264.5153,0.1160), (197.7316,0.1056), (269.5307,0.2228),
(197.2858,0.1445), (291.2755,0.1484), (249.5192,0.1159), (195.7558,0.0999),
(267.4449,0.2241), (198.0466,0.1408), (290.2158,0.1410), (232.1980,0.1132),
(194.2326,0.1029), (266.9806,0.2056), (203.7863,0.1394), (284.7081,0.1405),
(221.7414,0.1120), (237.3828,0.1496), (217.2325,0.1617), (207.9731,0.1414),
(280.3204,0.1422), (200.3454,0.1000), (243.4801,0.1799), (192.6192,0.1382),
(210.2645,0.1364), (213.7097,0.1369), (182.1537,0.1005), (256.1130,0.2082),
(197.5081,0.1335), (237.1677,0.1360), (210.3742,0.1331), (180.0293,0.1079),
(250.1990,0.2055), (198.7747,0.1384), (258.2063,0.1309), (213.6983,0.1353),
(180.6554,0.1089), (251.3242,0.1878), (207.0451,0.1417), (279.4244,0.1313),
(219.3553,0.1312), (202.0071,0.1574), (179.0222,0.1407), (218.8470,0.1381),
(273.6096,0.1274), (203.5757,0.1196), (259.5796,0.1872), (181.4827,0.1344),
(209.4065,0.1302), (218.0798,0.1237), (202.0941,0.1258), (259.9692,0.2073),
(189.4832,0.1351), (212.4306,0.1229), (220.6757,0.1225), (204.7680,0.1305),
(254.2442,0.2033), (197.4854,0.1392), (254.9679,0.1201), (218.7932,0.1244),
(251.9655,0.1606), (206.8583,0.1827), (194.2330,0.1373), (227.7380,0.1152),
(206.4133,0.1129), (266.3891,0.1983), (186.6405,0.1505), (231.8705,0.1419),
(213.2811,0.1110), (202.4525,0.1167), (266.9100,0.2239), (189.7839,0.1475),
(204.3150,0.1239), (215.8320,0.1058), (200.0448,0.1139), (277.8595,0.2368),
(266.2547,0.1270), (211.0323,0.1299), (203.1894,0.1600), (253.7940,0.1844),
(267.6766,0.1774), (288.9629,0.1498), (263.7043,0.1607), (263.8891,0.2267),
(274.3339,0.2204), (284.4769,0.2351), (292.9549,0.2172), (284.8095,0.2312),
(290.6727,0.3225), (287.0848,0.2911), (290.0335,0.3018), (291.7914,0.3047),
(291.1113,0.3259), (289.1098,0.4216), (287.6568,0.3915), (286.8991,0.3788),
(287.4484,0.4098), (288.3384,0.4346), (287.6027,0.5080), (286.2311,0.4964),
(286.1115,0.4823), (286.5078,0.5089), (287.3733,0.5267), (286.6022,0.5688),
(285.5604,0.5851), (285.9894,0.5881), (286.3863,0.5977), (286.7332,0.6289),
(286.0826,0.6498), (285.4335,0.6648), (285.5438,0.6611), (286.0493,0.6787),
(286.1926,0.7297), (285.9632,0.7361), (285.3793,0.7421), (285.5228,0.7195),
(286.1714,0.7181), (286.4507,0.7613), (286.0282,0.7445), (285.5081,0.7260),
(286.2617,0.7072), (287.0443,0.7102), (286.5448,0.7362), (285.7607,0.7347),
(286.2349,0.7116), (286.4282,0.7057), (287.1634,0.7138), (286.5383,0.7364),
(285.9917,0.7379), (286.3172,0.7159), (286.5882,0.7091), (287.1422,0.7347),
(286.4855,0.7348), (286.3211,0.7124), (286.5822,0.6727), (287.1361,0.6783),
(287.2338,0.7291), (286.6815,0.7107), (286.6034,0.6764), (286.6694,0.6746),
(287.2847,0.6820), (287.1467,0.7084), (286.3739,0.7021), (286.2981,0.6716),
(286.5895,0.6661), (287.3352,0.6942), (287.0086,0.6994), (286.1676,0.6991),
(286.2571,0.6878), (286.5979,0.6692), (286.9198,0.7108), (286.2457,0.7039),
(285.9472,0.6946), (286.1681,0.6890), (286.2532,0.6756), (286.4317,0.7295),
(285.7657,0.6954), (285.8782,0.6700), (286.0909,0.6835), (286.5309,0.6710),
(286.2227,0.7135), (285.3862,0.7028), (285.2308,0.6620), (285.6433,0.6855),
(286.5918,0.6799), (286.0919,0.6986), (285.2580,0.6962), (285.1875,0.6759),
(285.9056,0.6797), (286.4144,0.6967), (285.7634,0.6965), (284.8757,0.6976),
(285.2734,0.6808), (285.9783,0.6837), (286.3737,0.7150), (285.4091,0.7040),
(285.1866,0.6882), (285.3601,0.6825), (286.1223,0.6877), (286.3739,0.7335),
(285.6884,0.6915), (285.5743,0.6599), (286.1004,0.6663), (286.6615,0.6618),
(286.5005,0.6704), (286.3217,0.6461), (286.1876,0.5868), (286.6803,0.5860),
(287.8504,0.5854), (287.4065,0.5807), (286.8881,0.5636), (286.9236,0.5205),
(287.3634,0.4980), (288.3368,0.5319), (287.8541,0.4930), (287.2652,0.4758),
(288.1096,0.4291), (288.7487,0.4146), (289.3233,0.4886), (288.3537,0.4148),
(288.5265,0.3647), (290.3139,0.3370), (289.7415,0.3212), (290.0688,0.3954),
(286.9768,0.3258), (287.4541,0.2350), (291.2583,0.2468), (275.1396,0.2311),
(278.0460,0.2715), (267.0072,0.2497), (283.1824,0.1839), (270.0196,0.1729),
(274.4582,0.2356), (255.6562,0.1983), (259.6610,0.1892), (287.0470,0.1375),
(204.4526,0.1243), (269.9945,0.2494), (194.1423,0.1569), (277.2609,0.1630),
(224.3735,0.1318), (195.7577,0.1138), (266.9542,0.2402), (194.8483,0.1553),
(286.2105,0.1652), (231.0548,0.1318), (196.5004,0.1149), (248.2409,0.2060),
(196.7104,0.1497), (283.5185,0.1580), (226.9556,0.1288), (233.4960,0.1395),
(223.5203,0.1861), (200.7455,0.1472), (285.6509,0.1581), (205.9949,0.1249),
(244.4662,0.1940), (185.3354,0.1517), (213.0832,0.1458), (279.9172,0.1503),
(182.6313,0.1154), (248.4805,0.2206), (188.7560,0.1455), (245.3817,0.1490),
(245.0172,0.1554), (180.9275,0.1183), (245.0738,0.2231), (195.1868,0.1459),
(260.2165,0.1538), (240.4963,0.1572), (179.5176,0.1186), (232.3028,0.1904),
(194.7332,0.1459), (276.6096,0.1471), (220.2679,0.1496), (200.9006,0.1677),
(186.7713,0.1583), (201.3285,0.1357), (283.8556,0.1457), (205.0472,0.1398),
(258.3170,0.2113), (180.1830,0.1436), (208.5502,0.1381), (236.1691,0.1389),
(199.6895,0.1398), (253.1601,0.2226), (184.1786,0.1362), (205.3448,0.1345),
(232.2037,0.1405), (199.1461,0.1455), (242.2786,0.2083), (189.8548,0.1382),
(244.4908,0.1358), (248.7491,0.1460), (211.9662,0.1608), (189.8812,0.1846),
(273.6728,0.1456), (224.6837,0.1432), (228.4550,0.1919), (176.1841,0.1416),
(211.5204,0.1377), (269.2862,0.1403), (201.1557,0.1390), (256.3334,0.2205),
(184.5222,0.1361), (224.9424,0.1378), (212.7257,0.1404), (204.1002,0.1466),
(247.4374,0.2173), (187.9537,0.1381), (231.1537,0.1371), (225.0803,0.1419),
(201.8238,0.1479), (199.2961,0.1826), (193.8933,0.1386), (245.7953,0.1325),
(225.1454,0.1364), (254.5538,0.1986), (184.1645,0.1613), (198.3494,0.1398),
(262.2971,0.1331), (203.2847,0.1240), (270.1623,0.2376), (186.3280,0.1526),
(208.1304,0.1362), (214.4773,0.1261), (199.3009,0.1285), (265.5420,0.2468),
(189.3545,0.1441), (256.4001,0.1482), (218.1777,0.1276), (199.1906,0.1321),
(253.2649,0.2059), (194.7758,0.1573), (270.2534,0.1360), (222.2415,0.1264),
(223.0311,0.1518), (238.5122,0.1951), (197.3280,0.1484), (282.9274,0.1377),
(201.5319,0.1215), (253.7069,0.2055), (184.6179,0.1595), (208.7502,0.1564),
(286.7505,0.1327), (198.8719,0.1128), (270.7023,0.2457), (190.9778,0.1604),
(286.0060,0.1617), (283.7869,0.1344), (249.5459,0.1471), (276.6227,0.2830),
(270.3047,0.2107), (289.0054,0.1660), (276.2396,0.2011), (269.7996,0.2203),
(277.1999,0.2988), (280.5667,0.2838), (296.8464,0.2477), (290.6133,0.2840),
(290.9530,0.3193), (289.0109,0.3614), (286.9089,0.3758), (288.6318,0.3794),
(288.4781,0.3931), (289.0758,0.4595), (287.7180,0.4719), (287.2245,0.4946),
(288.0143,0.5011), (287.4336,0.5207), (288.0403,0.6015), (287.0657,0.5941),
(286.5431,0.5887), (286.8825,0.6061), (287.1752,0.6131), (287.2634,0.6939),
(286.3288,0.6851), (286.1829,0.6708), (286.6380,0.6815), (287.2088,0.6772),
(287.0735,0.6975), (286.2728,0.6959), (286.1199,0.6664), (286.5168,0.6775),
(287.3200,0.6915), (286.7058,0.6978), (285.8233,0.6990), (286.1821,0.6804),
(286.2291,0.6794), (287.2873,0.7067), (286.2880,0.6961), (285.9706,0.6879),
(286.1501,0.6740), (286.2659,0.6806), (286.5445,0.7202), (286.1397,0.6956),
(285.9661,0.6680), (286.1411,0.6762), (286.6345,0.6814), (286.4603,0.7145),
(285.8144,0.6970), (285.9487,0.6597), (286.0677,0.6735), (286.7639,0.6922),
(286.3397,0.6985), (285.7474,0.6936), (285.6202,0.6712), (285.9740,0.6726),
]
class FingerDetectorTest(DetectorTest):
def testPreprocessing(self):
frame = self.calibratedFrame("finger.png")
location, confidence = FingerDetector().Preprocess(frame, None)
delta = np.abs(location - 33.5)
self.assertLess(delta, 1)
def testSampleEventGeneration(self):
trace = Trace(FingerDetector().GenerateEvents(sample_preprocessed_data))
location = trace.finger
smoothed = nputil.LowPass(location, 9)
roughness = smoothed - location
self.assertLess(np.max(np.abs(roughness)), 10)