|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Python 2/3 compatibility |
| 4 | +from __future__ import print_function |
| 5 | + |
| 6 | +import os, numpy |
| 7 | + |
| 8 | +import cv2 as cv |
| 9 | + |
| 10 | +from tests_common import NewOpenCVTests |
| 11 | + |
| 12 | +class structured_light_test(NewOpenCVTests): |
| 13 | + |
| 14 | + def test_unwrap(self): |
| 15 | + paramsPsp = cv.structured_light_SinusoidalPattern_Params(); |
| 16 | + paramsFtp = cv.structured_light_SinusoidalPattern_Params(); |
| 17 | + paramsFaps = cv.structured_light_SinusoidalPattern_Params(); |
| 18 | + paramsPsp.methodId = cv.structured_light.PSP; |
| 19 | + paramsFtp.methodId = cv.structured_light.FTP; |
| 20 | + paramsFaps.methodId = cv.structured_light.FAPS; |
| 21 | + |
| 22 | + sinusPsp = cv.structured_light.SinusoidalPattern_create(paramsPsp) |
| 23 | + sinusFtp = cv.structured_light.SinusoidalPattern_create(paramsFtp) |
| 24 | + sinusFaps = cv.structured_light.SinusoidalPattern_create(paramsFaps) |
| 25 | + |
| 26 | + captures = [] |
| 27 | + for i in range(0,3): |
| 28 | + capture = self.get_sample('/cv/structured_light/data/capture_sin_%d.jpg'%i, cv.IMREAD_GRAYSCALE) |
| 29 | + if capture is None: |
| 30 | + raise unittest.SkipTest("Missing files with test data") |
| 31 | + captures.append(capture) |
| 32 | + |
| 33 | + rows,cols = captures[0].shape |
| 34 | + |
| 35 | + unwrappedPhaseMapPspRef = self.get_sample('/cv/structured_light/data/unwrappedPspTest.jpg', |
| 36 | + cv.IMREAD_GRAYSCALE) |
| 37 | + unwrappedPhaseMapFtpRef = self.get_sample('/cv/structured_light/data/unwrappedFtpTest.jpg', |
| 38 | + cv.IMREAD_GRAYSCALE) |
| 39 | + unwrappedPhaseMapFapsRef = self.get_sample('/cv/structured_light/data/unwrappedFapsTest.jpg', |
| 40 | + cv.IMREAD_GRAYSCALE) |
| 41 | + |
| 42 | + wrappedPhaseMap,shadowMask = sinusPsp.computePhaseMap(captures); |
| 43 | + unwrappedPhaseMap = sinusPsp.unwrapPhaseMap(wrappedPhaseMap, (cols, rows), shadowMask=shadowMask) |
| 44 | + unwrappedPhaseMap8 = unwrappedPhaseMap*1 + 128 |
| 45 | + unwrappedPhaseMap8 = numpy.uint8(unwrappedPhaseMap8) |
| 46 | + |
| 47 | + sumOfDiff = 0 |
| 48 | + count = 0 |
| 49 | + for i in range(rows): |
| 50 | + for j in range(cols): |
| 51 | + ref = int(unwrappedPhaseMapPspRef[i, j]) |
| 52 | + comp = int(unwrappedPhaseMap8[i, j]) |
| 53 | + sumOfDiff += (ref - comp) |
| 54 | + count += 1 |
| 55 | + |
| 56 | + ratio = sumOfDiff/float(count) |
| 57 | + self.assertLessEqual(ratio, 0.2) |
| 58 | + |
| 59 | + wrappedPhaseMap,shadowMask = sinusFtp.computePhaseMap(captures); |
| 60 | + unwrappedPhaseMap = sinusFtp.unwrapPhaseMap(wrappedPhaseMap, (cols, rows), shadowMask=shadowMask) |
| 61 | + unwrappedPhaseMap8 = unwrappedPhaseMap*1 + 128 |
| 62 | + unwrappedPhaseMap8 = numpy.uint8(unwrappedPhaseMap8) |
| 63 | + |
| 64 | + sumOfDiff = 0 |
| 65 | + count = 0 |
| 66 | + for i in range(rows): |
| 67 | + for j in range(cols): |
| 68 | + ref = int(unwrappedPhaseMapFtpRef[i, j]) |
| 69 | + comp = int(unwrappedPhaseMap8[i, j]) |
| 70 | + sumOfDiff += (ref - comp) |
| 71 | + count += 1 |
| 72 | + |
| 73 | + ratio = sumOfDiff/float(count) |
| 74 | + self.assertLessEqual(ratio, 0.2) |
| 75 | + |
| 76 | + wrappedPhaseMap,shadowMask2 = sinusFaps.computePhaseMap(captures); |
| 77 | + unwrappedPhaseMap = sinusFaps.unwrapPhaseMap(wrappedPhaseMap, (cols, rows), shadowMask=shadowMask) |
| 78 | + unwrappedPhaseMap8 = unwrappedPhaseMap*1 + 128 |
| 79 | + unwrappedPhaseMap8 = numpy.uint8(unwrappedPhaseMap8) |
| 80 | + |
| 81 | + sumOfDiff = 0 |
| 82 | + count = 0 |
| 83 | + for i in range(rows): |
| 84 | + for j in range(cols): |
| 85 | + ref = int(unwrappedPhaseMapFapsRef[i, j]) |
| 86 | + comp = int(unwrappedPhaseMap8[i, j]) |
| 87 | + sumOfDiff += (ref - comp) |
| 88 | + count += 1 |
| 89 | + |
| 90 | + ratio = sumOfDiff/float(count) |
| 91 | + self.assertLessEqual(ratio, 0.2) |
| 92 | + |
| 93 | +if __name__ == '__main__': |
| 94 | + NewOpenCVTests.bootstrap() |
0 commit comments