diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..0c4e12d3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,79 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Binaries
+*.npz
+
+# PyCharm
+.idea/
+CMakeLists.txt
+
+# Other
+*.mtl
+*.obj
+!transdec.obj
+
+*.dic
+pedometry.txt
+.DS_STORE
+# Autosave files from QtCreator
+*.autosave
+*~
+
+# Vim swaps
+*.swp
diff --git a/drivers/mil_passive_sonar/CMakeLists.txt b/drivers/mil_passive_sonar/CMakeLists.txt
new file mode 100644
index 00000000..94c4818b
--- /dev/null
+++ b/drivers/mil_passive_sonar/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.3)
+project(mil_passive_sonar)
+
+find_package(catkin REQUIRED COMPONENTS
+ rospy
+)
+
+catkin_python_setup()
+
+catkin_package(
+# INCLUDE_DIRS include
+# LIBRARIES sub8_sonar
+# CATKIN_DEPENDS rospy
+# DEPENDS system_lib
+)
+
+include_directories(
+ ${catkin_INCLUDE_DIRS}
+)
diff --git a/drivers/mil_passive_sonar/README.md b/drivers/mil_passive_sonar/README.md
new file mode 100644
index 00000000..9fc82f1d
--- /dev/null
+++ b/drivers/mil_passive_sonar/README.md
@@ -0,0 +1,24 @@
+# Sonar Driver
+
+This script interfaces with Jake's sonar board and provides a ROS service that returns the location and time of emission of the last heard pinger pulse.
+
+## How to run and use
+To start the driver, run:
+
+ rosrun mil_passive_sonar sonar.launch
+
+> Note: make sure that port, and baud rate, and hydrophone locations are loaded into the parameter server. See launch/test.launch for an example.
+
+In order to ask for hydrophone information:
+
+ rosservice call /sonar/get_pinger_pulse *double_tab*
+
+The service should respond with the x, y, and z of the last heard pinger
+pulse. Remember that this should be considered the tip of an arrow
+pointing in the direction of the pinger, the range is completely unreliable
+and varies wildly.
+
+## TODO
++ This package is not yet fully set up to use the paulbaurd. The interface to make this happen would be simple to implement.
++ This package should estimate the least squares solution for the actual 3d position of the pinger.
++ Visualize both individual heading veactors and the LS position estimate.
diff --git a/drivers/mil_passive_sonar/launch/test.launch b/drivers/mil_passive_sonar/launch/test.launch
new file mode 100644
index 00000000..206be6b9
--- /dev/null
+++ b/drivers/mil_passive_sonar/launch/test.launch
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+ { hydro0: {x: 0, y: 0, z: 0},
+ hydro1: {x: 0, y: 25.4, z: 0},
+ hydro2: {x: -22, y: -12.7, z: 0},
+ hydro3: {x: 22, y: -12.7, z: 0}}
+
+
+
diff --git a/drivers/mil_passive_sonar/mil_passive_sonar/__init__.py b/drivers/mil_passive_sonar/mil_passive_sonar/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/drivers/mil_passive_sonar/mil_passive_sonar/sonar_driver.py b/drivers/mil_passive_sonar/mil_passive_sonar/sonar_driver.py
new file mode 100755
index 00000000..ddfb3f6a
--- /dev/null
+++ b/drivers/mil_passive_sonar/mil_passive_sonar/sonar_driver.py
@@ -0,0 +1,305 @@
+#!/usr/bin/python
+from __future__ import division
+import numpy as np
+import numpy.linalg as la
+from scipy.signal import resample, periodogram
+
+from itertools import product
+
+import rospy
+import rosparam
+
+from sub8_msgs.srv import Sonar, SonarResponse
+from sub8_ros_tools import thread_lock, make_header
+from sub8_alarm import AlarmBroadcaster
+from multilateration import Multilaterator
+
+import threading
+import serial
+import binascii
+import struct
+import time
+import crc16
+import sys
+
+# temp
+import matplotlib
+matplotlib.use("WX")
+import matplotlib.patches as mpatches
+import matplotlib.pyplot as plt
+fig = plt.figure(0)
+fig2 =plt.figure(1)
+plt.ion()
+plt.show()
+
+lock = threading.Lock()
+
+
+class Sub8Sonar():
+ '''
+ Smart sensor that provides high level ROS code with the location of pinger pulses detected with
+ Jake Easterling's Hydrophone board.
+
+ TODO: Add a function to try and reconnect to the serial port if we lose connection.
+ TODO: Express pulse location in map frame
+ '''
+ def __init__(self, method, c, hydrophone_locations, port, baud=19200):
+ rospy.init_node("sonar")
+
+ alarm_broadcaster = AlarmBroadcaster()
+ self.disconnection_alarm = alarm_broadcaster.add_alarm(
+ name='sonar_disconnect',
+ action_required=True,
+ severity=0
+ )
+ self.packet_error_alarm = alarm_broadcaster.add_alarm(
+ name='sonar_packet_error',
+ action_required=False,
+ severity=2
+ )
+
+ try:
+ self.ser = serial.Serial(port=port, baudrate=baud, timeout=None)
+ self.ser.flushInput()
+ except Exception, e:
+ print "\x1b[31mSonar serial connection error:\n\t", e, "\x1b[0m"
+ return None
+
+ self.c = c
+ self.hydrophone_locations = []
+ for key in hydrophone_locations:
+ sensor_location = np.array([hydrophone_locations[key]['x'], hydrophone_locations[key]['y'], hydrophone_locations[key]['z']])
+ self.hydrophone_locations += [sensor_location]
+ self.multilaterator = Multilaterator(hydrophone_locations, self.c, method) # speed of sound in m/s
+ self.est_signal_freq_kHz = 0
+ self._freq_sum = 0
+ self._freq_samples = 0
+
+ rospy.Service('~/sonar/get_pinger_pulse', Sonar, self.get_pulse_from_raw_data)
+ print "\x1b[32mSub8 sonar driver initialized\x1b[0m"
+ rospy.spin()
+
+ @thread_lock(lock)
+ def get_pulse_from_timestamps(self, srv):
+ self.ser.flushInput()
+
+ try:
+ self.ser.write('A')
+ print "Sent timestamp request..."
+ except: # Except only serial errors in the future.
+ self.disconnection_alarm.raise_alarm(
+ problem_description="Sonar board serial connection has been terminated."
+ )
+ return False
+ return self.multilaterator.getPulseLocation(self.timestamp_listener())
+
+ def timestamp_listener(self):
+ '''
+ Parse the response of the board.
+ '''
+ print "Listening..."
+
+ # We've found a packet now disect it.
+ response = self.ser.read(19)
+ # rospy.loginfo("Received: %s" % response) #uncomment for debugging
+ if self.check_CRC(response):
+ delete_last_lines(0) # Heard response!
+ # The checksum matches the data so split the response into each piece of data.
+ # For info on what these letters mean: https://docs.python.org/2/library/struct.html#format-characters
+ data = struct.unpack('>BffffH', response)
+ timestamps = [data[4], data[1], data[2], data[3] ]
+ print "timestamps:", timestamps
+ return timestamps
+ else:
+ self.packet_error_alarm.raise_alarm(
+ problem_description="Sonar board checksum error.",
+ parameters={
+ 'fault_info': {'data': response}
+ }
+ )
+ return None
+
+ @thread_lock(lock)
+ def get_pulse_from_raw_data(self, srv):
+ # request signals from hydrophone board
+ self.ser.flushInput()
+ try:
+ self.ser.write('B')
+ print "Sent raw data request..."
+ except: # Except only serial errors in the future.
+ self.disconnection_alarm.raise_alarm(
+ problem_description="Sonar board serial connection has been terminated."
+ )
+ return False
+ return self.multilaterator.getPulseLocation(self.raw_data_listener())
+
+ def raw_data_listener(self):
+ '''
+ Parse the response of the board.
+ '''
+ print "Listening..."
+
+ # prepare arrays for storing signals
+ signal_bias = 32767
+ waves_recorded = 3
+ samples_per_wave = 17.24
+ upsample_scale = 3
+ exp_recording_size = np.floor(samples_per_wave) * waves_recorded * upsample_scale - 1
+ raw_signals = np.zeros([4, exp_recording_size], dtype=float)
+
+ try:
+ # read in start bit of packet
+ timeout = 0
+ start_bit = self.ser.read(1)
+ # If start bit not read, keep trying
+ while start_bit != '\xBB':
+ start_bit = self.ser.read(1)
+ timeout += 1
+ if timeout > 600:
+ raise BufferError("Timeout: failed to read a start bit from sonar board")
+ for elem in np.nditer(raw_signals, op_flags=['readwrite']):
+ elem[...] = float(self.ser.read(5)) - signal_bias # ... is idx to current elem
+ except BufferError as e:
+ print e
+
+ non_zero_end_idx = 57
+ up_factor = 8
+ sampling_freq = 430E3 * 0.8 # Hz
+ samp_period = 1E6 / sampling_freq # microseconds
+ upsamp_step = samp_period / up_factor
+
+ # Set how much of each signal to actually use for processing
+ raw_signals = raw_signals[:, 0:non_zero_end_idx]
+
+ # upsample the signals for successful cross-correlation
+ upsampled_signals = [resample(x, up_factor*len(x)) for x in raw_signals]
+
+ # scale waves so they all have the same variance
+ equalized_signals = [x / np.std(x) for x in upsampled_signals]
+ raw_signals = [x / np.std(x) for x in raw_signals]
+ w0_upsamp, w1_upsamp, w2_upsamp, w3_upsamp = equalized_signals
+ t_up = np.arange(0, non_zero_end_idx*samp_period, upsamp_step)
+
+ zero_crossings = np.where(np.diff(np.sign(w0_upsamp)))[0]
+ num_crossings = len(zero_crossings)
+ if num_crossings % 2 == 0: # we want an odd number of zero crossings
+ zero_crossings = zero_crossings[1:]
+ num_crossings -= 1
+ waves_between_first_and_last_crossing = (num_crossings - 1) / 2
+ time_between_first_and_last_crossing = t_up[zero_crossings[-1]] - t_up[zero_crossings[0]]
+ curr_signal_freq_kHz = 1E3 * waves_between_first_and_last_crossing / time_between_first_and_last_crossing # kHz
+ self._freq_sum += curr_signal_freq_kHz
+ self._freq_samples += 1
+ self.est_signal_freq_kHz = self._freq_sum / self._freq_samples
+
+
+ # frequencies, spectrum = periodogram(w0_upsamp, sampling_freq * up_factor)
+ # signal_freq = frequencies[np.argmax(spectrum)] # Hz
+ # print "fft source frequency:", signal_freq, "Hz"
+ print "current source frequency:", curr_signal_freq_kHz, "kHz"
+ print "est source frequency:", self.est_signal_freq_kHz, "kHz"
+ # ax = fig2.add_subplot(111)
+ # ax.semilogy(frequencies,spectrum)
+ # ax.set_ylim([1e-7, 1e2])
+ # ax.set_xlim([0, 6e4])
+ # ax.set_xlabel('frequency [Hz]')
+ signal_period = 1E3 / self.est_signal_freq_kHz # microseconds
+ upsamples_recorded = len(w0_upsamp)
+
+ waves_ref = 3.5
+ waves_non_ref = 2.5
+ samples_per_wave = signal_period / samp_period
+ ref_upsamples = int(round(waves_ref * samples_per_wave * up_factor))
+ nonref_upsamples = int(np.ceil(waves_non_ref * samples_per_wave * up_factor))
+
+ ref_start_idx = None
+ if (len(w0_upsamp) % 2 == ref_upsamples % 2):
+ ref_start_idx = int(round((upsamples_recorded / 2) - (ref_upsamples / 2)))
+ else:
+ ref_start_idx = int(np.ceil((upsamples_recorded / 2) - (ref_upsamples / 2)))
+ ref_end_idx = ref_start_idx + ref_upsamples - 1
+ nonref_end_idx = ref_start_idx + nonref_upsamples - 1
+
+ w0_select = w0_upsamp[ref_start_idx : ref_end_idx + 1]
+ w1_select = w1_upsamp[ref_start_idx : nonref_end_idx + 1]
+ w2_select = w2_upsamp[ref_start_idx : nonref_end_idx + 1]
+ w3_select = w3_upsamp[ref_start_idx : nonref_end_idx + 1]
+ t_ref_select = t_up[ref_start_idx : ref_end_idx + 1]
+ t_nonref_select = t_up[ref_start_idx : nonref_end_idx + 1]
+
+ cc1 = np.correlate(w0_select, w1_select, mode='full')
+ cc2 = np.correlate(w0_select, w2_select, mode='full')
+ cc3 = np.correlate(w0_select, w3_select, mode='full')
+ corr_start = t_ref_select[0] - t_nonref_select[-1]
+ corr_end = t_ref_select[-1] - t_ref_select[0] + upsamp_step
+ t_corr = np.arange(corr_start, corr_end, upsamp_step)
+ print len(cc1), len(t_corr)
+
+ fig.clf()
+ ax1 = fig.add_subplot(511)
+ ax2 = fig.add_subplot(512)
+ ax3 = fig.add_subplot(513)
+ ax4 = fig.add_subplot(514)
+ ax5 = fig.add_subplot(515)
+ axarr = [ax1, ax2, ax3, ax4, ax5]
+
+ axarr[0].plot(t_up,w1_upsamp,'r',t_up,w2_upsamp,'g',t_up,w3_upsamp,'b',t_up,w0_upsamp,'k')
+ axarr[0].axis([0,60*samp_period,-3,3])
+ axarr[0].set_title('Signals')
+
+ axarr[1].plot(t_nonref_select, w1_select, 'r',
+ t_nonref_select, w2_select, 'g',
+ t_nonref_select, w3_select, 'b',
+ t_ref_select, w0_select, 'k')
+ axarr[1].set_title('Selected portions')
+
+ axarr[2].plot(t_corr, cc1)
+ axarr[2].set_title('Hydrophone 1 cross-correlation')
+ axarr[3].plot(t_corr, cc2)
+ axarr[3].set_title('Hydrophone 2 cross-correlation')
+ axarr[4].plot(t_corr, cc3)
+ axarr[4].set_title('Hydrophone 3 cross-correlation')
+
+ plt.draw()
+ plt.pause(0.1)
+
+ return [0,0,0,0] #DBG
+
+ def max_delta_t(hydrophone_idx_a, hydrophone_idx_b):
+ a = self.hydrophone_locations[hydrophone_idx_a]
+ b = self.hydrophone_locations[hydrophone_idx_b]
+ dist = la.norm(a - b)
+ return dist / self.c
+
+ def CRC(self, message):
+ # You may have to change the checksum type.
+ # Check the crc16 module online to see how to do that.
+ crc = crc16.crc16xmodem(message, 0xFFFF)
+ return struct.pack('>H', crc)
+
+ def check_CRC(self, message):
+ '''
+ Given a message with a checksum as the last two bytes, this will return True or False
+ if the checksum matches the given message.
+ '''
+ msg_checksum = message[-2:]
+ raw_message = message[:-2]
+ crc = crc16.crc16xmodem(raw_message, 0xFFFF)
+
+ # If the two match the message was correct
+ if crc == struct.unpack('>H', msg_checksum)[0]:
+ return True
+ else:
+ return False
+
+def delete_last_lines(n=1):
+ CURSOR_UP_ONE = '\x1b[1A'
+ ERASE_LINE = '\x1b[2K'
+ for _ in range(n):
+ sys.stdout.write(CURSOR_UP_ONE)
+ sys.stdout.write(ERASE_LINE)
+
+if __name__ == "__main__":
+ d = Sub8Sonar('LS', 1.484, rospy.get_param('~/sonar_driver/hydrophones'),
+ "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AH02X4IE-if00-port0",
+ 19200)
\ No newline at end of file
diff --git a/drivers/mil_passive_sonar/multilateration/__init__.py b/drivers/mil_passive_sonar/multilateration/__init__.py
new file mode 100644
index 00000000..87a0c3ea
--- /dev/null
+++ b/drivers/mil_passive_sonar/multilateration/__init__.py
@@ -0,0 +1 @@
+from multilateration import Multilaterator, ReceiverArraySim, Pulse
diff --git a/drivers/mil_passive_sonar/multilateration/multilateration.py b/drivers/mil_passive_sonar/multilateration/multilateration.py
new file mode 100644
index 00000000..1ef865c4
--- /dev/null
+++ b/drivers/mil_passive_sonar/multilateration/multilateration.py
@@ -0,0 +1,212 @@
+#!/usr/bin/python
+from __future__ import division
+import numpy as np
+import numpy.linalg as la
+from scipy import optimize
+from itertools import combinations
+
+from sub8_msgs.srv import Sonar, SonarResponse
+
+
+class Multilaterator(object):
+ '''
+ Finds the origin location of a pulse given differential times of
+ arrival to the individual sensors. c is the wave speed in the medium of operation.
+ Units:
+ Hydrohone coordinates are expected in millimeters, pulse location will be given in millimeters.
+ Timestamps are expected in microseconds. c is expected in millimeters per microsecond
+ Note:
+ hydrophone locations should be the dict returned by rospy.get_param('~//hydrophones
+ '''
+ def __init__(self, hydrophone_locations, c, method): # speed in millimeters/microsecond
+ self.hydrophone_locations = []
+ for key in hydrophone_locations:
+ sensor_location = np.array([hydrophone_locations[key]['x'], hydrophone_locations[key]['y'], hydrophone_locations[key]['z']])
+ self.hydrophone_locations += [sensor_location]
+ self.pairs = list(combinations(range(len(hydrophone_locations)),2))
+ self.c = c
+ self.method = method
+ print "\x1b[32mSpeed of Sound (c):", self.c, "millimeter/microsecond\x1b[0m"
+
+ def getPulseLocation(self, timestamps, method=None):
+ '''
+ Returns a ros message with the location and time of emission of a pinger pulse.
+ '''
+ try:
+ if method == None:
+ method = self.method
+ # print "\x1b[32mMultilateration algorithm:", method, "\x1b[0m"
+ assert len(self.hydrophone_locations) == len(timestamps)
+ source = None
+ if method == 'bancroft':
+ source = self.estimate_pos_bancroft(timestamps)
+ elif method == 'LS':
+ source = self.estimate_pos_LS(timestamps)
+ else:
+ print method, "is not an available multilateration algorithm"
+ return
+ response = SonarResponse()
+ response.x = source[0]
+ response.y = source[1]
+ response.z = source[2]
+ print "Reconstructed Pulse:\n\t" + "x: " + str(response.x) + " y: " + str(response.y) \
+ + " z: " + str(response.z) + " (mm)"
+ return response
+ except KeyboardInterrupt:
+ print "Source localization interupted, returning all zeroes."
+ response = SonarResponse()
+ response.x, response.y, response.z = (0, 0, 0)
+
+
+ def estimate_pos_bancroft(self, reception_times):
+ N = len(reception_times)
+ assert N >= 4
+
+ L = lambda a, b: a[0]*b[0] + a[1]*b[1] + a[2]*b[2] - a[3]*b[3]
+
+ def get_B(delta):
+ B = np.zeros((N, 4))
+ for i in xrange(N):
+ B[i] = np.concatenate([self.hydrophone_locations[i]/(self.c), [-reception_times[i]]]) + delta
+ return B
+
+ delta = min([.1*np.random.randn(4) for i in xrange(10)], key=lambda delta: np.linalg.cond(get_B(delta)))
+ # delta = np.zeros(4) # gives very good heading for noisy timestamps, although range is completely unreliable
+
+ B = get_B(delta)
+ a = np.array([0.5 * L(B[i], B[i]) for i in xrange(N)])
+ e = np.ones(N)
+
+ Bpe = np.linalg.lstsq(B, e)[0]
+ Bpa = np.linalg.lstsq(B, a)[0]
+
+ Lambdas = quadratic(
+ L(Bpe, Bpe),
+ 2*(L(Bpa, Bpe) - 1),
+ L(Bpa, Bpa))
+ if not Lambdas:
+ return [0, 0, 0]
+
+ res = []
+ for Lambda in Lambdas:
+ u = Bpa + Lambda * Bpe
+ position = u[:3] - delta[:3]
+ time = u[3] + delta[3]
+ if any(reception_times[i] < time for i in xrange(N)): continue
+ res.append(position*self.c)
+ if len(res) == 1:
+ source = res[0]
+ elif len(res) == 2:
+ source = [x for x in res if x[2] < 0] # Assume that the source is below us
+ if not source:
+ source = res[0]
+ else:
+ source = source[0]
+ else:
+ source = [0, 0, 0]
+ return source
+
+ def estimate_pos_LS(self, timestamps):
+ '''
+ Returns a ros message with the location and time of emission of a pinger pulse.
+ '''
+ self.timestamps = timestamps
+ init_guess = np.random.normal(0,100,3)
+ opt = {'disp': 0}
+ opt_method = 'Powell'
+ result = optimize.minimize(self.cost_LS, init_guess, method=opt_method, options=opt, tol=1e-15)
+ if(result.success):
+ source = [result.x[0], result.x[1], result.x[2]]
+ else:
+ source = [0, 0, 0]
+ return source
+
+ def cost_LS(self, potential_pulse):
+ '''
+ Compares the difference in observed and theoretical difference in time of arrival
+ between tevery unique pair of hydrophones.
+
+ Note: the result will be along the direction of the heading but not at the right distance.
+ '''
+ cost = 0
+ t = self.timestamps
+ c = self.c
+ x = np.array(potential_pulse)
+ for pair in self.pairs:
+ h0 = self.hydrophone_locations[pair[0]]
+ h1 = self.hydrophone_locations[pair[1]]
+ residual = la.norm(x-h0) - la.norm(x-h1) - c*(t[pair[0]] - t[pair[1]])
+ cost += residual**2
+ return cost
+
+ def cost_LS2(self, potential_pulse):
+ """
+ Slightly less accurate than the one above in terms of heading but much faster.
+ """
+ cost = 0
+ t = self.timestamps
+ x0 = self.hydrophone_locations[0][0]
+ y0 = self.hydrophone_locations[0][1]
+ z0 = self.hydrophone_locations[0][2]
+ x = potential_pulse[0]
+ y = potential_pulse[1]
+ z = potential_pulse[2]
+ d0 = np.sqrt((x0 - x)**2 + (y0 - x)**2 + (z0 - x)**2)
+ for i in xrange(1, len(self.hydrophone_locations)):
+ xi = self.hydrophone_locations[i][0]
+ yi = self.hydrophone_locations[i][1]
+ zi = self.hydrophone_locations[i][2]
+ di = np.sqrt((xi - x)**2 + (yi - x)**2 + (zi - x)**2)
+ hydro_i_cost = (di - d0 - self.c * t[i])**2
+ cost = cost + hydro_i_cost
+ return cost
+
+
+class ReceiverArraySim(object):
+ """
+ Simulates an array of receivers that listens to point sources and returns the DTOA.
+ (difference in time of arrival)
+ Base Units:
+ time - microseconds
+ length - millimeters
+ """
+ def __init__(self, hydrophone_locations, wave_propagation_speed_mps):
+ self.c = wave_propagation_speed_mps
+ self.hydrophone_locations = np.array([0, 0, 0])
+ for key in hydrophone_locations:
+ sensor_location = np.array([hydrophone_locations[key]['x'], hydrophone_locations[key]['y'], hydrophone_locations[key]['z']])
+ self.hydrophone_locations = np.vstack((self.hydrophone_locations, sensor_location))
+ self.hydrophone_locations = self.hydrophone_locations[1:]
+
+ def listen(self, pulse):
+ timestamps = []
+ for idx in range(4):
+ src_range = np.sqrt(sum(np.square(pulse.position() - self.hydrophone_locations[idx])))
+ timestamps += [pulse.t + src_range / self.c]
+ return np.array(timestamps)
+
+class Pulse(object):
+ """
+ Represents an omnidirectional wave or impulse emmited from a point source
+ """
+ def __init__(self, x, y, z, t):
+ self.x = x
+ self.y = y
+ self.z = z
+ self.t = t
+
+ def position(self):
+ return np.array([self.x, self.y, self.z])
+
+ def __repr__(self):
+ return "Pulse:\t" + "x: " + str(self.x) + " y: " + str(self.y) + " z: " \
+ + str(self.z) + " (mm)"
+
+
+def quadratic(a, b, c):
+ discriminant = b*b - 4*a*c
+ if discriminant >= 0:
+ first_times_a = (-b+math.copysign(math.sqrt(discriminant), -b))/2
+ return [first_times_a/a, c/first_times_a]
+ else:
+ return []
\ No newline at end of file
diff --git a/drivers/mil_passive_sonar/nodes/pinger_finder.py b/drivers/mil_passive_sonar/nodes/pinger_finder.py
new file mode 100755
index 00000000..88d2faf8
--- /dev/null
+++ b/drivers/mil_passive_sonar/nodes/pinger_finder.py
@@ -0,0 +1,173 @@
+#!/usr/bin/env python
+import rospy
+import rospkg
+import numpy as np
+from numpy import linalg as npl
+import tf
+from navigator_msgs.srv import FindPinger, SetFrequency, SetFrequencyResponse
+from hydrophones.msg import ProcessedPing
+from geometry_msgs.msg import Point, PoseStamped, Pose
+from visualization_msgs.msg import Marker
+from std_srvs.srv import SetBool, SetBoolResponse
+import navigator_tools
+
+class PingerFinder(object):
+ """
+ This class will find the position of a pinger at a given frequency. For it
+ to find a good solution, it needs to get observations from at least 2 sufficiently
+ different positions. Observations are considered valid if they fall within
+ self.freq_tol of self.target_freq, where self.target_freq can be set
+ using 'rosservice call /hydrophones/set_freq "frequency: ____"'.
+
+ The default behaviour is to not store observations. To start recording valid
+ observations, run 'rosservice call /hydrophones/set_listen "data: true"'. Remember
+ to run 'rosservice call /hydrophones/set_listen "data: false"' to stop recording
+ observations. For best results, it is best to only record observations while the
+ vehicle is station-keeping.
+
+ When running, this class will publish arrow markers to /visualization_marker and
+ a green cube marker representing the estimated position of the pinger whenever the
+ /hydrophones/find_pinger service is called.
+ """
+
+ def __init__(self):
+ self.map_frame = "/enu"
+ self.hydrophone_frame = "/hydrophones"
+ self.tf_listener = tf.TransformListener()
+ self.target_freq = 35E3
+ self.freq_tol = 1E3
+ self.min_amp = 200 # if too many outliers, increase this
+ self.max_observations = 200
+ self.line_array =np.empty((0, 4), float)
+ self.observation_amplitudes = np.empty((0, 0), float)
+ self.pinger_position = Point(0, 0, 0)
+ self.heading_pseudorange = 10
+ self.debug_arrow_id = 0
+ self.debug_arrow_lifetime = rospy.Duration(10, 0)
+ self.listen = False
+ self.ping_sub = rospy.Subscriber("/hydrophones/processed", ProcessedPing, callback=self.ping_cb)
+ self.marker_pub = rospy.Publisher("/visualization_marker", Marker, queue_size=10)
+ self.pinger_finder_srv = rospy.Service('hydrophones/find_pinger', FindPinger, self.find_pinger)
+ self.activate_listening = rospy.Service('hydrophones/set_listen', SetBool, self.set_listen)
+ self.set_freq_srv = rospy.Service('hydrophones/set_freq', SetFrequency, self.set_freq)
+
+ def ping_cb(self, ping):
+ print rospkg.get_ros_package_path()
+ print "PINGERFINDER: freq={p.freq:.0f} amp={p.amplitude:.0f}".format(p=ping)
+ if abs(ping.freq - self.target_freq) < self.freq_tol and ping.amplitude > self.min_amp and self.listen:
+ trans, rot = None, None
+ try:
+ self.tf_listener.waitForTransform(self.map_frame, self.hydrophone_frame, ping.header.stamp, rospy.Duration(0.25))
+ trans, rot = self.tf_listener.lookupTransform(self.map_frame, self.hydrophone_frame, ping.header.stamp)
+ except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException) as e:
+ print e
+ return
+ p0 = np.array([trans[0], trans[1]])
+ R = tf.transformations.quaternion_matrix(rot)[:3, :3]
+ delta = R.dot(navigator_tools.point_to_numpy(ping.position))[:2]
+ p1 = p0 + self.heading_pseudorange * delta / npl.norm(delta)
+ line_coeffs = np.array([[p0[0], p0[1], p1[0], p1[1]]]) # p0 and p1 define a line
+ self.visualize_arrow(Point(p0[0], p0[1], 0), Point(p1[0], p1[1], 0))
+ self.line_array = np.append(self.line_array, line_coeffs, 0)
+ self.observation_amplitudes = np.append(self.observation_amplitudes, ping.amplitude)
+ if len(self.line_array) >= self.max_observations: # delete softest samples if we have over max_observations
+ softest_idx = np.argmin(self.observation_amplitudes)
+ self.line_array = np.delete(self.line_array, softest_idx, axis=0)
+ self.observation_amplitudes = np.delete(self.observation_amplitudes, softest_idx)
+ print "PINGERFINDER: Observation collected. Total: {}".format(self.line_array.shape[0])
+
+ def LS_intersection(self):
+ """
+ self.line_array represents a system of 2d line equations. Each row represents a different
+ observation of a line in map frame on which the pinger lies. Row structure: [x1, y1, x2, y2]
+ Calculates the point in the plane with the least cummulative distance to every line
+ in self.line_array. For more information, see:
+ https://en.wikipedia.org/wiki/Line-line_intersection#In_two_dimensions_2
+ """
+
+ def line_segment_norm(line_end_pts):
+ assert len(line_end_pts) == 4
+ return npl.norm(line_end_pts[2:] - line_end_pts[:2])
+
+ begin_pts = self.line_array[:, :2]
+ diffs = self.line_array[:, 2:4] - begin_pts
+ norms = np.apply_along_axis(line_segment_norm, 1, self.line_array).reshape(diffs.shape[0], 1)
+ rot_left_90 = np.array([[0, -1], [1, 0]])
+ perp_unit_vecs = np.apply_along_axis(lambda unit_diffs: rot_left_90.dot(unit_diffs), 1, diffs / norms)
+ A_sum = np.zeros((2, 2))
+ Ap_sum = np.zeros((2, 1))
+
+ for x, y in zip(begin_pts, perp_unit_vecs):
+ begin = x.reshape(2, 1)
+ perp_vec = y.reshape(2, 1)
+ A = perp_vec.dot(perp_vec.T)
+ Ap = A.dot(begin)
+ A_sum += A
+ Ap_sum += Ap
+
+ res = npl.inv(A_sum).dot(Ap_sum)
+ self.pinger_position = Point(res[0], res[1], 0)
+ return self.pinger_position
+
+ def find_pinger(self, srv_request):
+ if self.line_array.shape[0] < 2:
+ print "PINGER_FINDER: Can't locate pinger. Less than two valid observations have been recorded."
+ return {}
+ res = {'pinger_position' : self.LS_intersection(), 'num_samples' : self.line_array.shape[0]}
+ self.visualize_pinger()
+ return res
+
+ def visualize_pinger(self):
+ marker = Marker()
+ marker.ns = "pinger{}".format(self.target_freq)
+ marker.header.stamp = rospy.Time(0)
+ marker.header.frame_id = self.map_frame
+ marker.type = marker.CUBE
+ marker.action = marker.ADD
+ marker.scale.x = 1.0
+ marker.scale.y = 1.0
+ marker.scale.z = 1.0
+ marker.color.g = 1.0
+ marker.color.a = 0.75
+ marker.pose.position = self.pinger_position
+ if self.pinger_position != Point(0, 0, 0):
+ self.marker_pub.publish(marker)
+ print "PINGERFINDER: position: ({p.x[0]:.2f}, {p.y[0]:.2f})".format(p=self.pinger_position)
+
+
+ def visualize_arrow(self, tail, head):
+ marker = Marker()
+ marker.ns = "pinger{}/heading".format(self.target_freq)
+ marker.header.stamp = rospy.Time(0)
+ marker.header.frame_id = self.map_frame
+ marker.id = self.debug_arrow_id
+ self.debug_arrow_id += 1
+ marker.type = marker.ARROW
+ marker.action = marker.ADD
+ marker.lifetime = self.debug_arrow_lifetime
+ marker.points.append(tail)
+ marker.points.append(head)
+ marker.scale.x = 0.5
+ marker.scale.y = 1.0
+ marker.scale.z = 1.0
+ marker.color.g = 1.0
+ marker.color.b = 1.0
+ marker.color.a = 0.5
+ self.marker_pub.publish(marker)
+
+ def set_listen(self, listen_status):
+ self.listen = listen_status.data
+ print "PINGERFINDER: setting listening to on" if self.listen else "PINGERFINDER: setting listening to off"
+ return {'success': True, 'message': ""}
+
+ def set_freq(self, msg):
+ self.target_freq = msg.frequency
+ self.line_array = np.empty((0, 4), float)
+ self.sample_amplitudes = np.empty((0, 0), float)
+ self.pinger_position = Point(0, 0, 0)
+ return SetFrequencyResponse()
+
+if __name__ == '__main__':
+ rospy.init_node('pinger_finder')
+ as_per_the_ususal = PingerFinder()
+ rospy.spin()
diff --git a/drivers/mil_passive_sonar/nodes/plotter.py b/drivers/mil_passive_sonar/nodes/plotter.py
new file mode 100755
index 00000000..93d8f7ad
--- /dev/null
+++ b/drivers/mil_passive_sonar/nodes/plotter.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+import rospy
+import rosparam
+
+import numpy as np
+from scipy import optimize
+
+from sub8_msgs.srv import Sonar, SonarResponse
+
+import matplotlib.pyplot as plt
+from mpl_toolkits.mplot3d import Axes3D
+fig = plt.figure()
+ax = fig.add_subplot(111, projection='3d')
+
+print "Waiting for sonar service"
+rospy.wait_for_service('~/sonar/get_pinger_pulse')
+sonar = rospy.ServiceProxy('~/sonar/get_pinger_pulse', Sonar)
+print "sonar serv proxy created"
+
+try:
+ while(True):
+ try:
+ pinger_pose = sonar()
+ except Exception:
+ plt.close('all')
+ print "\nSonar driver is down, shutting down plotter"
+ break
+ print "x:", str(pinger_pose.x).rjust(15), "y:", str(pinger_pose.y).rjust(15), "z:", str(pinger_pose.z).rjust(15)
+ ax.scatter(pinger_pose.x, pinger_pose.y, pinger_pose.z)
+ plt.draw()
+ plt.pause(0.1)
+except KeyboardInterrupt:
+ plt.close('all')
+ print "\nshutting down plotter"
\ No newline at end of file
diff --git a/drivers/mil_passive_sonar/nodes/sonar_test.py b/drivers/mil_passive_sonar/nodes/sonar_test.py
new file mode 100755
index 00000000..d4aa9108
--- /dev/null
+++ b/drivers/mil_passive_sonar/nodes/sonar_test.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+from __future__ import division
+import numpy as np
+import numpy.linalg as la
+from scipy import optimize
+import rospy
+import rosparam
+import random
+from multilateration import Multilaterator, ReceiverArraySim, Pulse
+import sys
+
+
+if __name__ == '__main__':
+ def print_green(str):
+ print '\x1b[32m' + str + '\x1b[0m'
+
+ def error(obs, exp):
+ # Interesting, faster, but not as accurate
+ # alpha = np.arccos(np.clip(np.dot(obs/la.norm(obs),exp/la.norm(exp)),-1,1))*180/np.pi
+ alpha = 2*np.arctan2(la.norm(la.norm(exp)*obs-la.norm(obs)*exp),la.norm(la.norm(exp)*obs+la.norm(obs)*exp))
+ mag_error = 100 * (la.norm(obs) - la.norm(exp)) / la.norm(exp)
+ return ('\x1b[31m' if (mag_error == -100) else "") + ("Errors: directional=" + str(alpha) + "deg").ljust(42) \
+ + ("magnitude=" + str(mag_error) + "%").ljust(20)
+
+ def delete_last_lines(n=0):
+ CURSOR_UP_ONE = '\x1b[1A'
+ ERASE_LINE = '\x1b[2K'
+ for _ in range(n):
+ sys.stdout.write(CURSOR_UP_ONE)
+ sys.stdout.write(ERASE_LINE)
+
+ c = 1.484 # millimeters/microsecond
+ hydrophone_locations = rospy.get_param('~/sonar_test/hydrophones')
+ hydrophone_array = ReceiverArraySim(hydrophone_locations, c)
+ sonar = Multilaterator(hydrophone_locations, c, 'LS')
+
+ # # Simulate individual pulses (Debugging Jakes Board)
+ # pulse = Pulse(-5251, -7620, 1470, 0)
+ # tstamps = hydrophone_array.listen(pulse)
+ # tstamps = tstamps - tstamps[0]
+ # print_green(pulse.__repr__())
+ # print "Perfect timestamps: (microseconds)\n\t", tstamps
+ # res_msg = sonar.getPulseLocation(np.array(tstamps))
+ # res = np.array([res_msg.x, res_msg.y, res_msg.z])
+ # print "\t\x1b[33m".ljust(22) + error(res, pulse.position()) + "\x1b[0m"
+
+ # pulses will be generated with inside a cube with side-length $(pulse_range) (mm)
+ try:
+ for h in range(3,8):
+ # smallest cube will be a meter wide, largest will be 10 km wide
+ pulse_range = 10**h # in mm
+ rand_args = [-pulse_range, pulse_range + 1]
+ num_pulses = 10
+ print "\n\x1b[1mGenerating " + str(num_pulses) + " pulses within a " \
+ + str(2*pulse_range/1000) + " meters wide cube\x1b[0m\n"
+
+ for i in range(num_pulses):
+ pulse = Pulse(random.randrange(*rand_args),
+ random.randrange(*rand_args),
+ random.randrange(*rand_args), 0)
+ tstamps = hydrophone_array.listen(pulse)
+ tstamps = tstamps - tstamps[0]
+ print_green(str(i).ljust(2) + str(pulse))
+ print "Perfect timestamps: (microseconds)\n\t", tstamps
+ res_msg = sonar.getPulseLocation(np.array(tstamps))
+ delete_last_lines(4) # more concise output
+ res = np.array([res_msg.x, res_msg.y, res_msg.z])
+ print "\t\x1b[33m".ljust(22) + error(res, pulse.position()) + "\x1b[0m"
+ print "Progressively adding noise to timestamps..."
+
+ for j in range(-5, 2):
+ sigma = 10**j
+ noisy_tstamps = [x + np.random.normal(0, sigma) for x in tstamps]
+ noisy_tstamps[0] = 0
+ print "Noisy timestamps:\n\t", noisy_tstamps
+ res_msg = sonar.getPulseLocation(np.array(noisy_tstamps))
+ res = np.array([res_msg.x, res_msg.y, res_msg.z])
+ delete_last_lines(4) # more concise output
+ print "\t\x1b[33m" + ("sigma: " + str(sigma)).ljust(16) \
+ + error(res, pulse.position()) + "\x1b[0m"
+ except KeyboardInterrupt:
+ print "\nAborting mutilateration tests prematurely"
diff --git a/drivers/mil_passive_sonar/package.xml b/drivers/mil_passive_sonar/package.xml
new file mode 100644
index 00000000..f3f79469
--- /dev/null
+++ b/drivers/mil_passive_sonar/package.xml
@@ -0,0 +1,16 @@
+
+
+ mil_passive_sonar
+ 1.0.0
+ Package for multilateration and passive sonar
+
+ Matthew Langford
+ David Soto
+
+ MIT
+
+ catkin
+ rospy
+ rospy
+
+
diff --git a/drivers/mil_passive_sonar/paulboard_driver/README.md b/drivers/mil_passive_sonar/paulboard_driver/README.md
new file mode 100644
index 00000000..14c960ce
--- /dev/null
+++ b/drivers/mil_passive_sonar/paulboard_driver/README.md
@@ -0,0 +1,19 @@
+# Paulboard Driver
+
+The scripts here are used to run the old 'Paulboard', the hydrophone board,
+that MIL started using in 2013.
+
+The driver node in this package used to interface with the old 'hydrophone'
+package. Communication would occur via custom ROS msg's.
+
+## TODO
+If there is a need or want to continue using this board, as opposed to Jake
+Easterling's, then the sonar_driver node in mil_passive_sonar should be,
+ammended to be able to import the paulboard_driver code.
+
+## Explanation of `permute` parameter
+
+A `permute` value of `w x y z` means that the connector labeled Aw on the PCB
+maps to hydrophone 0 as the hydrophones package wants it, Ax maps to 1, Ay
+maps to 2, and Az maps to 3.
+
diff --git a/drivers/mil_passive_sonar/paulboard_driver/SimpleHyd2013.bin b/drivers/mil_passive_sonar/paulboard_driver/SimpleHyd2013.bin
new file mode 100644
index 00000000..4b4c50a0
Binary files /dev/null and b/drivers/mil_passive_sonar/paulboard_driver/SimpleHyd2013.bin differ
diff --git a/drivers/mil_passive_sonar/paulboard_driver/__init__.py b/drivers/mil_passive_sonar/paulboard_driver/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/drivers/mil_passive_sonar/paulboard_driver/ais_bootloader.py b/drivers/mil_passive_sonar/paulboard_driver/ais_bootloader.py
new file mode 100755
index 00000000..1ac1dcd8
--- /dev/null
+++ b/drivers/mil_passive_sonar/paulboard_driver/ais_bootloader.py
@@ -0,0 +1,147 @@
+import logging
+import serial
+import time
+
+MAGICWORD = 0x41504954;
+XMT_START_WORD = 0x58535441;
+RCV_START_WORD = 0x52535454;
+
+OP_BOOTTABLE = 0x58535907;
+OP_SEQREADEN = 0x58535963;
+OP_SECTIONLOAD = 0x58535901;
+OP_CSECTIONLOAD = 0x58535909;
+OP_SECTIONFILL = 0x5853590A;
+OP_FXNEXEC = 0x5853590D;
+OP_JUMP = 0x58535905;
+OP_JUMPCLOSE = 0x58535906;
+OP_CRCEN = 0x58535903;
+OP_CRCDIS = 0x58535904;
+OP_CRCREQ = 0x58535902;
+OP_READWAIT = 0x58535914;
+OP_STARTOVER = 0x58535908;
+OP_PINGDEVICE = 0x5853590B;
+
+def op2ack(op):
+ return (op & ~0x0F000000) | 0x02000000
+
+class Exception(RuntimeError):
+ pass
+
+def delay():
+ time.sleep(5/1000)
+
+def word2str(word):
+ return chr(word & 0xFF) + \
+ chr((word >> 8) & 0xFF) + \
+ chr((word >> 16) & 0xFF) + \
+ chr((word >> 24) & 0xFF)
+
+def str2word(s):
+ vals = map(ord, s)
+ return vals[0] + (vals[1] << 8) + (vals[2] << 16) + (vals[3] << 24)
+
+def read_word_timeout(ser):
+ s = ser.read(4)
+ if len(s) < 4:
+ raise Exception('Timeout while reading word')
+ return str2word(s)
+
+def sws(ser):
+ """Start word sync"""
+ logging.debug('Performing SWS')
+ ser.write(chr(XMT_START_WORD >> 24))
+ while True:
+ response = ser.read(1)
+ if len(response) == 0:
+ raise Exception('Timeout during start word sync')
+ if ord(response[0]) == (RCV_START_WORD >> 24):
+ return True
+
+def pos(ser, N=10):
+ """Ping opcode sync"""
+ logging.debug('Performing POS')
+ ser.write(word2str(OP_PINGDEVICE))
+ if read_word_timeout(ser) != op2ack(OP_PINGDEVICE):
+ raise Exception('Invalid response to ping opcode')
+ delay()
+
+ ser.write(word2str(N))
+ if read_word_timeout(ser) != N:
+ raise Exception('Invalid response to ping count')
+
+ for i in xrange(1, N+1):
+ ser.write(word2str(i))
+ if read_word_timeout(ser) != i:
+ raise Exception('Invalid response to ping %d' % i)
+ return True
+
+def os(ser, op):
+ ser.write(word2str(op))
+ response = read_word_timeout(ser)
+ if response != op2ack(op):
+ raise Exception('Invalid response to opcode (%x, expected %x)' % (response, op2ack(op)))
+
+def boot(ser, file):
+ magic = str2word(file.read(4))
+ if magic != MAGICWORD:
+ raise Exception('Invalid magic word in file')
+
+ sws(ser)
+ pos(ser)
+
+ while True:
+ delay()
+ op = str2word(file.read(4))
+ os(ser, op)
+
+ if op == OP_SECTIONLOAD or op == OP_CSECTIONLOAD:
+ addr = str2word(file.read(4))
+ ser.write(word2str(addr))
+ size = str2word(file.read(4))
+ ser.write(word2str(size))
+ logging.debug('SECTIONLOAD of %d bytes to 0x%x' % (size, addr))
+ ser.write(file.read(size))
+ elif op == OP_FXNEXEC:
+ args = str2word(file.read(4))
+ ser.write(word2str(args))
+ words = (args >> 16)*4
+ logging.debug('FXNEXEC of %d bytes' % words)
+ ser.write(file.read(words))
+ elif op == OP_JUMPCLOSE:
+ addr = str2word(file.read(4))
+ logging.debug('JUMPLOAD to 0x%x' % addr)
+ ser.write(word2str(addr))
+ break
+ elif op == OP_CRCEN:
+ logging.debug('Enabled CRC')
+ elif op == OP_CRCDIS:
+ logging.debug('Disabled CRC')
+ elif op == OP_CRCREQ:
+ calc_crc = read_word_timeout(ser)
+ real_crc = str2word(file.read(4))
+ seek = str2word(file.read(4))
+ if seek > 0x7FFFFFFF:
+ seek = (seek-1) - 0xFFFFFFFF
+ if real_crc == calc_crc:
+ logging.debug('CRC passed')
+ else:
+ logging.debug('CRC failed')
+ file.seek(seek, 1)
+ else:
+ raise Exception('Unknown opcode 0x%x' % op)
+
+ donestr = ser.read(8)
+ if donestr != " DONE\0":
+ raise Exception('Invalid done string: %s' % donestr)
+
+ return True
+
+def main():
+ ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
+ with open('SimpleHyd2013.bin') as file:
+ boot(ser, file)
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.DEBUG)
+ main()
+
diff --git a/drivers/mil_passive_sonar/paulboard_driver/paulboard_driver b/drivers/mil_passive_sonar/paulboard_driver/paulboard_driver
new file mode 100755
index 00000000..d5dcbafd
--- /dev/null
+++ b/drivers/mil_passive_sonar/paulboard_driver/paulboard_driver
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+
+import serial
+import numpy
+
+import roslib
+roslib.load_manifest('paulboard_driver')
+import rospy
+
+from std_msgs.msg import Header
+
+from paulboard_driver import ais_bootloader
+from hydrophones.msg import Ping
+from hydrophones import util
+
+class Node(object):
+ def __init__(self, ser):
+ self.sample_rate = rospy.get_param('~sample_rate', 300e3)
+ self.thresh = rospy.get_param('~thresh', 500)
+ self.frame = rospy.get_param('~frame', '/hydrophones')
+ permute_str = rospy.get_param('~permute', '1 2 3 4')
+ self.permute = [int(v)-1 for v in permute_str.split(' ')]
+ self.ser = ser
+ self.pub = rospy.Publisher('hydrophones/ping', Ping)
+ self.buf = ""
+ self.last_packet_num = None
+
+ self.ser.baudrate = 1152000
+
+ def run_command(self, cmd):
+ self.ser.timeout = .2
+ self.ser.write(cmd)
+ response = self.ser.read(128)
+ if 'OK' not in response:
+ raise RuntimeError('Invalid response to command "%s"\n got: "%s"' % (cmd, response))
+
+ def run(self):
+ self.run_command('samplerate set\r%d\r' % (self.sample_rate))
+ self.run_command('thresh set\r%d\r' % (self.thresh))
+ self.ser.write('go\r')
+ self.ser.read(99999)
+ self.ser.timeout = .1
+ rospy.loginfo('Paulboard running')
+
+ buf = ""
+ while not rospy.is_shutdown():
+ got = self.ser.read(10240)
+ if len(got) > 0:
+ buf += got
+ elif len(buf) > 0:
+ self.parse_publish_ping(buf)
+ buf = ""
+
+ def parse_publish_ping(self, buf):
+ result = self.try_parse_ping(buf)
+ if result is None:
+ rospy.logerr('Got bad ping packet')
+ return
+
+ packet_num, samples = result
+ if self.last_packet_num is not None and packet_num != self.last_packet_num+1:
+ rospy.logwarn('Dropped %d ping packet(s)' % (packet_num - (self.last_packet_num+1)))
+ self.last_packet_num = packet_num
+
+ samples = samples[self.permute, :]
+
+ self.pub.publish(Ping(
+ header=Header(stamp=rospy.Time.now(),
+ frame_id=self.frame),
+ channels=samples.shape[0],
+ samples=samples.shape[1],
+ data=util.samples_to_list(samples),
+ sample_rate=self.sample_rate))
+
+ def try_parse_ping(self, buf):
+ # Verify we got a header
+ if len(buf) < 8:
+ return None
+ header = word16(buf[0:2])
+ if header != 0x1234:
+ return None
+
+ # Parse header, verify we have all data
+ packet_num = word16(buf[2:4])
+ sample_rate = word16(buf[4:6])*1000
+ sample_count = word16(buf[6:8])
+ if len(buf) < 8 + 8*sample_count + 4:
+ return None
+
+ # Parse all samples into an array of column vectors
+ pos = 8
+ samples = numpy.zeros((4, sample_count), numpy.uint16)
+ for sample in xrange(sample_count):
+ for chan in xrange(4):
+ samples[chan, sample] = word16(buf[pos:pos+2])
+ pos += 2
+
+ # Parse footer
+ checksum = word16(buf[pos:pos+2])
+ footer = word16(buf[pos+2:pos+4])
+ if footer != 0x4321:
+ return None
+
+ return (packet_num, samples)
+
+def word16(str):
+ return ord(str[0]) + (ord(str[1]) << 8)
+
+def check_board_bootloaded(ser):
+ ser.timeout = .5
+ ser.write('\r')
+ got = ser.read(99999)
+ if got.endswith('> '):
+ return True
+ return False
+
+def bootload_board(ser):
+ path = roslib.packages.resource_file('paulboard_driver', 'blobs', 'SimpleHyd2013.bin')
+ print 'Bin path: ', path
+ ser.timeout = 1
+ ser.baudrate = 115200
+ with open(path, 'rb') as file:
+ ais_bootloader.boot(ser, file)
+ rospy.sleep(0.5) # Give program time to start
+
+if __name__ == '__main__':
+ rospy.init_node('paulboard_driver')
+ port = rospy.get_param('~port')
+ print 'Port: ', port
+
+ with serial.Serial(port, 115200, timeout=.3) as ser:
+ if check_board_bootloaded(ser):
+ rospy.loginfo('PaulBoard already bootloaded')
+ else:
+ rospy.loginfo('Bootloading PaulBoard')
+ while True:
+ try:
+ bootload_board(ser)
+ rospy.loginfo('Bootloading complete')
+ break
+ except ais_bootloader.Exception, ex:
+ rospy.logerr('Failed to bootload: %s' % ex)
+ if rospy.is_shutdown():
+ break
+ rospy.sleep(1)
+
+ Node(ser).run()
+
+
diff --git a/drivers/mil_passive_sonar/scripts/generate_dtoa.py b/drivers/mil_passive_sonar/scripts/generate_dtoa.py
new file mode 100755
index 00000000..b23c3b68
--- /dev/null
+++ b/drivers/mil_passive_sonar/scripts/generate_dtoa.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+from multilateration import *
+import numpy as np
+import argparse
+
+h0 = {'x' : 0, 'y': 0, 'z' : 0}
+h1 = {'x' : 25.4, 'y': 0, 'z' : 0}
+h2 = {'x' : -25.4, 'y': 0, 'z' : 0}
+h3 = {'x' : 0, 'y': 25.4, 'z' : 0}
+hydrophone_locations = [h1, h2, h3]
+
+def dict_to_xyz_vec(pos_dict):
+ '''
+ Converts a dictionary with 'x', 'y', and 'z' keys to a numpy array
+ '''
+ p = pos_dict
+ return np.array([p['x'], p['y'], p['z']])
+
+def get_dtoa(c, sensor_position, source):
+ '''
+ Calculates the dtoa for a signal and a sensor that is ref_offset away from the reference sensor
+ c should be in millimeter per microsecond
+ position params should have units of mm
+ '''
+ assert(isinstance(sensor_position, np.ndarray))
+ assert(isinstance(source, np.ndarray))
+ assert(len(sensor_position) == 3)
+ assert(len(source) == 3)
+ t_ref = np.linalg.norm(source) / c
+ t = np.linalg.norm(source - sensor_position) / c
+ delta_t = t_ref - t
+ #print __name__, sensor_position, source, c, t_ref, t, delta_t
+ return delta_t
+
+def get_batch_dtoa(c, sensor_positions, source):
+ '''
+ Calculates the dtoa's of a signal to a list of sensors(positions). The reference
+ is assumed to be at the origin.
+ c should be in millimeter per microsecond
+ position params should have units of mm
+ '''
+ dtoa = []
+ for x in sensor_positions:
+ dtoa.append(get_dtoa(c, x, source))
+ return dtoa
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(
+ description='Generates dtoa measurements given sensor and source locations',
+ usage='Pass the path to a file with source locations. Each row should have 3 columns' +
+ 'The columns should have the x, y, and z coordinates of each source location, ' \
+ 'separated by spaces or tabs. Coordinates should be in units of millimeters.')
+ parser.add_argument('path_to_input')
+ args = parser.parse_args()
+ sonar_test = np.loadtxt(args.path_to_input)
+ sensors = [dict_to_xyz_vec(x) for x in hydrophone_locations]
+ res = []
+ for case in sonar_test:
+ res.append(get_batch_dtoa(1.484, sensors, case))
+ res = np.array(res)
+ # output format is {numbers of input rows} rows w/ 3 columns (dtoa measurements in microseconds)
+ print res
+
diff --git a/drivers/mil_passive_sonar/setup.py b/drivers/mil_passive_sonar/setup.py
new file mode 100644
index 00000000..49a04b0c
--- /dev/null
+++ b/drivers/mil_passive_sonar/setup.py
@@ -0,0 +1,13 @@
+# ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
+
+from distutils.core import setup
+from catkin_pkg.python_setup import generate_distutils_setup
+
+# fetch values from package.xml
+setup_args = generate_distutils_setup(
+ packages=['mil_passive_sonar',
+ 'multilateration',
+ 'paulboard_driver'],
+)
+
+setup(**setup_args)
diff --git a/odometry_tools b/odometry_tools
index b23dc5d7..299eb06d 160000
--- a/odometry_tools
+++ b/odometry_tools
@@ -1 +1 @@
-Subproject commit b23dc5d74b941dd36159fce030479d9772c58113
+Subproject commit 299eb06d1c538085ac2cb86a2ff2ba070042fed0
diff --git a/perception/mil_vision/CMakeLists.txt b/perception/mil_vision/CMakeLists.txt
new file mode 100644
index 00000000..a5508733
--- /dev/null
+++ b/perception/mil_vision/CMakeLists.txt
@@ -0,0 +1,106 @@
+cmake_minimum_required(VERSION 2.8.3)
+project(mil_vision)
+
+# set c++11 as default, overide with set_target_properties()
+# if needed for specific nodes (cough..cough... PCL)
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -g -pedantic -Wall -std=c++11 ")
+
+find_package(catkin
+ REQUIRED COMPONENTS
+ roscpp
+ rospy
+ eigen_conversions
+ rostime
+ image_transport
+ image_geometry
+ cv_bridge
+ message_generation
+ mil_msgs
+ std_msgs
+ std_srvs
+ geometry_msgs
+ sensor_msgs
+ tf
+ pcl_ros
+ tf2_sensor_msgs
+ tf2_geometry_msgs
+ mil_tools
+)
+
+find_package(PCL 1.7 REQUIRED)
+find_package(Boost REQUIRED date_time filesystem)
+
+catkin_python_setup()
+
+catkin_package(
+ INCLUDE_DIRS
+ include
+ LIBRARIES
+ mil_vision_lib
+ mil_sparsestereo
+ CATKIN_DEPENDS
+ roscpp
+ rospy
+ message_runtime
+ std_msgs
+ geometry_msgs
+ sensor_msgs
+ mil_msgs
+ mil_tools
+ pcl_ros
+ DEPENDS
+ system_lib
+ image_transport
+ image_geometry
+ cv_bridge
+ mil_msgs
+)
+
+include_directories(
+ include
+ SYSTEM
+ ${PCL_INCLUDE_DIRS}
+ ${Boost_INCLUDE_DIR}
+ ${catkin_INCLUDE_DIRS}
+)
+link_directories(${PCL_LIBRARY_DIRS})
+add_definitions(${PCL_DEFINITIONS})
+
+FILE(GLOB EXFAST_SOURCES exFAST_SparseStereo/src/sparsestereo/*)
+add_library( mil_sparsestereo SHARED ${EXFAST_SOURCES})
+target_include_directories(mil_sparsestereo PUBLIC exFAST_SparseStereo/src)
+target_link_libraries(mil_sparsestereo ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_INCLUDE_DIRS})
+set_target_properties(mil_sparsestereo PROPERTIES COMPILE_FLAGS "-O3 -DNDEBUG -fopenmp -g -Wall -march=native -msse -msse2 -msse3 -mssse3 -msse4 -ffast-math -mfpmath=sse")
+
+add_library(
+ mil_vision_lib
+ src/mil_vision_lib/cv_utils.cc
+ src/mil_vision_lib/image_filtering.cpp
+ src/mil_vision_lib/active_contours.cpp
+ src/mil_vision_lib/colorizer/pcd_colorizer.cpp
+ src/mil_vision_lib/colorizer/single_cloud_processor.cpp
+ src/mil_vision_lib/colorizer/camera_observer.cpp
+ src/mil_vision_lib/colorizer/color_observation.cpp
+)
+target_include_directories(mil_vision_lib PUBLIC include/mil_vision_lib)
+target_link_libraries(mil_vision_lib ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${PCL_COMMON_LIBRARIES} ${PCL_COMMON_LIBRARIES})
+
+add_executable(camera_stream_demo src/camera_stream_demo.cpp)
+add_dependencies(camera_stream_demo mil_vision_lib ${catkin_EXPORTED_TARGETS})
+target_link_libraries(
+ camera_stream_demo
+ mil_vision_lib
+ ${catkin_LIBRARIES}
+ ${Boost_LIBRARIES}
+ ${OpenCV_INCLUDE_DIRS}
+)
+
+add_executable(camera_lidar_transformer src/camera_lidar_transformer.cpp)
+add_dependencies(camera_lidar_transformer mil_vision_lib ${catkin_EXPORTED_TARGETS})
+target_link_libraries(
+ camera_lidar_transformer
+ mil_vision_lib
+ ${catkin_LIBRARIES}
+ ${Boost_LIBRARIES}
+ ${OpenCV_INCLUDE_DIRS}
+)
diff --git a/perception/mil_vision/exFAST_SparseStereo/GPL.txt b/perception/mil_vision/exFAST_SparseStereo/GPL.txt
new file mode 100644
index 00000000..94a9ed02
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/GPL.txt
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/perception/mil_vision/exFAST_SparseStereo/README.txt b/perception/mil_vision/exFAST_SparseStereo/README.txt
new file mode 100644
index 00000000..752d37c7
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/README.txt
@@ -0,0 +1,38 @@
+exFAST and High-Performance Sparse Stereo Matcher
+
+This source code is published under the GNU General Public License version 3,
+of which a copy is distributed with this code. Exempt from this license is the
+FAST9 detector (file: src/sparsestereo/fast9-inl.h), which was originally
+written by Edward Rosten and has only been modified by us.
+
+The source code makes heavy use of the GCC vector extensions to take advantage
+of the SSE instruction sets. Hence, the code cannot be complied with a
+different compiler without making major modifications.
+
+We included a simple example application that demonstrates how to use our code.
+Also included is one example stereo pair with a matching camera calibration
+file.
+
+Some notes about camera calibration: We use the OpenCV functions
+stereoCalibrate and stereoRectify to obtain the calibration and rectification
+data. The example application loads those settings from an XML file. The
+meaning of the individual data items is as follows:
+
+M1: Camera matrix of left camera (from stereoCalibrate)
+M2: Camera matrix of right camera (from steroCalibrate)
+D1: Distortion coefficients for left camera (from stereoCalibrate)
+D2: Distortion coefficients for right camera (from stereoCalibrate)
+R1: Rectification transformation for left camera (from stereoRectify)
+R2: Rectification transformation for right camera (from stereoRectify)
+P1: Projection matrix for left camera (from stereoRectify)
+P2: Projection matrix for right camera (from stereoRectify)
+Q: Disparity-to-depth mapping matrix (from stereoRectify)
+size: Image size of one camera image
+
+If you use our code for any research that will be published, we kindly ask you
+to cite our paper:
+
+Konstantin Schauwecker, Reinhard Klette, and Andreas Zell. A New Feature
+Detector and Stereo Matching Method for Accurate High-Performance Sparse Stereo
+Matching. In IEEE/RSJ International Conference on Intelligent Robots and
+Systems (IROS). IEEE, October 2012.
diff --git a/perception/mil_vision/exFAST_SparseStereo/example-data/calibration.xml b/perception/mil_vision/exFAST_SparseStereo/example-data/calibration.xml
new file mode 100644
index 00000000..ccb6f2c2
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/example-data/calibration.xml
@@ -0,0 +1,79 @@
+
+
+
+ 3
+ 3
+ d
+
+ 6.5241357652015370e+02 0. 3.4737478196748043e+02 0.
+ 6.5434070705887893e+02 2.2621555342556007e+02 0. 0. 1.
+
+ 1
+ 5
+ d
+
+ -4.3763636007329099e-01 2.8006488733035506e-01
+ 4.0981386272831622e-04 -1.1888413625068292e-03
+ -1.4136761880997478e-01
+
+ 3
+ 3
+ d
+
+ 6.5181248374572181e+02 0. 3.3187853747142810e+02 0.
+ 6.5339335949419046e+02 2.2968726339955754e+02 0. 0. 1.
+
+ 1
+ 5
+ d
+
+ -4.3932608881272195e-01 2.9797543665860654e-01
+ -4.7999780141084688e-04 -1.0480857219477820e-03
+ -1.6575380391655467e-01
+
+ 3
+ 3
+ d
+
+ 9.9964441516773250e-01 -5.8620392937120611e-03
+ 2.6013068240420170e-02 5.8033365360402080e-03 9.9998044230621075e-01
+ 2.3315853243672281e-03 -2.6026227329585080e-02
+ -2.1797936586566173e-03 9.9965888381517143e-01
+
+ 3
+ 3
+ d
+
+ 9.9993558455087461e-01 5.2798013266097798e-03
+ -1.0047409957402902e-02 -5.3024541086745978e-03
+ 9.9998345699189362e-01 -2.2292875470448703e-03
+ 1.0035473547670247e-02 2.2824198766964580e-03 9.9994703851263078e-01
+
+ 3
+ 4
+ d
+
+ 5.4581318104785521e+02 0. 3.3994384384155273e+02 0. 0.
+ 5.4581318104785521e+02 2.2540025138854980e+02 0. 0. 0. 1. 0.
+
+ 3
+ 4
+ d
+
+ 5.4581318104785521e+02 0. 3.3994384384155273e+02
+ -5.9573462113779023e+01 0. 5.4581318104785521e+02
+ 2.2540025138854980e+02 0. 0. 0. 1. 0.
+
+ 4
+ 4
+ d
+
+ 1. 0. 0. -3.3994384384155273e+02 0. 1. 0. -2.2540025138854980e+02 0.
+ 0. 0. 5.4581318104785521e+02 0. 0. -9.1620188198129178e+00 0.
+
+ 2
+ 1
+ i
+
+ 640 480
+
diff --git a/perception/mil_vision/exFAST_SparseStereo/example-data/left.png b/perception/mil_vision/exFAST_SparseStereo/example-data/left.png
new file mode 100644
index 00000000..0c5b9a18
Binary files /dev/null and b/perception/mil_vision/exFAST_SparseStereo/example-data/left.png differ
diff --git a/perception/mil_vision/exFAST_SparseStereo/example-data/right.png b/perception/mil_vision/exFAST_SparseStereo/example-data/right.png
new file mode 100644
index 00000000..dfdcd941
Binary files /dev/null and b/perception/mil_vision/exFAST_SparseStereo/example-data/right.png differ
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/example/example.cpp b/perception/mil_vision/exFAST_SparseStereo/src/example/example.cpp
new file mode 100644
index 00000000..4c6426eb
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/example/example.cpp
@@ -0,0 +1,144 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+// This is a minimalistic example on how to use the extended
+// FAST feature detector and the sparse stereo matcher.
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+using namespace cv;
+using namespace sparsestereo;
+using namespace boost;
+using namespace boost::posix_time;
+
+int main(int argc, char** argv) {
+ try {
+ // Stereo matching parameters
+ double uniqueness = 0.7;
+ int maxDisp = 70;
+ int leftRightStep = 2;
+
+ // Feature detection parameters
+ double adaptivity = 1.0;
+ int minThreshold = 10;
+
+ // Parse arguments
+ if(argc != 3 && argc != 4) {
+ cout << "Usage: " << argv[0] << " LEFT-IMG RIGHT-IMG [CALIBRARION-FILE]" << endl;
+ return 1;
+ }
+ char* leftFile = argv[1];
+ char* rightFile = argv[2];
+ char* calibFile = argc == 4 ? argv[3] : NULL;
+
+ // Read input images
+ cv::Mat_ leftImg, rightImg;
+ leftImg = imread(leftFile, CV_LOAD_IMAGE_GRAYSCALE);
+ rightImg = imread(rightFile, CV_LOAD_IMAGE_GRAYSCALE);
+
+ if(leftImg.data == NULL || rightImg.data == NULL)
+ throw sparsestereo::Exception("Unable to open input images!");
+
+ // Load rectification data
+ StereoRectification* rectification = NULL;
+ if(calibFile != NULL)
+ rectification = new StereoRectification(CalibrationResult(calibFile));
+
+ // The stereo matcher. SSE Optimized implementation is only available for a 5x5 window
+ SparseStereo, short> stereo(maxDisp, 1, uniqueness,
+ rectification, false, false, leftRightStep);
+
+ // Feature detectors for left and right image
+ FeatureDetector* leftFeatureDetector = new ExtendedFAST(true, minThreshold, adaptivity, false, 2);
+ FeatureDetector* rightFeatureDetector = new ExtendedFAST(false, minThreshold, adaptivity, false, 2);
+
+ ptime lastTime = microsec_clock::local_time();
+ vector correspondences;
+
+ // Objects for storing final and intermediate results
+ cv::Mat_ charLeft(leftImg.rows, leftImg.cols),
+ charRight(rightImg.rows, rightImg.cols);
+ Mat_ censusLeft(leftImg.rows, leftImg.cols),
+ censusRight(rightImg.rows, rightImg.cols);
+ vector keypointsLeft, keypointsRight;
+
+ // For performance evaluation we do the stereo matching 100 times
+ for(int i=0; i< 100; i++) {
+ // Featuredetection. This part can be parallelized with OMP
+ #pragma omp parallel sections default(shared) num_threads(2)
+ {
+ #pragma omp section
+ {
+ ImageConversion::unsignedToSigned(leftImg, &charLeft);
+ Census::transform5x5(charLeft, &censusLeft);
+ keypointsLeft.clear();
+ leftFeatureDetector->detect(leftImg, keypointsLeft);
+ }
+ #pragma omp section
+ {
+ ImageConversion::unsignedToSigned(rightImg, &charRight);
+ Census::transform5x5(charRight, &censusRight);
+ keypointsRight.clear();
+ rightFeatureDetector->detect(rightImg, keypointsRight);
+ }
+ }
+
+ // Stereo matching. Not parallelized (overhead too large)
+ correspondences.clear();
+ stereo.match(censusLeft, censusRight, keypointsLeft, keypointsRight, &correspondences);
+ }
+
+ // Print statistics
+ time_duration elapsed = (microsec_clock::local_time() - lastTime);
+ cout << "Time for 100x stereo matching: " << elapsed.total_microseconds()/1.0e6 << "s" << endl
+ << "Features detected in left image: " << keypointsLeft.size() << endl
+ << "Features detected in right image: " << keypointsRight.size() << endl
+ << "Percentage of matched features: " << (100.0 * correspondences.size() / keypointsLeft.size()) << "%" << endl;
+
+ // Highlight matches as colored boxes
+ Mat_ screen(leftImg.rows, leftImg.cols);
+ cvtColor(leftImg, screen, CV_GRAY2BGR);
+
+ for(int i=0; i<(int)correspondences.size(); i++) {
+ double scaledDisp = (double)correspondences[i].disparity() / maxDisp;
+ Vec3b color;
+ if(scaledDisp > 0.5)
+ color = Vec3b(0, (1 - scaledDisp)*512, 255);
+ else color = Vec3b(0, 255, scaledDisp*512);
+
+ rectangle(screen, correspondences[i].imgLeft->pt - Point2f(2,2),
+ correspondences[i].imgLeft->pt + Point2f(2, 2),
+ (Scalar) color, CV_FILLED);
+ }
+
+ // Display image and wait
+ namedWindow("Stereo");
+ imshow("Stereo", screen);
+ waitKey();
+
+ // Clean up
+ delete leftFeatureDetector;
+ delete rightFeatureDetector;
+ if(rectification != NULL)
+ delete rectification;
+
+ return 0;
+ }
+ catch (const std::exception& e) {
+ cerr << "Fatal exception: " << e.what();
+ return 1;
+ }
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/CMakeLists.txt b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/CMakeLists.txt
new file mode 100644
index 00000000..e57cf787
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/CMakeLists.txt
@@ -0,0 +1,26 @@
+add_library(sparsestereo
+ calibrationresult.h
+ calibrationresult.cpp
+ censuswindow.h
+ exception.h
+ extendedfast.cpp
+ extendedfast.h
+ fast9.h
+ fast9-inl.h
+ hammingdistance.cpp
+ hammingdistance.h
+ simd.h
+ simd.cpp
+ sparsematch.h
+ sparserectification.cpp
+ sparserectification.h
+ sparsestereo.h
+ sparsestereo-inl.h
+ stereorectification.cpp
+ stereorectification.h
+ imageconversion.h
+ imageconversion.cpp
+ census.h
+ census-inl.h
+ census.cpp
+)
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/calibrationresult.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/calibrationresult.cpp
new file mode 100644
index 00000000..8f64530e
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/calibrationresult.cpp
@@ -0,0 +1,55 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "calibrationresult.h"
+#include
+#include "exception.h"
+
+namespace sparsestereo {
+ using namespace cv;
+ using namespace std;
+
+ CalibrationResult::CalibrationResult(const char* file) {
+ FileStorage fs(file, CV_STORAGE_READ);
+ if(!fs.isOpened())
+ throw Exception("Unable to read calibration results");
+
+ fs["M1"] >> cameraMatrix[0];
+ fs["D1"] >> distCoeffs[0];
+ fs["M2"] >> cameraMatrix[1];
+ fs["D2"] >> distCoeffs[1];
+ fs["R1"] >> R[0];
+ fs["R2"] >> R[1];
+ fs["P1"] >> P[0];
+ fs["P2"] >> P[1];
+ fs["Q"] >> Q;
+ fs["T"] >> T;
+
+ Mat_ sz(2, 1);
+ fs["size"] >> sz;
+ imageSize.width = sz(0, 0);
+ imageSize.height = sz(1, 0);
+
+ fs.release();
+ }
+
+ void CalibrationResult::writeToFile(const char * file) const {
+ FileStorage fs(file, CV_STORAGE_WRITE);
+ if(!fs.isOpened())
+ throw Exception("Unable to store calibration results");
+
+ fs << "M1" << cameraMatrix[0] << "D1" << distCoeffs[0]
+ << "M2" << cameraMatrix[1] << "D2" << distCoeffs[1]
+ << "R1" << R[0] << "R2" << R[1] << "P1" << P[0] << "P2" << P[1] << "Q" << Q
+ << "T" << T;
+
+ Mat_ sz(2, 1);
+ sz(0, 0) = imageSize.width;
+ sz(1, 0) = imageSize.height;
+ fs << "size" << sz;
+
+ fs.release();
+ }
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/calibrationresult.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/calibrationresult.h
new file mode 100644
index 00000000..872aa787
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/calibrationresult.h
@@ -0,0 +1,28 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_CALIBRATIONRESULT_H
+#define SPARSESTEREO_CALIBRATIONRESULT_H
+
+#include
+
+namespace sparsestereo {
+ // Stores the results of a stereo camera calibration
+ struct CalibrationResult {
+ cv::Mat_ cameraMatrix[2], distCoeffs[2];
+ cv::Mat_ R[2], P[2], Q, T;
+ cv::Size imageSize;
+
+ CalibrationResult() {
+ cameraMatrix[0] = cv::Mat_::eye(3, 3);
+ cameraMatrix[1] = cv::Mat_::eye(3, 3);
+ }
+ CalibrationResult(const char* file);
+
+ void writeToFile(const char* file) const;
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/census-inl.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/census-inl.h
new file mode 100644
index 00000000..d22e3839
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/census-inl.h
@@ -0,0 +1,59 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_CENSUS_INL_H
+#define SPARSESTEREO_CENSUS_INL_H
+
+#include "exception.h"
+#include "census.h"
+
+namespace sparsestereo {
+ template
+ void Census::transform5x5(const cv::Mat_& input, cv::Mat_* output) {
+ int maxX=input.cols-2, maxY=input.rows-2;
+
+ for(int y=2; y input(y-2, x-2)) << 24) |
+ ((centoid > input(y-2, x-1)) << 23) |
+ ((centoid > input(y-2, x)) << 22) |
+ ((centoid > input(y-2, x+1)) << 21) |
+ ((centoid > input(y-2, x+2)) << 20) |
+ // Row 2
+ ((centoid > input(y-1, x-2)) << 19) |
+ ((centoid > input(y-1, x-1)) << 18) |
+ ((centoid > input(y-1, x)) << 17) |
+ ((centoid > input(y-1, x+1)) << 16) |
+ ((centoid > input(y-1, x+2)) <<15) |
+ // Row 3
+ ((centoid > input(y, x-2)) << 14) |
+ ((centoid > input(y, x-1)) << 13) |
+ ((centoid > input(y, x)) << 12) |
+ ((centoid > input(y, x+1)) << 11) |
+ ((centoid > input(y, x+2)) << 10) |
+ // Row 4
+ ((centoid > input(y+1, x-2)) << 9) |
+ ((centoid > input(y+1, x-1)) << 8) |
+ ((centoid > input(y+1, x)) << 7) |
+ ((centoid > input(y+1, x+1)) << 6) |
+ ((centoid > input(y+1, x+2)) << 5) |
+ // Row 5
+ ((centoid > input(y+2, x-2)) << 4) |
+ ((centoid > input(y+2, x-1)) << 3) |
+ ((centoid > input(y+2, x)) << 2) |
+ ((centoid > input(y+2, x+1)) << 1) |
+ (centoid > input(y+2, x+2));
+ }
+ }
+
+ template <>
+ void Census::transform5x5(const cv::Mat_& input, cv::Mat_* output);
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/census.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/census.cpp
new file mode 100644
index 00000000..0bbab689
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/census.cpp
@@ -0,0 +1,109 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "census-inl.h"
+
+namespace sparsestereo {
+ using namespace std;
+ using namespace cv;
+
+ template <>
+ void Census::transform5x5(const Mat_& input, Mat_* output) {
+ transform5x5SSE(input, output);
+ }
+
+ void Census::transform5x5SSE(const Mat_& input, Mat_* output) {
+ // Predeclare required constants
+ const v16qi const01 = SIMD::scalar16(0x01);
+
+ // We skip one row at the beginning and end to avoid range checking
+ for(int y=2; y
+#include "simd.h"
+
+namespace sparsestereo {
+ // Computes various variants of the census transform
+ class Census {
+ public:
+ // Census transform using 5x5 window
+ template
+ static void transform5x5(const cv::Mat_& input, cv::Mat_* output);
+
+ private:
+ // SSE optimized implementations
+ static void transform5x5SSE(const cv::Mat_& input, cv::Mat_* output);
+
+ // Efficiently stores 4 byte blocks by interleaving four 1-byte vectors
+ static __always_inline void storeSSEVec(const v16qi& byte4, const v16qi& byte3, const v16qi& byte2,
+ const v16qi& byte1, char* dst);
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/censuswindow.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/censuswindow.h
new file mode 100644
index 00000000..9ce555c0
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/censuswindow.h
@@ -0,0 +1,237 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_CENSUSWINDOW_H
+#define SPARSESTEREO_CENSUSWINDOW_H
+
+#include
+#include
+#include "hammingdistance.h"
+#include "simd.h"
+
+//#define SPARSESTEREO_NO_POPCNT //Defined by CMake
+
+#if defined(SPARSESTEREO_NO_POPCNT)
+#define SPARSESTEREO_SSE_OPTIMIZE
+#endif
+
+namespace sparsestereo {
+ // Matches over a set of census windows
+ template
+ class CensusWindow {
+ public:
+ CensusWindow() {
+#ifdef SPARSESTEREO_SSE_OPTIMIZE
+ lookupTablePtr = hammingDist.getLookupTable();
+ lookupTableVec = SIMD::scalar4((int)hammingDist.getLookupTable());
+ zero = SIMD::scalar16(0);
+#endif
+ }
+
+ void setReferenceImage(const cv::Mat_& image) {
+ refImage = image;
+ }
+
+ void setComparisonImage(const cv::Mat_& image) {
+ compImage = image;
+ }
+
+ const cv::Mat_& getReferenceImage() const {return refImage;}
+ const cv::Mat_& getComparisonImage() const {return compImage;}
+ const int getWindowSize() const {return SIZE;}
+
+ // Sets the position of the reference window
+ void setReferencePoint(const cv::Point2i& point);
+
+ // Performs a window matching using census transformed images
+ __always_inline short match(cv::Point2i point) const;
+
+ private:
+ v4si lookupTableVec;
+ v4si refWindow[6];
+ v16qi zero;
+
+ const unsigned char* lookupTablePtr;
+ HammingDistance hammingDist;
+ cv::Mat_ refImage;
+ cv::Mat_ compImage;
+ cv::Point2i refPoint;
+
+ // Stores a window in two SSE vectors
+ void loadWindow(const cv::Mat_& image, const cv::Point2i& point, v4si* dstWindow) const;
+ } __attribute__ ((aligned (16)));
+
+ template
+ void CensusWindow::loadWindow(const cv::Mat_& image, const cv::Point2i& point, v4si* dstWindow) const {}
+
+#ifdef SPARSESTEREO_SSE_OPTIMIZE
+ template <>
+ void CensusWindow<5>::loadWindow(const cv::Mat_& image, const cv::Point2i& point, v4si* dstWindow) const {
+ dstWindow[0] = (v4si)__builtin_ia32_loaddqu((char*)&image(point.y-2, point.x-2));
+ dstWindow[1] = (v4si)__builtin_ia32_loaddqu((char*)&image(point.y-1, point.x-2));
+ dstWindow[2] = (v4si)__builtin_ia32_loaddqu((char*)&image(point.y, point.x-2));
+ dstWindow[3] = (v4si)__builtin_ia32_loaddqu((char*)&image(point.y+1, point.x-2));
+ dstWindow[4] = (v4si)__builtin_ia32_loaddqu((char*)&image(point.y+2, point.x-2));
+
+ // Unfortunately, the rest cannot be loaded aligned
+ v4si buffer = {image(point.y-2, point.x+2), image(point.y-1, point.x+2), image(point.y, point.x+2), image(point.y+1, point.x+2)};
+ dstWindow[5] = buffer;
+ }
+#endif
+
+ template
+ void CensusWindow::setReferencePoint(const cv::Point2i& point) {
+ refPoint = point;
+ }
+
+#ifdef SPARSESTEREO_SSE_OPTIMIZE
+ template <>
+ void CensusWindow<5>::setReferencePoint(const cv::Point2i& point) {
+ loadWindow(refImage, point, refWindow);
+ }
+#endif
+
+ template
+ __always_inline short CensusWindow::match(cv::Point2i point) const {
+ int costs = 0;
+
+#ifndef SPARSESTEREO_NO_POPCNT
+ for(int y=-SIZE/2; y<=SIZE/2; y++) {
+ unsigned long long* ptr1 = (unsigned long long*)&refImage(refPoint.y + y, refPoint.x -SIZE/2);
+ unsigned long long* ptr2 = (unsigned long long*)&compImage(point.y + y, point.x -SIZE/2);
+
+ for(int x=0; x<=SIZE/2;x++)
+ costs += __builtin_popcountll(ptr1[x] ^ ptr2[x]);
+ }
+#else
+ for(int y=-SIZE/2; y<=SIZE/2; y++)
+ for(int x=-SIZE/2; x<=SIZE/2; x++)
+ costs += hammingDist.calculate(refImage(refPoint.y + y, refPoint.x + x),
+ compImage(point.y + y, point.x + x));
+#endif
+
+ return costs;
+ }
+
+#ifdef SPARSESTEREO_SSE_OPTIMIZE
+#ifdef __LP64__
+ // SSE2 optimized implementation for 64-bit systems.
+ template <>
+ __always_inline short CensusWindow<5>::match(cv::Point2i point) const {
+ v8hi xorRes;
+ unsigned int sum;
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y-2, point.x-2)), (v2di)refWindow[0]);
+ sum = lookupTableVec[(unsigned short)SIMD::element8(xorRes, 0)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 1)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 2)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 3)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 4)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 5)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 6)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 7)];
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y-1, point.x-2)), (v2di)refWindow[1]);
+ sum += lookupTableVec[(unsigned short)SIMD::element8(xorRes, 0)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 1)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 2)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 3)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 4)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 5)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 6)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 7)];
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y, point.x-2)), (v2di)refWindow[2]);
+ sum += lookupTableVec[(unsigned short)SIMD::element8(xorRes, 0)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 1)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 2)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 3)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 4)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 5)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 6)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 7)];
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y+1, point.x-2)), (v2di)refWindow[3]);
+ sum += lookupTableVec[(unsigned short)SIMD::element8(xorRes, 0)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 1)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 2)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 3)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 4)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 5)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 6)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 7)];
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y+2, point.x-2)), (v2di)refWindow[4]);
+ sum += lookupTableVec[(unsigned short)SIMD::element8(xorRes, 0)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 1)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 2)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 3)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 4)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 5)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 6)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 7)];
+
+ v4si buffer1 = {compImage(point.y-2, point.x+2), compImage(point.y-1, point.x+2), compImage(point.y, point.x+2), compImage(point.y+1, point.x+2)};
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)buffer1, (v2di)refWindow[5]);
+ sum += lookupTableVec[(unsigned short)SIMD::element8(xorRes, 0)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 1)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 2)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 3)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 4)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 5)]
+ + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 6)] + lookupTableVec[(unsigned short)SIMD::element8(xorRes, 7)];
+
+ unsigned short lastXor = compImage(point.y+2, point.x+2) ^ refImage(refPoint.y + 2, refPoint.x+2);
+ sum += lookupTablePtr[(unsigned short)lastXor] + lookupTablePtr[((unsigned short*)&lastXor)[1]];
+
+ return sum;
+ }
+
+#else
+
+ // SSE2 optimized implementation for 32-bit systems.
+ template <>
+ __always_inline short CensusWindow<5>::match(cv::Point2i point) const {
+
+ v8hi xorRes;
+ v4si lookupPtr;
+ unsigned int sum;
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y-2, point.x-2)), (v2di)refWindow[0]);
+ lookupPtr = (v4si)__builtin_ia32_punpcklwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum = *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+ lookupPtr = (v4si)__builtin_ia32_punpckhwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y-1, point.x-2)), (v2di)refWindow[1]);
+ lookupPtr = (v4si)__builtin_ia32_punpcklwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+ lookupPtr = (v4si)__builtin_ia32_punpckhwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y, point.x-2)), (v2di)refWindow[2]);
+ lookupPtr = (v4si)__builtin_ia32_punpcklwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+ lookupPtr = (v4si)__builtin_ia32_punpckhwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y+1, point.x-2)), (v2di)refWindow[3]);
+ lookupPtr = (v4si)__builtin_ia32_punpcklwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+ lookupPtr = (v4si)__builtin_ia32_punpckhwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)__builtin_ia32_loaddqu((char*)&compImage(point.y+2, point.x-2)), (v2di)refWindow[4]);
+ lookupPtr = (v4si)__builtin_ia32_punpcklwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+ lookupPtr = (v4si)__builtin_ia32_punpckhwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+
+ v4si buffer1 = {compImage(point.y-2, point.x+2), compImage(point.y-1, point.x+2), compImage(point.y, point.x+2), compImage(point.y+1, point.x+2)};
+ xorRes = (v8hi)__builtin_ia32_pxor128((v2di)buffer1, (v2di)refWindow[5]);
+ lookupPtr = (v4si)__builtin_ia32_punpcklwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+ lookupPtr = (v4si)__builtin_ia32_punpckhwd128(xorRes, (v8hi)zero) + lookupTableVec;
+ sum += *((unsigned char*)SIMD::element4(lookupPtr, 0)) + *((unsigned char*)SIMD::element4(lookupPtr, 1))
+ + *((unsigned char*)SIMD::element4(lookupPtr, 2)) + *((unsigned char*)SIMD::element4(lookupPtr, 3));
+
+ unsigned short lastXor = compImage(point.y+2, point.x+2) ^ refImage(refPoint.y + 2, refPoint.x+2);
+ sum += lookupTablePtr[(unsigned short)lastXor] + lookupTablePtr[((unsigned short*)&lastXor)[1]];
+
+ return sum;
+ }
+#endif
+#endif
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/exception.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/exception.h
new file mode 100644
index 00000000..89330d9f
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/exception.h
@@ -0,0 +1,29 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_EXCEPTION_H
+#define SPARSESTEREO_EXCEPTION_H
+
+#include
+#include
+
+namespace sparsestereo {
+ // Base class for all exceptions
+ class Exception: public std::exception {
+ public:
+ Exception(const char* msg)
+ : message(msg) {}
+ Exception(std::string msg)
+ : message(msg) {}
+ ~Exception() throw() {}
+
+ virtual const char* what() const throw()
+ {return message.c_str();}
+
+ private:
+ std::string message;
+ };
+}
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast-inl.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast-inl.h
new file mode 100644
index 00000000..db816ee1
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast-inl.h
@@ -0,0 +1,47 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "extendedfast.h"
+
+namespace sparsestereo {
+
+ template
+ __always_inline v16qi ExtendedFAST::loadCircleSSE(const cv::Mat_& input, int x, int y) {
+ const char* center = (const char*)&(input(y, x));
+
+ v16qi circle = {*(center + offsets[0]), *(center + offsets[1]), *(center + offsets[2]), *(center + offsets[3]),
+ *(center + offsets[4]), *(center + offsets[5]), *(center + offsets[6]), *(center + offsets[7]),
+ *(center + offsets[8]), *(center + offsets[9]), *(center + offsets[10]), *(center + offsets[11]),
+ *(center + offsets[12]), *(center + offsets[13]), *(center + offsets[14]), *(center + offsets[15])
+ };
+
+ return circle;
+ }
+
+ // Tests for a feature and optionally stores the score
+ __always_inline bool ExtendedFAST::testFeatureAndScore(const cv::Mat_& input, const cv::Point2i pt, bool storeScore) {
+ // Calculate the adaptive threshold by computing an RMS contrast
+ // like measure based on absolute values
+ v16qi uCircle = loadCircleSSE(input, (int)pt.x, (int)pt.y);
+ v16qi circle = uCircle - const128;
+ v2di partialSum = __builtin_ia32_psadbw128(uCircle, const0);
+ int sum = SIMD::element2(partialSum, 0) + SIMD::element2(partialSum, 1);
+ v16qi avg = SIMD::scalar16(sum/16);
+
+ v2di partialSAD = __builtin_ia32_psadbw128(uCircle, avg);
+ int sad = SIMD::element2(partialSAD, 0) + SIMD::element2(partialSAD, 1);
+ unsigned char adaptiveThreshold = cv::saturate_cast(sad * adaptivity / 16);
+ v16qi adaptiveThresholdVec = SIMD::scalar16(adaptiveThreshold);
+
+ // Perform corner test
+ v16qi center = SIMD::scalar16(SPARSESTEREO_EXFAST_CENTRAL_VALUE(input, (int)pt.y, (int)pt.x) - 128);
+ if(detectSingleCornerSSE(circle, center, adaptiveThresholdVec, 9)) {
+ if(storeScore) // We have to calculate a corner score
+ scores.push_back(calcSingleScoreSSE(circle, center, adaptiveThresholdVec, 9) - adaptiveThreshold);
+ return true;
+ }
+ else return false;
+ }
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast.cpp
new file mode 100644
index 00000000..3378a76a
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast.cpp
@@ -0,0 +1,232 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include
+#include
+#include "extendedfast.h"
+#include "fast9-inl.h"
+#include "exception.h"
+
+namespace sparsestereo {
+ using namespace cv;
+ using namespace std;
+
+ const v16qi ExtendedFAST::const0(SIMD::scalar16NonLookup(0));
+ const v16qi ExtendedFAST::const128(SIMD::scalar16NonLookup(128));
+ const v16qi ExtendedFAST::const255(SIMD::scalar16NonLookup(255));
+
+ // Longest arc length lookup table
+ unsigned char ExtendedFAST::lookupTable[1U<<16];
+ bool ExtendedFAST::lookupInitialized = false;
+
+ ExtendedFAST::ExtendedFAST(bool nonmaxSuppression, unsigned char minThreshold, float adaptivity, bool subpixelPrecision, int minBorder)
+ : nonmaxSuppression(nonmaxSuppression), minThreshold(minThreshold), adaptivity(adaptivity), subpixelPrecision(subpixelPrecision) {
+ const int reserve = 512;
+ cornersMin.reserve(reserve); cornersAdapt.reserve(reserve); scores.reserve(reserve);
+
+ if(!lookupInitialized) {
+ // The first instance initializes the lookup table.
+ // Should be threadsafe as we always write the same values and set the
+ // initialization flag last.
+ for(int i=0; i<=0xFFFF; i++)
+ lookupTable[i] = findLongestArc(i) >= 9 ? 0xFF : 0;
+ lookupInitialized = true;
+ }
+ }
+
+ ExtendedFAST::~ExtendedFAST() {
+ }
+
+ inline unsigned char ExtendedFAST::findLongestArc(unsigned short stripe) {
+ int bestLength = 0;
+ int startLength = -1;
+ int currentLength = 0;
+
+ // We iterate over all possible 16-bit permutations
+ for(int i=1; i<0xFFFF; i = i<<1) {
+ if(stripe & i)
+ // Inside an arc segment
+ currentLength++;
+ else {
+ // Outside an arc segment
+ if(currentLength > bestLength)
+ bestLength = currentLength;
+ if(startLength == -1)
+ startLength = currentLength;
+ currentLength = 0;
+ }
+ }
+
+ // wrap-around case
+ if(startLength != -1)
+ currentLength += startLength;
+
+ // Handle last arc segment
+ if(currentLength > bestLength)
+ bestLength = currentLength;
+
+ return bestLength;
+ }
+
+ void ExtendedFAST::initOffsets(int step) {
+ offsets[0] = step*-3 -1;
+ offsets[1] = step*-3;
+ offsets[2] = step*-3 +1;
+ offsets[3] = step*-2 +2;
+ offsets[4] = step*-1 +3;
+ offsets[5] = +3;
+ offsets[6] = step +3;
+ offsets[7] = step*+2 +2;
+ offsets[8] = step*+3 +1;
+ offsets[9] = step*+3;
+ offsets[10] = step*+3 -1;
+ offsets[11] = step*+2 -2;
+ offsets[12] = step*+1 -3; //Aligned
+ offsets[13] = -3; //Aligned
+ offsets[14] = step*-1 -3; //Aligned
+ offsets[15] = step*-2 -2;
+ }
+
+ void ExtendedFAST::detectImpl(const Mat& image, vector& keypoints, const Mat& mask) {
+
+ if(mask.data != NULL)
+ throw Exception("Feature detection masks not supported!");
+ else if(image.type() != CV_8U)
+ throw Exception("Image data has to be of type unsigned char!");
+
+ // Create offsets for circle pixel
+ initOffsets(image.step);
+
+ FAST(image, cornersMin, minThreshold, false);
+ adaptiveThresholdAndScore(image);
+
+ if(nonmaxSuppression)
+ {
+ // Perform nonmax suppression
+ vector nonmaxPoints;
+ fast9.nonMaxSuppression(cornersAdapt, scores, nonmaxPoints);
+
+ // Copy and optionally refine result
+ keypoints.reserve(nonmaxPoints.size());
+ for(unsigned int i=0; i& input) {
+ initOffsets((int)input.step);
+ for(unsigned int i=0; i& input, int x, int y) {
+ const char* center = (const char*)&(input(y, x));
+
+ v16qi circle = {*(center + offsets[0]), *(center + offsets[1]), *(center + offsets[2]), *(center + offsets[3]),
+ *(center + offsets[4]), *(center + offsets[5]), *(center + offsets[6]), *(center + offsets[7]),
+ *(center + offsets[8]), *(center + offsets[9]), *(center + offsets[10]), *(center + offsets[11]),
+ *(center + offsets[12]), *(center + offsets[13]), *(center + offsets[14]), *(center + offsets[15])
+ };
+
+ return circle;
+ }
+
+ __always_inline bool ExtendedFAST::testFeatureAndScore(const cv::Mat_& input, const cv::Point2i pt, bool storeScore) {
+ // Calculate the adaptive threshold by computing an RMS contrast
+ // like measure based on absolute values
+ v16qi uCircle = loadCircleSSE(input, (int)pt.x, (int)pt.y);
+ v16qi circle = uCircle - const128;
+ v2di partialSum = __builtin_ia32_psadbw128(uCircle, const0);
+ int sum = SIMD::element2(partialSum, 0) + SIMD::element2(partialSum, 1);
+ v16qi avg = SIMD::scalar16(sum/16);
+
+ v2di partialSAD = __builtin_ia32_psadbw128(uCircle, avg);
+ int sad = SIMD::element2(partialSAD, 0) + SIMD::element2(partialSAD, 1);
+ unsigned char adaptiveThreshold = cv::saturate_cast(sad * adaptivity / 16);
+ v16qi adaptiveThresholdVec = SIMD::scalar16(adaptiveThreshold);
+
+ // Perform corner test
+ v16qi center = SIMD::scalar16(SPARSESTEREO_EXFAST_CENTRAL_VALUE(input, (int)pt.y, (int)pt.x) - 128);
+ if(detectSingleCornerSSE(circle, center, adaptiveThresholdVec, 9)) {
+ if(storeScore) // We have to calculate a corner score
+ scores.push_back(calcSingleScoreSSE(circle, center, adaptiveThresholdVec, 9) - adaptiveThreshold);
+ return true;
+ }
+ else return false;
+ }
+
+ __always_inline bool ExtendedFAST::detectSingleCornerSSE(const v16qi& circle, const v16qi& center, const v16qi& threshold,
+ unsigned char minLength) {
+
+ // Find longest brighter arc
+ v16qi centersPlus = __builtin_ia32_paddsb128(center, threshold);
+ int arcBrighter = __builtin_ia32_pmovmskb128(__builtin_ia32_pcmpgtb128(circle, centersPlus));
+
+ if(lookupTable[arcBrighter] >= minLength)
+ return true;
+ else {
+ // Find longest darker arc
+ v16qi centersMinus = __builtin_ia32_psubsb128(center, threshold);
+ int arcDarker = __builtin_ia32_pmovmskb128(__builtin_ia32_pcmpgtb128(centersMinus, circle));
+ if(lookupTable[arcDarker] >= minLength)
+ return true;
+ }
+
+ return false;
+ }
+
+ __always_inline unsigned char ExtendedFAST::calcSingleScoreSSE(const v16qi& circle, v16qi center, const v16qi& bstartVec,
+ unsigned char minLength) {
+
+ v16qi bmin = bstartVec;
+ v16qi bmax = const255;
+ v16qi b = __builtin_ia32_pavgb128 (bmax, bmin);
+ center += const128;
+
+ //Compute the score using binary search
+ for(;;)
+ {
+ // Find brighter arc
+ v16qi centerPlus = __builtin_ia32_paddusb128(center, b) - const128;
+ int arcBrighter = __builtin_ia32_pmovmskb128(__builtin_ia32_pcmpgtb128(circle, centerPlus));
+
+ if(lookupTable[arcBrighter] >= minLength)
+ bmin = b; // corner
+ else {
+ // Find darker arc
+ v16qi centerMinus = __builtin_ia32_psubusb128(center, b) - const128;
+ int arcDarker = __builtin_ia32_pmovmskb128(__builtin_ia32_pcmpgtb128(centerMinus, circle));
+ if(lookupTable[arcDarker] >= minLength)
+ bmin = b; // corner
+ else
+ bmax = b; // Not a corner
+ }
+
+ unsigned char singleBMin = SIMD::element16(bmin, 0), singleBMax = SIMD::element16(bmax, 0);
+ if(singleBMin == singleBMax || singleBMin == singleBMax - 1)
+ return (unsigned char)SIMD::element16(bmin, 0);
+
+ // Update threshold
+ b = __builtin_ia32_pavgb128 (bmax, bmin);
+ }
+ }
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast.h
new file mode 100644
index 00000000..7136ab51
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/extendedfast.h
@@ -0,0 +1,77 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_EXTENDEDFAST_H
+#define SPARSESTEREO_EXTENDEDFAST_H
+
+#include
+#include
+#include
+#include "simd.h"
+#include "fast9.h"
+
+namespace sparsestereo {
+
+//#define SPARSESTEREO_EXFAST_CENTRAL_VALUE(img, y, x) img(y, x)
+#define SPARSESTEREO_EXFAST_CENTRAL_VALUE(img, y, x) (((int)img(y, x) + (int)img(y-1, x) + (int)img(y+1, x) + (int)img(y, x-1) + (int)img(y, x+1))/5)
+
+ // Extended version of the fast feature detector
+ class ExtendedFAST: public cv::FeatureDetector {
+ public:
+ ExtendedFAST(bool nonmaxSuppression, unsigned char minThreshold, float adaptivity, bool subpixelPrecision, int minBorder = 0);
+ virtual ~ExtendedFAST();
+
+ protected:
+ // Implements the feature detector interface
+ virtual void detectImpl(const cv::Mat& image, std::vector& keypoints, const cv::Mat& mask=cv::Mat()) const {
+ // OpenCV tries to force this method to be const, but we don't like that!
+ const_cast(this)->detectImpl(image, keypoints, mask);
+ }
+ void detectImpl(const cv::Mat& image, std::vector& keypoints, const cv::Mat& mask=cv::Mat());
+
+ private:
+ // Constants for SSE processing
+ static const v16qi const0, const128, const255;
+
+ bool nonmaxSuppression;
+ // Adaptive threshold parameteres
+ unsigned char minThreshold;
+ unsigned char maxThreshold;
+ float adaptivity;
+ bool subpixelPrecision;
+ int border;
+ FAST9 fast9;
+
+ // Feature point data
+ std::vector cornersAdapt;
+ std::vector cornersMin;
+ std::vector scores;
+
+ // Offsets for the circle pixel
+ int offsets[16];
+ // Lookup table for longest arc lengths
+ static unsigned char lookupTable[1U<<16];
+ static bool lookupInitialized;
+
+ // Finds the longest arc for a given comparison pattern
+ inline unsigned char findLongestArc(unsigned short stripe);
+ // Initializes offsets for corner detection
+ void initOffsets(int step);
+ // Loads 16 circle pixels into one SSE vector
+ __always_inline v16qi loadCircleSSE(const cv::Mat_& input, int x, int y);
+ // Performs feature test and score calculation
+ __always_inline bool testFeatureAndScore(const cv::Mat_& input, const cv::Point2i pt, bool storeScore);
+ // Performs a corner detection using the circle pixels from an SSE vector
+ __always_inline bool detectSingleCornerSSE(const v16qi& circle, const v16qi& center, const v16qi& threshold,
+ unsigned char minLength);
+ // Performs a score calculation using the circle pixels from an SSE vector
+ __always_inline unsigned char calcSingleScoreSSE(const v16qi& circle, v16qi center, const v16qi& bstartVec,
+ unsigned char minLength);
+ // Applies the adaptive threshold to cornersMin, and calculates the score
+ void adaptiveThresholdAndScore(const cv::Mat_& input);
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/fast9-inl.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/fast9-inl.h
new file mode 100644
index 00000000..ada45d04
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/fast9-inl.h
@@ -0,0 +1,6016 @@
+// This code is based on the original FAST corner detector by Edward Rosten.
+// Below is the original copyright and references
+
+/*
+Copyright (c) 2006, 2008 Edward Rosten
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ *Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ *Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ *Neither the name of the University of Cambridge nor the names of
+ its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+The references are:
+ * Machine learning for high-speed corner detection,
+ E. Rosten and T. Drummond, ECCV 2006
+ * Faster and better: A machine learning approach to corner detection
+ E. Rosten, R. Porter and T. Drummond, PAMI, 2009
+*/
+
+#ifndef SPARSESTEREO_FAST9_INL_H
+#define SPARSESTEREO_FAST9_INL_H
+
+#include "fast9.h"
+
+namespace sparsestereo {
+ template
+ const int FAST9::pixelOffsetsX[16] = {0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1};
+
+ template
+ const int FAST9::pixelOffsetsY[16] = {3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1, 0, 1, 2, 3};
+
+ template
+ FAST9::FAST9():step(-1) {
+ setStep(640);
+ }
+
+ template
+ void FAST9::setStep(int s) {
+ if(s == step)
+ return; // noting changed
+
+ step = s;
+ for(int i=0; i<16; i++)
+ pixel[i] = pixelOffsetsX[i] + step * pixelOffsetsY[i];
+ }
+
+ /* This defines non-strict maxima */
+#define SPARSESTEREO_NONMAX_COMPARE(X, Y) ((X)>=(Y))
+
+ /* This is a fast, integer only, sparse nonmaximal suppression. */
+ /* probably only useful for FAST corner detection */
+ template template
+ void FAST9::nonMaxSuppression(const std::vector& corners, const std::vector& scores, std::vector& ret_nonmax) const {
+ int i, j, num_corners = (int)corners.size();
+
+ // Point above points (roughly) to the pixel above the one of interest, if there is a feature there.
+ int point_above = 0;
+ int point_below = 0;
+
+ ret_nonmax.clear();
+ if(num_corners < 1)
+ return;
+
+ /* Find where each row begins
+ (the corners are output in raster scan order). A beginning of -1 signifies
+ that there are no corners on that row. */
+ int last_row = corners[num_corners-1].y;
+ std::vector row_start(last_row+1);
+
+ for(i=0; i < last_row+1; i++)
+ row_start[i] = -1;
+
+ int prev_row = -1;
+ for(i=0; i< num_corners; i++)
+ if(corners[i].y != prev_row)
+ {
+ row_start[corners[i].y] = i;
+ prev_row = corners[i].y;
+ }
+
+
+ ret_nonmax.reserve(num_corners);
+ for(i = 0; i < num_corners; i++) {
+
+ T2 score = scores[i];
+ cv::Point pos = corners[i];
+
+ // Check left
+ if(i > 0 && corners[i-1].x == pos.x-1 && corners[i-1].y == pos.y) {
+ if(SPARSESTEREO_NONMAX_COMPARE(scores[i-1], score))
+ continue;
+ }
+
+ // Check right
+ if(i < num_corners-1 && corners[i+1].x == pos.x+1 && corners[i+1].y == pos.y) {
+ if(SPARSESTEREO_NONMAX_COMPARE(scores[i+1], score))
+ continue;
+ }
+
+ bool suppressed = false;
+ // Check above (if there is a valid row above)
+ if(pos.y != 0 && row_start[pos.y - 1] != -1) {
+ // Make sure that current point_above is one row above.
+ if(corners[point_above].y < pos.y - 1)
+ point_above = row_start[pos.y-1];
+
+ // Make point_above point to the first of the pixels above the current point, if it exists.
+ for(; corners[point_above].y < pos.y && corners[point_above].x < pos.x - 1; point_above++)
+ ;
+
+ for(j=point_above; corners[j].y < pos.y && corners[j].x <= pos.x + 1; j++) {
+ int x = corners[j].x;
+ if( (x == pos.x - 1 || x ==pos.x || x == pos.x+1)) {
+ if(SPARSESTEREO_NONMAX_COMPARE(scores[j], score)) {
+ suppressed = true;
+ break;
+ }
+ }
+ }
+ if( suppressed )
+ continue;
+ }
+
+ // Check below (if there is anything below)
+ if(pos.y != last_row && row_start[pos.y + 1] != -1 && point_below < num_corners) { // Nothing below
+ if(corners[point_below].y < pos.y + 1)
+ point_below = row_start[pos.y+1];
+
+ // Make point below point to one of the pixels belowthe current point, if it exists.
+ for(; point_below < num_corners && corners[point_below].y == pos.y+1
+ && corners[point_below].x < pos.x - 1; point_below++)
+ ;
+
+ for(j=point_below; j < num_corners && corners[j].y == pos.y+1 && corners[j].x <= pos.x + 1; j++) {
+ int x = corners[j].x;
+ if( (x == pos.x - 1 || x ==pos.x || x == pos.x+1)) {
+ if(SPARSESTEREO_NONMAX_COMPARE(scores[j],score)) {
+ suppressed = true;
+ break;
+ }
+ }
+ }
+ if( suppressed )
+ continue;
+ }
+
+ ret_nonmax.push_back(i);
+ }
+ }
+
+ template
+ int FAST9::cornerScore(const T* p, T c, int bstart) const {
+ int bmin = bstart;
+ int bmax = 255;
+ int b = (bmax + bmin)/2;
+
+ /*Compute the score using binary search*/
+ for(;;)
+ {
+ int cb = c + b;
+ int c_b= c - b;
+
+ if( p[pixel[0]] > cb) {
+ if( p[pixel[1]] > cb) {
+ if( p[pixel[2]] > cb) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[7]] < c_b) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[14]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[6]] < c_b) {
+ if( p[pixel[15]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[13]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[13]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[5]] < c_b) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[12]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[14]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[12]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[4]] < c_b) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[11]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[13]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[11]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[3]] < c_b) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[10]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[10]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[2]] < c_b) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[9]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[9]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[1]] < c_b) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[2]] > cb) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[8]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[2]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[2]] > cb) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[8]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[2]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[0]] < c_b) {
+ if( p[pixel[1]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[2]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[2]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[1]] < c_b) {
+ if( p[pixel[2]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[3]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[2]] < c_b) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[13]] < c_b) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[6]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[14]] < c_b) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[15]] < c_b) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[6]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[3]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[2]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[2]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[7]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[7]] > cb) {
+ if( p[pixel[8]] > cb) {
+ if( p[pixel[9]] > cb) {
+ if( p[pixel[6]] > cb) {
+ if( p[pixel[5]] > cb) {
+ if( p[pixel[4]] > cb) {
+ if( p[pixel[3]] > cb) {
+ if( p[pixel[2]] > cb) {
+ if( p[pixel[1]] > cb) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] > cb) {
+ if( p[pixel[11]] > cb) {
+ if( p[pixel[12]] > cb) {
+ if( p[pixel[13]] > cb) {
+ if( p[pixel[14]] > cb) {
+ if( p[pixel[15]] > cb) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else if( p[pixel[7]] < c_b) {
+ if( p[pixel[8]] < c_b) {
+ if( p[pixel[9]] < c_b) {
+ if( p[pixel[6]] < c_b) {
+ if( p[pixel[5]] < c_b) {
+ if( p[pixel[4]] < c_b) {
+ if( p[pixel[3]] < c_b) {
+ if( p[pixel[2]] < c_b) {
+ if( p[pixel[1]] < c_b) {
+ goto is_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ if( p[pixel[10]] < c_b) {
+ if( p[pixel[11]] < c_b) {
+ if( p[pixel[12]] < c_b) {
+ if( p[pixel[13]] < c_b) {
+ if( p[pixel[14]] < c_b) {
+ if( p[pixel[15]] < c_b) {
+ goto is_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+ } else
+ goto is_not_a_corner;
+
+ is_a_corner:
+ bmin=b;
+ goto end_if;
+
+ is_not_a_corner:
+ bmax=b;
+ goto end_if;
+
+ end_if:
+
+ if(bmin == bmax - 1 || bmin == bmax)
+ return bmin;
+ b = (bmin + bmax) / 2;
+ }
+ }
+
+ template
+ __always_inline int FAST9::cornerTest(const T* p, T c, unsigned char b) const {
+ int cb = c + b;
+ int c_b= c - b;
+
+ if(p[pixel[0]] > cb) {
+ if(p[pixel[1]] > cb) {
+ if(p[pixel[2]] > cb) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x108; //pixel 0 - 8
+ } else
+ if(p[pixel[15]] > cb) {
+ return 0x1f7; //pixel 15 - 7
+ } else
+ return 0;
+ } else if(p[pixel[7]] < c_b) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1e6; //pixel 14 - 6
+ } else
+ return 0;
+ } else if(p[pixel[14]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1e6; //pixel 14 - 6
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[6]] < c_b) {
+ if(p[pixel[15]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x1d5; //pixel 13 - 5
+ } else
+ return 0;
+ } else if(p[pixel[13]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1d5; //pixel 13 - 5
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[13]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[5]] < c_b) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1c4; //pixel 12 - 4
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[12]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[14]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ return 0x05e; //pixel 5 - 14
+ } else
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1c4; //pixel 12 - 4
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[12]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[4]] < c_b) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1b3; //pixel 11 - 3
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[11]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[13]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ return 0x04d; //pixel 4 - 13
+ } else
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1b3; //pixel 11 - 3
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[11]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[3]] < c_b) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1a2; //pixel 10 - 2
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[10]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x1a2; //pixel 10 - 2
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[10]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[2]] < c_b) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x191; //pixel 9 - 1
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[9]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ return 0x02a; //pixel 2 - 10
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x191; //pixel 9 - 1
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[9]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[1]] < c_b) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x180; //pixel 8 - 0
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[2]] > cb) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x12a; //pixel 2 - 10
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[8]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[2]] < c_b) {
+ return 0x019; //pixel 1 - 9
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x180; //pixel 8 - 0
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[2]] > cb) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ return 0x12a; //pixel 2 - 10
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[8]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[2]] < c_b) {
+ return 0x02a; //pixel 2 - 10
+ } else
+ if(p[pixel[11]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[0]] < c_b) {
+ if(p[pixel[1]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[2]] > cb) {
+ return 0x119; //pixel 1 - 9
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x080; //pixel 8 - 0
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[2]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x02a; //pixel 2 - 10
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[1]] < c_b) {
+ if(p[pixel[2]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[3]] > cb) {
+ return 0x12a; //pixel 2 - 10
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x091; //pixel 9 - 1
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[2]] < c_b) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0a2; //pixel 10 - 2
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ return 0x14d; //pixel 4 - 13
+ } else
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[13]] < c_b) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0b3; //pixel 11 - 3
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[6]] > cb) {
+ return 0x15e; //pixel 5 - 14
+ } else
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[14]] < c_b) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0c4; //pixel 12 - 4
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[15]] < c_b) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x0d5; //pixel 13 - 5
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0e6; //pixel 14 - 6
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x008; //pixel 0 - 8
+ } else
+ if(p[pixel[15]] < c_b) {
+ return 0x0f7; //pixel 15 - 7
+ } else
+ return 0;
+ } else
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0e6; //pixel 14 - 6
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0d5; //pixel 13 - 5
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[6]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0c4; //pixel 12 - 4
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0b3; //pixel 11 - 3
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x0a2; //pixel 10 - 2
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[3]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x091; //pixel 9 - 1
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[2]] > cb) {
+ return 0x12a; //pixel 2 - 10
+ } else
+ if(p[pixel[11]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x080; //pixel 8 - 0
+ } else
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[2]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[7]] < c_b) {
+ return 0x02a; //pixel 2 - 10
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[7]] > cb) {
+ if(p[pixel[8]] > cb) {
+ if(p[pixel[9]] > cb) {
+ if(p[pixel[6]] > cb) {
+ if(p[pixel[5]] > cb) {
+ if(p[pixel[4]] > cb) {
+ if(p[pixel[3]] > cb) {
+ if(p[pixel[2]] > cb) {
+ if(p[pixel[1]] > cb) {
+ return 0x119; //pixel 1 - 9
+ } else
+ if(p[pixel[10]] > cb) {
+ return 0x12a; //pixel 2 - 10
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ return 0x13b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ return 0x14c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ return 0x15d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ return 0x16e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] > cb) {
+ if(p[pixel[11]] > cb) {
+ if(p[pixel[12]] > cb) {
+ if(p[pixel[13]] > cb) {
+ if(p[pixel[14]] > cb) {
+ if(p[pixel[15]] > cb) {
+ return 0x17f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else if(p[pixel[7]] < c_b) {
+ if(p[pixel[8]] < c_b) {
+ if(p[pixel[9]] < c_b) {
+ if(p[pixel[6]] < c_b) {
+ if(p[pixel[5]] < c_b) {
+ if(p[pixel[4]] < c_b) {
+ if(p[pixel[3]] < c_b) {
+ if(p[pixel[2]] < c_b) {
+ if(p[pixel[1]] < c_b) {
+ return 0x019; //pixel 1 - 9
+ } else
+ if(p[pixel[10]] < c_b) {
+ return 0x02a; //pixel 2 - 10
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ return 0x03b; //pixel 3 - 11
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ return 0x04c; //pixel 4 - 12
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ return 0x05d; //pixel 5 - 13
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ return 0x06e; //pixel 6 - 14
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ if(p[pixel[10]] < c_b) {
+ if(p[pixel[11]] < c_b) {
+ if(p[pixel[12]] < c_b) {
+ if(p[pixel[13]] < c_b) {
+ if(p[pixel[14]] < c_b) {
+ if(p[pixel[15]] < c_b) {
+ return 0x07f; //pixel 7 - 15
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+ } else
+ return 0;
+
+ return 1;
+ }
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/fast9.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/fast9.h
new file mode 100644
index 00000000..16e44888
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/fast9.h
@@ -0,0 +1,37 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_FAST9_H
+#define SPARSESTEREO_FAST9_H
+
+namespace sparsestereo {
+ // Some functions of FAST9 used by other classes
+ template
+ class FAST9 {
+ public:
+ // Pixel offsets used
+ int pixel[16];
+
+ FAST9();
+
+ // Sets the image row step width
+ void setStep(int step);
+ // Performs non-maximum suppression
+ template
+ void nonMaxSuppression(const std::vector& corners, const std::vector& scores, std::vector& ret_nonmax) const;
+
+ // Autogenerated scoring method
+ int cornerScore(const T* p, T c, int bstart) const;
+ // Autogenerated cornet test method
+ __always_inline int cornerTest(const T* p, T c, unsigned char b) const;
+
+ private:
+ static const int pixelOffsetsX[16];
+ static const int pixelOffsetsY[16];
+ int step;
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/hammingdistance.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/hammingdistance.cpp
new file mode 100644
index 00000000..3b7b2f34
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/hammingdistance.cpp
@@ -0,0 +1,24 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "hammingdistance.h"
+
+namespace sparsestereo {
+ bool HammingDistance::tableInitialized = false;
+ unsigned char HammingDistance::lookupTable[1U<<16] __attribute__ ((aligned (16)));
+
+ HammingDistance::HammingDistance() {
+ if(!tableInitialized)
+ initTable();
+ }
+
+ void HammingDistance::initTable() {
+ // This is threadsafe because we always write the same values and
+ // set the initialization flag at the end
+ for(unsigned int i=0; i < sizeof(lookupTable)/sizeof(*lookupTable); i++)
+ lookupTable[i] = countNotPrecomputed(i);
+ tableInitialized = true;
+ }
+}
\ No newline at end of file
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/hammingdistance.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/hammingdistance.h
new file mode 100644
index 00000000..15454872
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/hammingdistance.h
@@ -0,0 +1,80 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_HAMMINGDISTANCE_H
+#define SPARSESTEREO_HAMMINGDISTANCE_H
+
+namespace sparsestereo {
+ // Calculates the bitwise hamming distance between two integers
+ // or counts the number of set bits.
+ // NOTE: Prefer popcnt instruction if available
+ class HammingDistance {
+ public:
+ HammingDistance();
+
+ // Calculates the hamming distance for 32-bit integers
+ unsigned char calculate(unsigned int x, unsigned int y) const {
+ return countBits(x^y);
+ }
+
+ // Calculates the hamming distance for 16-bit integers
+ unsigned char calculate(unsigned short x, unsigned short y) const {
+ return countBits((unsigned short)(x^y));
+ }
+
+ // Determines the number of set bits for a 64-bit integer
+ unsigned char countBits(unsigned long long x) const {
+ // Count using precomputed table:
+ int buf = lookupTable[x & 0xFFFFU];
+ x = x >> 16;
+ buf += lookupTable[x & 0xFFFFU];
+ x = x >> 16;
+ return buf + lookupTable[x & 0xFFFFU] + lookupTable[x >> 16];
+ }
+
+ // Determines the number of set bits for a 32-bit integer
+ unsigned char countBits(unsigned int x) const {
+ // Count using precomputed table:
+ return lookupTable[x & 0xFFFFU] + lookupTable[x >> 16];
+ }
+
+ // Determines the number of set bits for a 16-bit integer
+ unsigned char countBits(unsigned short x) const {
+ return lookupTable[x];
+ }
+
+ // Returns a pointer to the static lookup table
+ const unsigned char* getLookupTable() const {return lookupTable;}
+
+ private:
+ static bool tableInitialized;
+ static unsigned char lookupTable[1U<<16];
+
+ // Initializes the lookup table
+ void initTable();
+
+ // Methods for parallel bit counting algorithm
+ unsigned int getBit(int i) {return 0x1U << i;}
+ unsigned int getMask(int i) {
+ return (((unsigned int)(-1)) / (getBit(getBit(i)) + 1U));
+ }
+ unsigned int countBlocks(int x, int level) {
+ return ((x) & getMask(level)) + (((x) >> (getBit(level))) & getMask(level));
+ }
+
+ // Performs a parallel bit counting without using the precomputed table
+ unsigned char countNotPrecomputed(unsigned int i) {
+ i = countBlocks(i, 0);
+ i = countBlocks(i, 1);
+ i = countBlocks(i, 2);
+ i = countBlocks(i, 3);
+ i = countBlocks(i, 4);
+ // i = countBlocks(i, 5); //For 64 Bits
+ return i;
+ }
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/imageconversion.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/imageconversion.cpp
new file mode 100644
index 00000000..4386e138
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/imageconversion.cpp
@@ -0,0 +1,95 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "imageconversion.h"
+#include "simd.h"
+
+namespace sparsestereo {
+ using namespace cv;
+
+ double ImageConversion::get8UScalingFactor(int type) {
+ if(type == CV_16U)
+ return 1.0/256.0;
+ else if(type == CV_32F || type == CV_64F)
+ return 255.0;
+ else return 1.0;
+ }
+
+ double ImageConversion::get16UScalingFactor(int type) {
+ if(type == CV_8U)
+ return 256.0;
+ else if(type == CV_32F || type == CV_64F)
+ return 65535.0;
+ else return 1.0;
+ }
+
+ bool ImageConversion::convert(const Mat& input, Mat* output, int channels, int type,
+ double scalingFactor, int colorConv) {
+ if(input.channels() == channels && input.type() == type) {
+ // No conversion neccessary
+ (*output) = input;
+ return false;
+ }
+ else if(input.type() != type) {
+ // Convert the data type
+ Mat buffer;
+ input.convertTo(buffer, type, scalingFactor);
+ if(input.channels() != channels)
+ // Then convert color
+ cvtColor(buffer, *output, colorConv);
+ else (*output) = buffer;
+ } else {
+ // Only convert color
+ cvtColor(input, *output, colorConv);
+ }
+
+ return true;
+ }
+
+ bool ImageConversion::convertTo8U(const Mat& input, cv::Mat_* output) {
+ return convert(input, output, 1, CV_8U, get8UScalingFactor(input.type()), CV_RGB2GRAY);
+ }
+
+ bool ImageConversion::convertTo16U(const Mat& input, cv::Mat_* output) {
+ return convert(input, output, 1, CV_16U, get8UScalingFactor(input.type()), CV_RGB2GRAY);
+ }
+
+ bool ImageConversion::convertToColor(const Mat& input, cv::Mat_* output) {
+ return convert(input, output, 3, CV_8U, get8UScalingFactor(input.type()), CV_GRAY2RGB);
+ }
+
+ void ImageConversion::unsignedToSigned(const Mat_& src, Mat_* dst) {
+ // Adds an offset of -128 to all values
+ if(src.cols % 16 == 0) {
+ // SSE Optimized
+ v16qi offset = SIMD::scalar16(-128);
+
+ for(int y=0; y& src, Mat_* dst) {
+ // Adds an offset of 128 to all values
+ if(src.cols%16 != 0) {
+ // SSE Optimized
+ v16qi offset = SIMD::scalar16(128);
+
+ for(int y=0; y
+
+namespace sparsestereo {
+ // Static methods for image conversion. If the return value is false
+ // then the output image points to the data of the input image. In this
+ // case, the input image should not be deleted.
+ class ImageConversion {
+ public:
+ // Converts an image to 8-bit grayscale
+ static bool convertTo8U(const cv::Mat& input, cv::Mat_* output);
+ // Converts an image to 16-bit grayscale
+ static bool convertTo16U(const cv::Mat& input, cv::Mat_* output);
+ // Converts an image to a color image
+ static bool convertToColor(const cv::Mat& input, cv::Mat_* output);
+ // Converts an unsigned char to a signed char image
+ static void unsignedToSigned(const cv::Mat_& src,cv::Mat_* dst);
+ // Converts a signed char to an unsigned char image
+ static void signedToUnsigned(const cv::Mat_& src,cv::Mat_* dst);
+
+ private:
+ // Methods for calculating scaling factors
+ static double get8UScalingFactor(int type);
+ static double get16UScalingFactor(int type);
+ static bool convert(const cv::Mat& input, cv::Mat* output, int channels, int type,
+ double scalingFactor, int colorConv);
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/simd.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/simd.cpp
new file mode 100644
index 00000000..0cb0f425
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/simd.cpp
@@ -0,0 +1,29 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "simd.h"
+
+#define S16(x) SIMD::scalar16NonLookup(x)
+
+namespace sparsestereo {
+ v16qi SIMD::v16Constants[256] __attribute__((aligned (16))) = {
+ S16(0), S16(1), S16(2), S16(3), S16(4), S16(5), S16(6), S16(7), S16(8), S16(9), S16(10), S16(11), S16(12), S16(13), S16(14), S16(15),
+ S16(16), S16(17), S16(18), S16(19), S16(20), S16(21), S16(22), S16(23), S16(24), S16(25), S16(26), S16(27), S16(28), S16(29), S16(30), S16(31),
+ S16(32), S16(33), S16(34), S16(35), S16(36), S16(37), S16(38), S16(39), S16(40), S16(41), S16(42), S16(43), S16(44), S16(45), S16(46), S16(47),
+ S16(48), S16(49), S16(50), S16(51), S16(52), S16(53), S16(54), S16(55), S16(56), S16(57), S16(58), S16(59), S16(60), S16(61), S16(62), S16(63),
+ S16(64), S16(65), S16(66), S16(67), S16(68), S16(69), S16(70), S16(71), S16(72), S16(73), S16(74), S16(75), S16(76), S16(77), S16(78), S16(79),
+ S16(80), S16(81), S16(82), S16(83), S16(84), S16(85), S16(86), S16(87), S16(88), S16(89), S16(90), S16(91), S16(92), S16(93), S16(94), S16(95),
+ S16(96), S16(97), S16(98), S16(99), S16(100), S16(101), S16(102), S16(103), S16(104), S16(105), S16(106), S16(107), S16(108), S16(109), S16(110), S16(111),
+ S16(112), S16(113), S16(114), S16(115), S16(116), S16(117), S16(118), S16(119), S16(120), S16(121), S16(122), S16(123), S16(124), S16(125), S16(126), S16(127),
+ S16(128), S16(129), S16(130), S16(131), S16(132), S16(133), S16(134), S16(135), S16(136), S16(137), S16(138), S16(139), S16(140), S16(141), S16(142), S16(143),
+ S16(144), S16(145), S16(146), S16(147), S16(148), S16(149), S16(150), S16(151), S16(152), S16(153), S16(154), S16(155), S16(156), S16(157), S16(158), S16(159),
+ S16(160), S16(161), S16(162), S16(163), S16(164), S16(165), S16(166), S16(167), S16(168), S16(169), S16(170), S16(171), S16(172), S16(173), S16(174), S16(175),
+ S16(176), S16(177), S16(178), S16(179), S16(180), S16(181), S16(182), S16(183), S16(184), S16(185), S16(186), S16(187), S16(188), S16(189), S16(190), S16(191),
+ S16(192), S16(193), S16(194), S16(195), S16(196), S16(197), S16(198), S16(199), S16(200), S16(201), S16(202), S16(203), S16(204), S16(205), S16(206), S16(207),
+ S16(208), S16(209), S16(210), S16(211), S16(212), S16(213), S16(214), S16(215), S16(216), S16(217), S16(218), S16(219), S16(220), S16(221), S16(222), S16(223),
+ S16(224), S16(225), S16(226), S16(227), S16(228), S16(229), S16(230), S16(231), S16(232), S16(233), S16(234), S16(235), S16(236), S16(237), S16(238), S16(239),
+ S16(240), S16(241), S16(242), S16(243), S16(244), S16(245), S16(246), S16(247), S16(248), S16(249), S16(250), S16(251), S16(252), S16(253), S16(254), S16(255)
+ };
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/simd.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/simd.h
new file mode 100644
index 00000000..854f91e5
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/simd.h
@@ -0,0 +1,150 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_SIMD_H
+#define SPARSESTEREO_SIMD_H
+
+#include
+#include
+#include
+
+// SIMD Headers
+#ifdef __SSE3__
+#include
+#else
+#error "SSE3 support not available"
+#endif
+
+#ifdef __SSSE3__
+#include
+#else
+#warning "SSSE3 support not available"
+#endif
+
+#ifdef __SSE4_1__
+#include
+#else
+#warning "SSE4.1 support not available"
+#endif
+
+#ifdef __SSE4_2__
+#include
+#else
+#warning "SSE4.2 support not available"
+#endif
+
+/* This file contains declarations required for SIMD programming */
+
+namespace sparsestereo {
+ // Integer types
+ typedef char v16qi __attribute__ ((vector_size (16), aligned (16)));
+ typedef short v8hi __attribute__ ((vector_size (16), aligned (16)));
+ typedef int v4si __attribute__ ((vector_size (16), aligned (16)));
+ typedef long long v2di __attribute__ ((vector_size (16), aligned (16)));
+
+ // Floating point types
+ typedef float v4sf __attribute__ ((vector_size (16), aligned (16)));
+ typedef double v2sf __attribute__ ((vector_size (16), aligned (16)));
+
+ class SIMD {
+ public:
+ // Methods for creating constants with just one scalar
+ static __always_inline const v16qi& scalar16(char c) {
+ /*const v16qi ret = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
+ return ret;*/
+ return v16Constants[(unsigned char)c];
+ }
+
+ static v16qi scalar16NonLookup(char c) {
+ const v16qi ret = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
+ return ret;
+ }
+
+ static __always_inline v8hi scalar8(short s) {
+ const v8hi ret = {s, s, s, s, s, s, s, s};
+ return ret;
+ }
+
+ static __always_inline v4si scalar4(int i) {
+ const v4si ret = {i, i, i, i};
+ return ret;
+ }
+
+ static __always_inline v2di scalar2(long long i) {
+ const v2di ret = {i, i};
+ return ret;
+ }
+
+ // Methods for accessing vector elements
+
+ static __always_inline char& element16(v16qi& vec, int index) {
+ union Accessor {
+ v16qi vector;
+ char elements[16];
+ } __attribute__((may_alias));
+
+ return ((Accessor*)&vec)->elements[index];
+ }
+
+ static __always_inline short& element8(v8hi& vec, int index) {
+ union Accessor {
+ v8hi vector;
+ short elements[8];
+ } __attribute__((may_alias));
+
+ return ((Accessor*)&vec)->elements[index];
+ }
+
+ static __always_inline int& element4(v4si& vec, int index) {
+ union Accessor {
+ v4si vector;
+ int elements[16];
+ } __attribute__((may_alias));
+
+ return ((Accessor*)&vec)->elements[index];
+ }
+
+ static __always_inline long long& element2(v2di& vec, int index) {
+ union Accessor {
+ v2di vector;
+ long long elements[2];
+ } __attribute__((may_alias));
+
+ return ((Accessor*)&vec)->elements[index];
+ }
+
+ // Allocates a memory aligned array (only use primitive types!)
+ template
+ static __always_inline boost::shared_array alignedNew(int size, int alignment = 16) {
+
+ char* ptr = new char[sizeof(T) * size + alignment -1];
+ T* alignedPtr = (T*)((size_t(ptr) + alignment-1) & -alignment);
+
+ AlignedDeallocator d = {ptr};
+ return boost::shared_array(alignedPtr, d);
+ }
+
+ // Packed rotate left, 16-bit
+ static __always_inline v8hi prol16(const v8hi& value) {
+ v8hi lsb = __builtin_ia32_psrlwi128(value, 15);
+ return (value+value) | lsb;
+ }
+
+ private:
+ // Required for dealocating aligned memory areas
+ template
+ struct AlignedDeallocator {
+ char* ptr;
+ void operator() (T*) {
+ delete [] ptr;
+ }
+ };
+
+ // Lookup table for SSE 8-bit constants
+ static v16qi v16Constants[256] __attribute__((aligned (16)));
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsematch.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsematch.h
new file mode 100644
index 00000000..c1a009ef
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsematch.h
@@ -0,0 +1,54 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_SPARSEMATCH_H
+#define SPARSESTEREO_SPARSEMATCH_H
+
+#include
+#include "stereorectification.h"
+#include "exception.h"
+
+namespace sparsestereo {
+ // Struct for a single sparse stereo match
+ struct SparseMatch {
+ SparseMatch()
+ : imgLeft(NULL), imgRight(NULL), rectLeft(), rectRight(), cost(0) {}
+ SparseMatch(const cv::KeyPoint* imgLeft, const cv::KeyPoint* imgRight,
+ const cv::Point2f& rectLeft, const cv::Point2f& rectRight, short cost = 0)
+ : imgLeft(imgLeft), imgRight(imgRight), rectLeft(rectLeft), rectRight(rectRight), cost(cost) {}
+ SparseMatch(const cv::KeyPoint* imgLeft, const cv::KeyPoint* imgRight, short cost = 0)
+ : imgLeft(imgLeft), imgRight(imgRight), rectLeft(imgLeft->pt), rectRight(imgRight->pt), cost(cost) {}
+
+ const cv::KeyPoint* imgLeft;
+ const cv::KeyPoint* imgRight;
+ cv::Point2f rectLeft;
+ cv::Point2f rectRight;
+ short cost;
+
+ float disparity() const {
+ return rectLeft.x - rectRight.x;
+ }
+
+ // Converts a set of image coordinates and disparity values to 3d points
+ static void projectMatches(const std::vector& matches, std::vector* points,
+ const StereoRectification* rect) {
+ if(rect != NULL) {
+ const CalibrationResult& calib = rect->getCalibrationResult();
+ cv::Mat_ qFloat(calib.Q.rows, calib.Q.cols);
+ calib.Q.convertTo(qFloat, CV_32F);
+
+ points->reserve(matches.size());
+ for(unsigned int i=0; i product = qFloat * cv::Mat_(4, 1, point);
+ points->push_back(cv::Point3f(product(0)/product(3), product(1)/product(3), product(2)/product(3)));
+ }
+ }
+ else throw Exception("Projection of 3d points is only possible for calibrated cameras.");
+ }
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparserectification.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparserectification.cpp
new file mode 100644
index 00000000..c5373d13
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparserectification.cpp
@@ -0,0 +1,111 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "sparserectification.h"
+#include "stereorectification.h"
+
+namespace sparsestereo {
+ using namespace std;
+ using namespace cv;
+
+ SparseRectification::SparseRectification(bool subpixelFeatures, StereoRectification* rect)
+ : subpixelFeatures(subpixelFeatures), rect(rect) {
+ }
+
+ void SparseRectification::rectify(const vector& inLeft, const vector& inRight, vector* outLeft, vector* outRight) {
+
+ outLeft->resize(inLeft.size());
+ outRight->resize(inRight.size());
+
+ //#pragma omp parallel sections default(shared) num_threads(2)
+ {
+ //#pragma omp section
+ {
+ if(rect != NULL) {
+ // Rectify left features
+ if(subpixelFeatures)
+ for(int i=0; i<(int)inLeft.size(); i++) {
+ (*outLeft)[i].imgPoint = &inLeft[i];
+ (*outLeft)[i].rectPoint = rect->rectifyLeftPoint(inLeft[i].pt);
+ }
+ else for(int i=0; i<(int)inLeft.size(); i++) {
+ (*outLeft)[i].imgPoint = &inLeft[i];
+ (*outLeft)[i].rectPoint = rect->rectifyLeftPoint(cv::Point2i(inLeft[i].pt.x, inLeft[i].pt.y));
+ }
+ } else
+ // Copy unrectified
+ for(int i=0; i<(int)inLeft.size(); i++) {
+ (*outLeft)[i].imgPoint = &inLeft[i];
+ (*outLeft)[i].rectPoint = inLeft[i].pt;
+ }
+
+ // Sort features
+ sort(outLeft->begin(), outLeft->end(), featureSortComp);
+ }
+
+ //#pragma omp section
+ {
+ if(rect != NULL) {
+ // Rectify right features
+ if(subpixelFeatures)
+ for(int i=0; i<(int)inRight.size(); i++) {
+ (*outRight)[i].imgPoint = &inRight[i];
+ (*outRight)[i].rectPoint = rect->rectifyRightPoint(inRight[i].pt);
+ }
+ else for(int i=0; i<(int)inRight.size(); i++) {
+ (*outRight)[i].imgPoint = &inRight[i];
+ (*outRight)[i].rectPoint = rect->rectifyRightPoint(cv::Point2i(inRight[i].pt.x, inRight[i].pt.y));
+ }
+ } else
+ // Copy unrectified
+ for(int i=0; i<(int)inRight.size(); i++) {
+ (*outRight)[i].imgPoint = &inRight[i];
+ (*outRight)[i].rectPoint = inRight[i].pt;
+ }
+
+ // Sort features
+ sort(outRight->begin(), outRight->end(), featureSortComp);
+ }
+ }
+ }
+
+ void SparseRectification::precomputeEpilinesStart(int imageWidth, int imageHeight, Mat_* dst) {
+ Epiline::setMaxEpilineLength(imageWidth);
+ (*dst) = cv::Mat_(imageHeight, imageWidth, (short)0);
+
+ for(int y=0; ygetCalibrationResult().imageSize.width-1, rightRectX));
+
+ for(int i=0; i epsilon; i++) {
+ Epiline epiline = rect->getLeftEpiline(cv::Point2f(x1, leftImgY));
+ if(!epiline.isValid())
+ break; // Lets quit early if we can't find a valid epiline
+ float y1 = epiline.at(int(x1+0.5));
+
+ y1 = max(0.0F, min((float)rect->getCalibrationResult().imageSize.height-1, y1));
+
+ cv::Point2f guess = rect->rectifyLeftPoint(cv::Point2f(x1, y1));
+ float d = guess.x - rightRectX;
+
+ x1=max(0.0F, min((float)rect->getCalibrationResult().imageSize.width-1, x1-d));
+ }
+ return x1;
+ } else {
+ // We don't have to guess, we know it!
+ return rightRectX;
+ }
+ }
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparserectification.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparserectification.h
new file mode 100644
index 00000000..8145b72d
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparserectification.h
@@ -0,0 +1,49 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_SPARSERECTIFICATION_H
+#define SPARSESTEREO_SPARSERECTIFICATION_H
+
+#include
+#include
+
+namespace sparsestereo {
+ class StereoRectification;
+
+ // Rectifies two sets of features from the left and right image
+ class SparseRectification {
+ public:
+ // Stores a pair of rectified and unrectified feature points
+ struct RectifiedFeature {
+ const cv::KeyPoint* imgPoint;
+ cv::Point2f rectPoint;
+ };
+
+ SparseRectification(bool subpixelFeatures, StereoRectification* rect);
+
+ // Rectifies a set of sparse features
+ void rectify(const std::vector& inLeft, const std::vector& inRight,
+ std::vector* outLeft, std::vector* outRight);
+
+ // Precomputes epilines start position
+ void precomputeEpilinesStart(int imageWidth, int imageHeight, cv::Mat_* dst);
+
+ private:
+ // Comparision operator used for sorting feature points
+ static bool featureSortComp(const RectifiedFeature& left, const RectifiedFeature& right) {
+ return left.rectPoint.y < right.rectPoint.y || (left.rectPoint.y == right.rectPoint.y &&
+ left.rectPoint.x < right.rectPoint.x);
+ }
+
+ bool subpixelFeatures;
+ StereoRectification* rect;
+
+ // Estimates the distorted point in the left image, for which the disparity between rectified left and
+ // right image is 0. The given left point just serves for a first estimate.
+ inline float estimateDistortedInfiniteLeftX(int leftImgY, int rightRectX);
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsestereo-inl.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsestereo-inl.h
new file mode 100644
index 00000000..e0fcee22
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsestereo-inl.h
@@ -0,0 +1,225 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_SPARSESTEREO_INL_H
+#define SPARSESTEREO_SPARSESTEREO_INL_H
+
+#include "sparsestereo.h"
+#include
+#include
+#include
+#include "exception.h"
+#include "stereorectification.h"
+#include "simd.h"
+
+namespace sparsestereo {
+ using namespace std;
+
+ template
+ SparseStereo::SparseStereo(int maxDisparity, float yTolerance, float uniqueness,
+ StereoRectification* rect, bool subpixelFeatures, bool storeUnmatched, int leftRightStep)
+ : maxDisparity(maxDisparity), yTolerance(yTolerance), uniqueness(uniqueness), rect(rect),
+ storeUnmatched(storeUnmatched), leftRightStep(leftRightStep), precompEpilinesStart(0, 0),
+ sparseRect(subpixelFeatures, rect) {
+ }
+
+ template
+ SparseStereo::~SparseStereo() {
+ }
+
+ template
+ void SparseStereo::match(const cv::Mat& left, const cv::Mat& right,
+ const std::vector& leftFeat, const std::vector& rightFeat,
+ cv::vector* matches) {
+
+ if(left.size() != right.size() || (rect != NULL && left.size() != rect->getCalibrationResult().imageSize))
+ throw Exception("Mismatching image sizes");
+ if(leftFeat.size() == 0 || rightFeat.size() == 0)
+ return; // Can't match anything
+
+ // For the first time, or when the image size changes, compute epiline lookup table
+ if(left.cols != precompEpilinesStart.cols || left.rows != precompEpilinesStart.rows)
+ sparseRect.precomputeEpilinesStart(left.cols, left.rows, &precompEpilinesStart);
+
+ // Rectify feature points
+ sparseRect.rectify(leftFeat, rightFeat, &leftFeatures, &rightFeatures);
+
+ // Features are now sorted from top left to bottom right
+ boost::shared_array offsets = SIMD::alignedNew(left.rows);
+ int maxRowLen __attribute__((unused)) = getRowOffsets(rightFeatures, offsets.get(), left.rows);
+
+ minimumMatches.resize(leftFeatures.size());
+
+ // Perform matching
+ calcCosts(left, right, offsets.get());
+
+ // Perform left/right consistency check
+ denseConsistencyCheck(left, right);
+
+ // Compose sparse disparity list
+ for(int i=0; i<(int)leftFeatures.size(); i++) {
+ const cv::KeyPoint* rightFeature = NULL;
+ cv::Point2f rightRect = leftFeatures[i].rectPoint + cv::Point2f(1, 0); //Disparity -1
+ short cost = 0;
+
+ if(minimumMatches[i].first != -1) {
+ rightFeature = rightFeatures[minimumMatches[i].first].imgPoint;
+ rightRect = rightFeatures[minimumMatches[i].first].rectPoint;
+ cost = minimumMatches[i].second;
+ }
+
+ if(rightFeature != NULL || storeUnmatched)
+ matches->push_back(SparseMatch(leftFeatures[i].imgPoint, rightFeature, leftFeatures[i].rectPoint, rightRect, cost));
+ }
+ }
+
+ template
+ void SparseStereo::calcCosts(const cv::Mat& left, const cv::Mat& right, unsigned int* rowOffsets) {
+
+ int lastRow = -1e9; //Invalid value
+ CORRELATION correlation;
+ correlation.setReferenceImage(left);
+ correlation.setComparisonImage(right);
+
+ for(int l=0; l<(int)leftFeatures.size(); l++) {
+ // Find row start and end points
+ int ly = (int)(leftFeatures[l].rectPoint.y + 0.5);
+ int rightStart = rowOffsets[min(left.rows-1, max(0, int(ly - yTolerance)))];
+ int rightEnd = rowOffsets[min(left.rows-1, max(0, int(ly + yTolerance) + 2))];
+
+ if(ly != lastRow) {
+ // Skip top and bottom
+ if(ly < correlation.getWindowSize()/2) {
+ continue;
+ }
+ else if(ly >= left.rows - correlation.getWindowSize()/2 -1) {
+ // We reached the bottom of the image. Lets invalidate the remaining features.
+ for(; l<(int)leftFeatures.size(); l++)
+ minimumMatches[l].first = -1;
+ break;
+ }
+
+ // We have to initialize a new cost cube row
+ lastRow = ly;
+ }
+
+ COST_TYPE minCost = numeric_limits::max();
+ int minRightFeature = -1;
+
+ correlation.setReferencePoint(cv::Point2i(int(leftFeatures[l].imgPoint->pt.x + 0.5),
+ int(leftFeatures[l].imgPoint->pt.y + 0.5)));
+
+ for(int r=rightStart; r= leftFeatures[l].rectPoint.x - maxDisparity &&
+ fabs(leftFeatures[l].rectPoint.y - rightFeatures[r].rectPoint.y) <= yTolerance &&
+ rightFeatures[r].rectPoint.x >= correlation.getWindowSize()/2 &&
+ rightFeatures[r].rectPoint.x < left.cols - correlation.getWindowSize()/2)
+ {
+ // It is! Let's compute a cost
+ COST_TYPE currentCost = correlation.match(
+ cv::Point2i(int(rightFeatures[r].imgPoint->pt.x + 0.5), int(rightFeatures[r].imgPoint->pt.y + 0.5)));
+
+ if(currentCost < minCost) { // Only store smaller costs
+ minCost = currentCost;
+ minRightFeature = r;
+ }
+ }
+ }
+
+ minimumMatches[l] = std::pair(minRightFeature, minCost);
+ }
+ }
+
+ template
+ int SparseStereo::getRowOffsets(const std::vector& features,
+ unsigned int* offsets, int maxRows) {
+ int lastRow=-1, lastOffset = 0, longestRowLen = -1;
+
+ for(unsigned int i=0; i= maxRows -1)
+ break; // The rectified point is outside the visible image
+ else if(y<0)
+ continue;
+
+ if(y != lastRow) {
+ // Save offset
+ for(int j=lastRow+1; j<=y; j++)
+ offsets[j] = i;
+
+ if((int)i - lastOffset > longestRowLen)
+ longestRowLen = i - lastOffset;
+
+ lastRow = y;
+ lastOffset = i;
+ }
+ }
+
+ // Save offset for the remaining items
+ for(int i=lastRow+1; i < maxRows; i++)
+ offsets[i] = features.size();
+ if((int)features.size() - lastOffset > longestRowLen)
+ longestRowLen = features.size() - lastOffset;
+
+ return longestRowLen; //Return the maximum row length
+ }
+
+ template
+ void SparseStereo::denseConsistencyCheck(const cv::Mat& left, const cv::Mat& right) {
+ int lastRow = -1e9; //Invalid value
+ CORRELATION correlation;
+ correlation.setReferenceImage(right);
+ correlation.setComparisonImage(left);
+
+ for(int l = 0; l < (int)leftFeatures.size(); l++) {
+ int ly = (int)(leftFeatures[l].rectPoint.y + 0.5);
+ if(ly != lastRow) {
+ // Skip top and bottom
+ if(ly < correlation.getWindowSize()/2)
+ continue;
+ else if(ly >= left.rows - correlation.getWindowSize()/2 -1)
+ break;
+
+ lastRow = ly;
+ }
+
+ // Get the minimum match and cost
+ int r = minimumMatches[l].first;
+ COST_TYPE minCost = minimumMatches[l].second;
+
+ if(r == -1)
+ continue;
+
+ // Get epiline start and end
+ float leftStartX = precompEpilinesStart(leftFeatures[l].imgPoint->pt.y, max(0, min(
+ precompEpilinesStart.cols, (int)(rightFeatures[r].rectPoint.x+0.5))));
+ int startX = max(correlation.getWindowSize()/2, int(leftStartX /*+ 0.5*/));
+ int endX = min(precompEpilinesStart.cols - correlation.getWindowSize()/2,
+ int(leftStartX + maxDisparity /*+ 0.5*/));
+ Epiline epiline = rect!=NULL ? rect->getLeftEpiline(leftFeatures[l].imgPoint->pt) : Epiline(leftFeatures[l].imgPoint->pt.y);
+ if(!epiline.isValid())
+ continue;
+
+ // Preform consistency check
+ correlation.setReferencePoint(cv::Point2i(int(rightFeatures[r].imgPoint->pt.x + 0.5), int(rightFeatures[r].imgPoint->pt.y + 0.5)));
+ for(int x = startX; x < endX; x+= leftRightStep) {
+ int y = (int)(epiline.at(x) + 0.5);
+ if(y < correlation.getWindowSize()/2 || y >= left.rows - correlation.getWindowSize()/2)
+ continue;
+
+ COST_TYPE currentCost = correlation.match(cv::Point2i(x, y));
+
+ if(currentCost < minCost/uniqueness && fabs(x - int(leftFeatures[l].imgPoint->pt.x+0.5)) > leftRightStep) {
+ minimumMatches[l].first = -1;
+ break;
+ }
+ }
+ }
+ }
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsestereo.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsestereo.h
new file mode 100644
index 00000000..d4d44568
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/sparsestereo.h
@@ -0,0 +1,57 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_SPARSESTEREO_H
+#define SPARSESTEREO_SPARSESTEREO_H
+
+#include
+#include
+#include
+#include
+#include
+#include "sparsematch.h"
+#include "sparserectification.h"
+
+namespace sparsestereo {
+ class StereoRectification;
+
+ // Class bundling sparse stereo algorithms
+ template
+ class SparseStereo {
+ public:
+ SparseStereo(int maxDisparity, float yTolerance = 1, float uniqueness = 0.6, StereoRectification* rect = NULL,
+ bool subpixelFeatures = false, bool storeUnmatched = false, int leftRightStep = 1);
+ ~SparseStereo();
+
+ // Matches using a census window
+ void match(const cv::Mat& left, const cv::Mat& right, const std::vector& leftFeat,
+ const std::vector& rightFeat, std::vector* matches);
+
+ private:
+ std::vector leftFeatures, rightFeatures;
+ int maxDisparity;
+ float yTolerance;
+ float uniqueness;
+ StereoRectification* rect;
+ bool storeUnmatched;
+ int leftRightStep;
+ std::vector > minimumMatches;
+ cv::Mat_ precompEpilinesStart; // Preocomputed epilines start positions
+ cv::Size frameSize;
+ SparseRectification sparseRect;
+
+ // Gets the starting offsets of each row and returns the maximum row length
+ int getRowOffsets(const std::vector& features, unsigned int* offsets,
+ int maxRows);
+
+ // Calculates the matching costs using census windows
+ void calcCosts(const cv::Mat& left, const cv::Mat& right, unsigned int* rowOffsets);
+
+ // Performs a left/right consistency check that is dense in the left image
+ void denseConsistencyCheck(const cv::Mat& left, const cv::Mat& right);
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/stereorectification.cpp b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/stereorectification.cpp
new file mode 100644
index 00000000..1ccd67e7
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/stereorectification.cpp
@@ -0,0 +1,121 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#include "stereorectification.h"
+#include
+#include
+
+namespace sparsestereo {
+ using namespace std;
+ using namespace cv;
+ using namespace boost;
+
+ scoped_array Epiline::dummyLine;
+ int Epiline::dummyLineLength = -1;
+
+ void Epiline::setMaxEpilineLength(int len) {
+ if(dummyLineLength != len) {
+ dummyLine.reset(new float[len]);
+ memset(dummyLine.get(), 0, sizeof(float)*len);
+ dummyLineLength = len;
+ }
+ }
+
+ StereoRectification::StereoRectification(const CalibrationResult& calibRes, Interpolation interpolation)
+ : interpolation(interpolation), calibRes(calibRes)
+ {
+ initImageRectMap();
+ initPointRectMap();
+ initEpilines();
+ }
+
+ void StereoRectification::initImageRectMap() {
+ // Create rectification maps for image rectification
+ initUndistortRectifyMap(calibRes.cameraMatrix[0], calibRes.distCoeffs[0], calibRes.R[0],
+ calibRes.P[0], calibRes.imageSize, CV_16SC2, imageRectMap[0][0], imageRectMap[0][1]);
+ initUndistortRectifyMap(calibRes.cameraMatrix[1], calibRes.distCoeffs[1], calibRes.R[1],
+ calibRes.P[1], calibRes.imageSize, CV_16SC2, imageRectMap[1][0], imageRectMap[1][1]);
+ }
+
+ void StereoRectification::initPointRectMap() {
+ // Create rectification maps for integer point rectification
+ // Collect all image point coordinates
+ vector distortedPoints((calibRes.imageSize.width + 1) * (calibRes.imageSize.height + 1));
+ for(int y=0; y<=calibRes.imageSize.height; y++)
+ for(int x=0; x<=calibRes.imageSize.width; x++)
+ distortedPoints[y * (calibRes.imageSize.width + 1) + x]/*, 0)*/ = Point2f(x, y);
+ for(int i=0; i<2; i++) {
+ // Perform rectification
+ vector undistortedPoints(distortedPoints.size());
+ undistortPoints(distortedPoints, undistortedPoints, calibRes.cameraMatrix[i], calibRes.distCoeffs[i],
+ calibRes.R[i], calibRes.P[i]);
+ // Store results
+ pointRectMap[i] = Mat_(calibRes.imageSize.height + 1, calibRes.imageSize.width + 1, Point2f(-1, -1));
+ for(int y=0; y<= calibRes.imageSize.height; y++)
+ for(int x=0; x<= calibRes.imageSize.width; x++)
+ pointRectMap[i](y,x) = undistortedPoints[y * (calibRes.imageSize.width + 1) + x];//, 0);
+ }
+ }
+
+ void StereoRectification::initEpilines() {
+ for(int i=0; i<2; i++) {
+ epilines[i] = Mat_(calibRes.imageSize, -1e6);
+ // First calculate a float undistortion map
+ Mat_ rectMap[2];
+ initUndistortRectifyMap(calibRes.cameraMatrix[i], calibRes.distCoeffs[i], calibRes.R[i],
+ calibRes.P[i], calibRes.imageSize, CV_32F, rectMap[0], rectMap[1]);
+
+ //Calculate epilines
+ for(int y=0; y < calibRes.imageSize.height; y++) {
+ for(int x=0; x=0 && imgX < calibRes.imageSize.width) {
+ double interpolated = rectMap[1](y, x) + dy / dx * (imgX - rectMap[0](y, x));
+ if(interpolated >= 0 && interpolated < calibRes.imageSize.height) {
+ epilines[i](y, imgX) = interpolated;
+ }
+ }
+ }
+ }
+ }
+
+ // Fill epilines index
+ epilineIndex[i] = Mat_(calibRes.imageSize, -1);
+ for(int line = 0; line < calibRes.imageSize.height - 1; line++)
+ for(int x=0; x=0 && imgY < calibRes.imageSize.height) {
+ if(fabs(imgY - epilines[i](line, x)) < fabs(imgY - epilines[i](line+1, x)))
+ epilineIndex[i](imgY, x) = line;
+ else epilineIndex[i](imgY, x) = line + 1;
+ }
+ }
+ }
+ }
+
+ Point2f StereoRectification::highPrecisionRectifyLeftPoint(Point2f inLeft) const {
+ Mat_ inLeftPoint(1, 1, inLeft);
+ vector outLeftPoint;
+
+ undistortPoints(inLeftPoint, outLeftPoint, calibRes.cameraMatrix[0], calibRes.distCoeffs[0],
+ calibRes.R[0], calibRes.P[0]);
+
+ return outLeftPoint[0];
+ }
+
+ Point2f StereoRectification::highPrecisionRectifyRightPoint(Point2f inRight) const {
+ Mat_ inRightPoint(1, 1, inRight);
+ vector outRightPoint;
+
+ undistortPoints(inRightPoint, outRightPoint, calibRes.cameraMatrix[1], calibRes.distCoeffs[1],
+ calibRes.R[1], calibRes.P[1]);
+
+ return outRightPoint[0];
+ }
+}
diff --git a/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/stereorectification.h b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/stereorectification.h
new file mode 100644
index 00000000..d9da153e
--- /dev/null
+++ b/perception/mil_vision/exFAST_SparseStereo/src/sparsestereo/stereorectification.h
@@ -0,0 +1,163 @@
+/*
+ * Author: Konstantin Schauwecker
+ * Year: 2012
+ */
+
+#ifndef SPARSESTEREO_STEREORECTIFICATION_H
+#define SPARSESTEREO_STEREORECTIFICATION_H
+
+#include
+#include
+#include
+#include
+#include
+#include "calibrationresult.h"
+
+namespace sparsestereo {
+ // Stores one epiline and provides element access
+ class Epiline{
+ public:
+ Epiline(): line(NULL), dy(0) {}
+
+ // Stores one real epiline
+ Epiline(const cv::Mat_& refLines, const cv::Mat_ refLineIndices, const cv::Point2f& pointOnLine) {
+ int index = refLineIndices(int(pointOnLine.y + 0.5), int(pointOnLine.x + 0.5));
+ valid = (index != -1);
+ if(valid) {
+ assert(index != -1);
+ dy = pointOnLine.y - refLines(index, (int)round(pointOnLine.x));
+ line = &refLines(index, 0);
+#ifndef NDEBUG
+ width = refLines.cols;
+#endif
+ }
+#ifndef NDEBUG
+ else width = 0;
+#endif
+ }
+
+ // Creates a dummy epiline
+ Epiline(float y): line(dummyLine.get()), dy(y), valid(true) {
+#ifndef NDEBUG
+ width=dummyLineLength;
+#endif
+ }
+
+ // Returns the y-coordinate for the epiline at position x
+ float at(int x) const {
+ assert(x >= 0 && x dummyLine;
+ static int dummyLineLength;
+ const float* line;
+ float dy;
+#ifndef NDEBUG
+ int width;
+#endif
+ bool valid;
+ };
+
+ // Class for rectifying input images
+ class StereoRectification {
+ public:
+ enum Interpolation {
+ Cubic = cv::INTER_CUBIC,
+ Linear = cv::INTER_LINEAR,
+ Nearest = cv::INTER_NEAREST
+ };
+
+ StereoRectification(const CalibrationResult& calibRes, Interpolation iterpolation = Linear);
+
+ // Rectifies a stereo pair
+ template
+ void rectifyStereoPair(const std::pair, cv::Mat_ >& input, std::pair, cv::Mat_ >* output) const {
+ rectifyLeftImage(input.first, &(output->first));
+ rectifyRightImage(input.second, &(output->second));
+ }
+
+ // Rectifies the left image
+ template
+ void rectifyLeftImage(const cv::Mat_& input, cv::Mat_* output) const {
+ cv::remap(input, *output, imageRectMap[0][0], imageRectMap[0][1], interpolation);
+ }
+
+ // Rectifies the right image
+ template
+ void rectifyRightImage(const cv::Mat_& input, cv::Mat_* output) const {
+ cv::remap(input, *output, imageRectMap[1][0], imageRectMap[1][1], interpolation);
+ }
+
+ // Rectifies a left integer point
+ cv::Point2f rectifyLeftPoint(cv::Point2i inLeft) const {
+ return pointRectMap[0](inLeft.y, inLeft.x);
+ }
+
+ // Rectifies a right integer point
+ cv::Point2f rectifyRightPoint(cv::Point2i inRight) const {
+ return pointRectMap[1](inRight.y, inRight.x);
+ }
+
+ // Rectifies a left float point
+ cv::Point2f rectifyLeftPoint(cv::Point2f inLeft) const {
+ return interpolatedLookup(pointRectMap[0], inLeft);
+ }
+
+ // Rectifies a right float point
+ cv::Point2f rectifyRightPoint(cv::Point2f inRight) const {
+ return interpolatedLookup(pointRectMap[1], inRight);
+ }
+
+ // Rectifies a left float point. This implementation is slow!
+ cv::Point2f highPrecisionRectifyLeftPoint(cv::Point2f inLeft) const;
+
+ // Rectifies a right float point. This implementation is slow!
+ cv::Point2f highPrecisionRectifyRightPoint(cv::Point2f inRight) const;
+
+ // Returns an epiline going through the given left point
+ Epiline getLeftEpiline(cv::Point2f p) const {
+ return Epiline(epilines[0], epilineIndex[0], p);
+ }
+
+ // Returns an epiline going through the given left point
+ Epiline getRightEpiline(cv::Point2f p) const {
+ return Epiline(epilines[1], epilineIndex[1], p);
+ }
+
+ // Returns the calibration results
+ const CalibrationResult& getCalibrationResult() const {return calibRes;}
+
+ private:
+ cv::Mat imageRectMap[2][2];
+ cv::Mat_ pointRectMap[2];
+ cv::Mat_ epilines[2];
+ cv::Mat_ epilineIndex[2];
+ Interpolation interpolation;
+ CalibrationResult calibRes;
+
+ void initImageRectMap();
+ void initPointRectMap();
+ void initEpilines();
+
+ // Preforms an bilinear interpolated lookup
+ cv::Point2f interpolatedLookup(const cv::Mat_& map, cv::Point2f pt) const {
+ float dx = pt.x - int(pt.x);
+ float dy = pt.y - int(pt.y);
+
+ cv::Point2f top = (1.0 - dx) * map(int(pt.y), int(pt.x)) + dx * map(int(pt.y), int(pt.x + 1));
+ cv::Point2f bottom = (1.0 - dx) * map(int(pt.y + 1), int(pt.x)) + dx * map(int(pt.y + 1), int(pt.x + 1));
+ return (1.0 - dy) * top + dy * bottom;
+ }
+ };
+}
+
+#endif
diff --git a/perception/mil_vision/include/camera_lidar_transformer.hpp b/perception/mil_vision/include/camera_lidar_transformer.hpp
new file mode 100644
index 00000000..1273129d
--- /dev/null
+++ b/perception/mil_vision/include/camera_lidar_transformer.hpp
@@ -0,0 +1,65 @@
+#pragma once
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include