numpy.int16

Here are the examples of the python api numpy.int16 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

200 Examples 7

Example 1

Project: Yeppp
Source File: avx_add_test.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        func = avx.add.yepCore_Add.yepCore_Add_V16sV16s_V16s.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 2

Project: Yeppp
Source File: avx_multiply_test.py
View license
    def test_multiply_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        func = avx.multiply.yepCore_Multiply.yepCore_Multiply_V16sV16s_V16s.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] * b_tmp[i], c[i], "Mismatch at index %d" % i)

Example 3

Project: Yeppp
Source File: sse_add_test.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        func = sse.add.yepCore_Add.yepCore_Add_V16sV16s_V16s.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 4

Project: Yeppp
Source File: test_add_unittest.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        yepCore_Add_V16sV16s_V16s(a_ptr, b_ptr, c_ptr, self.n)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 5

Project: Yeppp
Source File: test_add_unittest.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        yepCore_Add_V16sV16s_V16s(a_ptr, b_ptr, c_ptr, self.n)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 6

Project: Yeppp
Source File: test_add_unittest.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        yepCore_Add_V16sV16s_V16s(a_ptr, b_ptr, c_ptr, self.n)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 7

Project: Yeppp
Source File: avx_add_test.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        func = avx.add.yepCore_Add.yepCore_Add_V16sV16s_V16s.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 8

Project: Yeppp
Source File: avx_multiply_test.py
View license
    def test_multiply_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        func = avx.multiply.yepCore_Multiply.yepCore_Multiply_V16sV16s_V16s.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] * b_tmp[i], c[i], "Mismatch at index %d" % i)

Example 9

Project: Yeppp
Source File: sse_add_test.py
View license
    def test_add_V16sV16s_V16s(self):
        a_tmp = self.a.astype(numpy.int16)
        b_tmp = self.b.astype(numpy.int16)
        c = numpy.empty([self.n]).astype(numpy.int16)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))

        func = sse.add.yepCore_Add.yepCore_Add_V16sV16s_V16s.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 10

Project: spectrum_painter
Source File: radios.py
View license
    def convert(self, complex_iq):
        intlv = self._interleave(complex_iq)
        clipped = self._clip(intlv, limit=1.0)
        converted = 2047. * clipped
        bladerf_out = converted.astype(np.int16)
        return bladerf_out

Example 11

Project: wub-machine
Source File: electrohouse.py
View license
def cutnote(audioData, length):
    beatlength = (audioData.sampleRate * 60 / tempo) #in samples
    i = beatlength/length
    data = audioData.data[0:i]
    if len(data) < i:
        if audioData.numChannels == 2:
            shape = (i - len(data),2)
        else:
            shape = (i - len(data),)
        data = numpy.append(data, numpy.zeros(shape, dtype=numpy.int16), 0)
    r = audio.AudioData(
        ndarray=data,
        numChannels=audioData.numChannels,
        sampleRate = audioData.sampleRate
    )
    return make_stereo(r) if (r.numChannels == 1) else r

Example 12

Project: pyrf
Source File: vrt.py
View license
    def __init__(self, binary_data):
        self._strdata = binary_data
        self._data = None
        self.np_array = np.frombuffer(self._strdata, dtype=np.int16)
        self.np_array = self.np_array.newbyteorder('>')
        self.np_array.shape = (-1, 2)

Example 13

Project: SALib
Source File: test_morris_util.py
View license
def test_add_indices():
    '''
    Tests whether the right indices are added.
    '''
    indices = (1,3,4)
    matr = np.zeros((6,6), dtype = np.int16)
    ind_extra = add_indices(indices, matr)

    expected = [(1,3,4,0),(1,3,4,2),(1,3,4,5)]
    
    assert_equal(ind_extra, expected)

Example 14

Project: scipy
Source File: test_idl.py
View license
    def test_idict(self):
        custom_dict = {'a': np.int16(999)}
        original_id = id(custom_dict)
        s = readsav(path.join(DATA_PATH, 'scalar_byte.sav'), idict=custom_dict, verbose=False)
        assert_equal(original_id, id(s))
        assert_('a' in s)
        assert_identical(s['a'], np.int16(999))
        assert_identical(s['i8u'], np.uint8(234))

Example 15

Project: scipy
Source File: test_idl.py
View license
    def test_scalars(self):
        s = readsav(path.join(DATA_PATH, 'struct_scalars.sav'), verbose=False)
        assert_identical(s.scalars.a, np.array(np.int16(1)))
        assert_identical(s.scalars.b, np.array(np.int32(2)))
        assert_identical(s.scalars.c, np.array(np.float32(3.)))
        assert_identical(s.scalars.d, np.array(np.float64(4.)))
        assert_identical(s.scalars.e, np.array([b"spam"], dtype=object))
        assert_identical(s.scalars.f, np.array(np.complex64(-1.+3j)))

Example 16

Project: scipy
Source File: test_idl.py
View license
    def test_scalars_replicated(self):
        s = readsav(path.join(DATA_PATH, 'struct_scalars_replicated.sav'), verbose=False)
        assert_identical(s.scalars_rep.a, np.repeat(np.int16(1), 5))
        assert_identical(s.scalars_rep.b, np.repeat(np.int32(2), 5))
        assert_identical(s.scalars_rep.c, np.repeat(np.float32(3.), 5))
        assert_identical(s.scalars_rep.d, np.repeat(np.float64(4.), 5))
        assert_identical(s.scalars_rep.e, np.repeat(b"spam", 5).astype(object))
        assert_identical(s.scalars_rep.f, np.repeat(np.complex64(-1.+3j), 5))

Example 17

Project: scipy
Source File: test_idl.py
View license
    def test_scalars_replicated_3d(self):
        s = readsav(path.join(DATA_PATH, 'struct_scalars_replicated_3d.sav'), verbose=False)
        assert_identical(s.scalars_rep.a, np.repeat(np.int16(1), 24).reshape(4, 3, 2))
        assert_identical(s.scalars_rep.b, np.repeat(np.int32(2), 24).reshape(4, 3, 2))
        assert_identical(s.scalars_rep.c, np.repeat(np.float32(3.), 24).reshape(4, 3, 2))
        assert_identical(s.scalars_rep.d, np.repeat(np.float64(4.), 24).reshape(4, 3, 2))
        assert_identical(s.scalars_rep.e, np.repeat(b"spam", 24).reshape(4, 3, 2).astype(object))
        assert_identical(s.scalars_rep.f, np.repeat(np.complex64(-1.+3j), 24).reshape(4, 3, 2))

Example 18

Project: scipy
Source File: test_idl.py
View license
    def test_arrays(self):
        s = readsav(path.join(DATA_PATH, 'struct_arrays.sav'), verbose=False)
        assert_array_identical(s.arrays.a[0], np.array([1, 2, 3], dtype=np.int16))
        assert_array_identical(s.arrays.b[0], np.array([4., 5., 6., 7.], dtype=np.float32))
        assert_array_identical(s.arrays.c[0], np.array([np.complex64(1+2j), np.complex64(7+8j)]))
        assert_array_identical(s.arrays.d[0], np.array([b"cheese", b"bacon", b"spam"], dtype=object))

Example 19

Project: scipy
Source File: test_idl.py
View license
    def test_inheritance(self):
        s = readsav(path.join(DATA_PATH, 'struct_inherit.sav'), verbose=False)
        assert_identical(s.fc.x, np.array([0], dtype=np.int16))
        assert_identical(s.fc.y, np.array([0], dtype=np.int16))
        assert_identical(s.fc.r, np.array([0], dtype=np.int16))
        assert_identical(s.fc.c, np.array([4], dtype=np.int16))

Example 20

Project: scipy
Source File: test_netcdf.py
View license
def test_dtype_specifiers():
    # Numpy 1.7.0-dev had a bug where 'i2' wouldn't work.
    # Specifying np.int16 or similar only works from the same commit as this
    # comment was made.
    with make_simple(BytesIO(), mode='w') as f:
        f.createDimension('x',4)
        f.createVariable('v1', 'i2', ['x'])
        f.createVariable('v2', np.int16, ['x'])
        f.createVariable('v3', np.dtype(np.int16), ['x'])

Example 21

Project: OpenSesame
Source File: synth.py
View license
def to_int_16(a):

	"""
	desc:
		Converts the float array to an 16 bit int array, which is a more
		typical sound format.

	visible:
		False
	"""

	a *= 32767
	return a.astype(np.int16)

Example 22

Project: spectral
Source File: envi.py
View license
    def test_save_image_ndarray_no_ext(self):
        '''Test saving an ENVI formated image with no image file extension.'''
        import os
        import spectral
        data = np.arange(1000, dtype=np.int16).reshape(10, 10, 10)
        base = os.path.join(testdir, 'test_save_image_ndarray_noext')
        hdr_file = base + '.hdr'
        spectral.envi.save_image(hdr_file, data, ext='')
        rdata = spectral.open_image(hdr_file).load()
        assert(np.all(data==rdata))

Example 23

Project: spectral
Source File: envi.py
View license
    def test_save_image_ndarray_alt_ext(self):
        '''Test saving an ENVI formated image with alternate extension.'''
        import os
        import spectral
        data = np.arange(1000, dtype=np.int16).reshape(10, 10, 10)
        base = os.path.join(testdir, 'test_save_image_ndarray_alt_ext')
        hdr_file = base + '.hdr'
        ext = '.foo'
        img_file = base + ext
        spectral.envi.save_image(hdr_file, data, ext=ext)
        rdata = spectral.envi.open(hdr_file, img_file).load()
        assert(np.all(data==rdata))

Example 24

Project: pi-tracking-telescope
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 25

Project: pi-tracking-telescope
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 26

Project: pi-tracking-telescope
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 27

Project: PyScada
Source File: __init__.py
View license
def _cast_value(value,_type):
    '''
    cast value to _type
    '''
    if _type.upper() == 'FLOAT64':
        return float64(value)
    elif _type.upper() == 'FLOAT32':
        return float32(value)
    elif  _type.upper() == 'INT32':
        return int32(value)
    elif  _type.upper() == 'UINT16':
        return uint16(value)
    elif  _type.upper() == 'INT16':
        return int16(value)
    elif _type.upper() == 'BOOLEAN':
        return uint8(value)
    else:
        return float64(value)

Example 28

Project: deepdish
Source File: test_core.py
View license
    def test_bytesize(self):
        assert dd.humanize_bytesize(1) == '1 B'
        assert dd.humanize_bytesize(2 * 1024) == '2 KB'
        assert dd.humanize_bytesize(3 * 1024**2) == '3 MB'
        assert dd.humanize_bytesize(4 * 1024**3) == '4 GB'
        assert dd.humanize_bytesize(5 * 1024**4) == '5 TB'

        assert dd.bytesize(np.ones((5, 2), dtype=np.int16)) == 20

        assert dd.memsize(np.ones((5, 2), dtype=np.int16)) == '20 B'

Example 29

Project: pyfasst
Source File: audioObject.py
View license
    def wavread(filename, first=0, last=None):
        sndfile = al.pysndfile.Sndfile(filename, mode='r')
        if last is None:
            last = sndfile.nframes
        
        sndfile.seek(first)
        fs = sndfile.samplerate
        data = sndfile.read_frames(nframes=last-first, )
        # Note: read_frame(nframes,dtype=np.int16) is broken! probably... 
        if sndfile.encoding == 'pcm16':
            # convert back to signed int16
            data = np.int16(data * 2.**15)
        sndfile.close()
        return fs, data, sndfile.encoding

Example 30

Project: xraylarch
Source File: xrf_netcdf.py
View license
def aslong(d):
    """unravels and converts array of int16 (int) to int32 (long)"""
    # need to unravel the array!!!
    d = d.astype(np.int16).ravel()
    d.dtype = np.int32
    return d

Example 31

Project: cubr
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 32

Project: python-mingus
Source File: pyfluidsynth.py
View license
def fluid_synth_write_s16_stereo(synth, len):
    """Return generated samples in stereo 16-bit format.

    Return value is a Numpy array of samples.
    """
    import numpy
    buf = create_string_buffer(len * 4)
    fluid_synth_write_s16(synth, len, buf, 0, 2, buf, 1, 2)
    return numpy.fromstring(buf[:], dtype=numpy.int16)

Example 33

Project: python-mingus
Source File: pyfluidsynth.py
View license
def raw_audio_string(data):
    """Return a string of bytes to send to soundcard.

    Input is a numpy array of samples. Default output format is 16-bit
    signed (other formats not currently supported).
    """
    import numpy
    return data.astype(numpy.int16).tostring()

Example 34

Project: facerec
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 35

Project: yatsm
Source File: test_changemap.py
View license
def test_changemap_first_pass_3(example_results, tmpdir, read_image):
    """ Make changemap of first change, but with all NDV
    """
    image = tmpdir.join('first.gtif').strpath
    runner = CliRunner()
    result = runner.invoke(
        cli,
        ['-v', 'changemap',
         '--root', example_results['root'],
         '--result', example_results['results_dir'],
         '--image', example_results['example_img'],
         '--out_date', '%Y%m%d',
         '--ndv', '0',
         'first', '1914-07-28', '1918-11-11', image
         ]
    )
    assert result.exit_code == 0
    np.testing.assert_equal(read_image(image)[0, ...],
                            np.zeros((5, 5), dtype=np.int16))

Example 36

Project: typefacet
Source File: _l_o_c_a.py
View license
	def compile(self, ttFont):
		locations = self.locations
		if max(locations) < 0x20000:
			locations = locations / 2
			locations = locations.astype(numpy.int16)
			ttFont['head'].indexToLocFormat = 0
		else:
			ttFont['head'].indexToLocFormat = 1
		if sys.byteorder <> "big":
			locations = locations.byteswap()
		return locations.tostring()

Example 37

Project: ibis
Source File: test_comms.py
View license
    def test_smallint(self):
        col = int_ex(self.N, IbisType.SMALLINT)
        self.assertEqual(col.nbytes(), self.N * 3)
        self._check_roundtrip([col])

        _check_pandas_ints_nulls(col, np.int16)

        _check_pandas_ints_no_nulls(self.N, IbisType.SMALLINT)

Example 38

Project: hope
Source File: test_cast.py
View license
@pytest.mark.parametrize("dtype", [dtype for dtype in dtypes if dtype != float])
def test_func_int16(dtype):
    def fkt(a):
        return np.int16(a)
    hfkt = hope.jit(fkt)
    ao, ah = random(dtype, [])
    co, ch = fkt(ao), hfkt(ah)
    assert type(co) == type(ch)

Example 39

View license
def generateVectors(level):
    """
    Given a level, this will generate x and y vectors that
    can be used to plot the hilbert curve path for that level.
    Useful for explaining HCs.
    """
    n = (1 << level)
    x = numpy.zeros(n**2, dtype=numpy.int16)
    y = numpy.zeros(n**2, dtype=numpy.int16)
    for i in xrange(0, n**2):
        x[i], y[i] = d2xy(n, i)
    return x, -y

Example 40

Project: PyCV-time
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 41

Project: PyCV-time
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 42

Project: PyCV-time
Source File: camshift.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
            self.tracking_state = 0
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                h, w = self.frame.shape[:2]
                xo, yo = self.drag_start
                x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y]))
                x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y]))
                self.selection = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.selection = (x0, y0, x1, y1)
            else:
                self.drag_start = None
                if self.selection is not None:
                    self.tracking_state = 1

Example 43

Project: PyCV-time
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 44

Project: PyCV-time
Source File: camshift.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
            self.tracking_state = 0
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                h, w = self.frame.shape[:2]
                xo, yo = self.drag_start
                x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y]))
                x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y]))
                self.selection = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.selection = (x0, y0, x1, y1)
            else:
                self.drag_start = None
                if self.selection is not None:
                    self.tracking_state = 1

Example 45

Project: PyCV-time
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 46

Project: PyCV-time
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)

Example 47

Project: gdal2cesium
Source File: gdal2cesium.py
View license
    def write_tile(self,tilename,new_tile,maskbytes):
        tilepath = os.path.join(self.processedPath,tilename)
        if not os.path.exists(os.path.dirname(tilepath)):
            os.makedirs(os.path.dirname(tilepath))
         
         
        tilearrayint = new_tile.astype(numpy.int16)
        data = tilearrayint.flatten()
        data_with_mask = numpy.append(data,maskbytes)
        data_with_mask.tofile(tilepath)

Example 48

Project: gdal2cesium
Source File: gdal2cesium.py
View license
    def write_tile(self,tilearray,tz,tx,ty,NB_FLAGS,WATER_MASK=0):
        tilefilename = os.path.join(self.tmpoutput, str(tz), str(tx), "%s.%s" % (ty, self.tileext))
        # Create directories for the tile
        if not os.path.exists(os.path.dirname(tilefilename)):
            os.makedirs(os.path.dirname(tilefilename))
        
        # convert to integer representation of heightmap accordind to Cesium format and append children flags byte       
        tilearray = (tilearray+1000) * 5
        tilearrayint = tilearray.astype(numpy.int16)
        tilearrayint.tofile(tilefilename)
        child_water_bytes = struct.pack('<BB',NB_FLAGS,WATER_MASK)
        with open(tilefilename,'ab') as outfile:
            outfile.write(child_water_bytes)

Example 49

Project: dash-hack
Source File: camshift.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
            self.tracking_state = 0
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                h, w = self.frame.shape[:2]
                xo, yo = self.drag_start
                x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y]))
                x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y]))
                self.selection = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.selection = (x0, y0, x1, y1)
            else:
                self.drag_start = None
                if self.selection is not None:
                    self.tracking_state = 1

Example 50

Project: dash-hack
Source File: common.py
View license
    def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)