Пример #1
0
# Copyright 2013 Tom SF Haines

# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



# Compile the code if need be...
try:
  from utils.make import make_mod
  import os.path

  make_mod('ms_c', os.path.dirname(__file__), ['philox.h', 'philox.c', 'bessel.h', 'bessel.c', 'eigen.h', 'eigen.c', 'kernels.h', 'kernels.c', 'data_matrix.h', 'data_matrix.c', 'spatial.h', 'spatial.c', 'balls.h', 'balls.c', 'mean_shift.h', 'mean_shift.c', 'ms_c.h', 'ms_c.c'])
except: pass



# Import the compiled module into this space, so we can pretend they are one and the same, just with automatic compilation...
from ms_c import MeanShift as MeanShiftC

import numpy



# Augment the class coded in C with some pure python functionality...
class MeanShift(MeanShiftC):
  __doc__ = MeanShiftC.__doc__
  
Пример #2
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.



import os.path
import math
import numpy

from utils.make import make_mod
from video_node import *



# The C version - we require that this be built, even if not used...
make_mod('backsub_dp_c', os.path.dirname(__file__), 'backsub_dp_c.c')
import backsub_dp_c



# The OpenCL version - try to compile it, and use it if at all possible...
try:
  make_mod('backsub_dp_cl', os.path.dirname(__file__), ['manager_cl.h', 'open_cl_help.h', 'backsub_dp_cl.c'], openCL=True)
  import backsub_dp_cl
except:
  backsub_dp_cl = None



# The python wrapper around BackSubCore, to give it the right interface etc.
class BackSubDP(VideoNode):
Пример #3
0
# Copyright 2016 Tom SF Haines

# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import os.path

from utils.make import make_mod



# Compile the code if need be...
make_mod('line_graph_c', os.path.dirname(__file__), ['line_graph_c.h', 'line_graph_c.c'])



# Import the compiled module into this space, so we can pretend they are one and the same, just with automatic compilation...
from line_graph_c import *
Пример #4
0
# Copyright 2016 Tom SF Haines

# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



# Compile the code if need be...
from utils.make import make_mod
import os.path

make_mod('transform_c', os.path.dirname(__file__), ['bspline.h', 'bspline.c', 'transform_c.h', 'transform_c.c'], numpy=True)

del make_mod



# Import the code...
from transform_c import *
Пример #5
0
# Copyright 2016 Tom SF Haines

# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



# Compile the code if need be...
from utils.make import make_mod
import os.path

make_mod('ddp_c', os.path.dirname(__file__), ['ddp_c.h', 'ddp_c.c'])



# Import the compiled module into this space, so we can pretend they are one and the same, just with automatic compilation...
from ddp_c import DDP
Пример #6
0
# Copyright 2016 Tom SF Haines

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os.path

from utils.make import make_mod



# Compile the code if need be...
make_mod('composite_c', os.path.dirname(__file__), ['composite_c.h', 'composite_c.c'])



# Import the compiled module into this space, so we can pretend they are one and the same, just with automatic compilation...
from composite_c import *
Пример #7
0

import os.path
import time
from collections import defaultdict

import cv

from utils.make import make_mod
from video_node import VideoNode



# Arrange for the Python module that does iniail setup for the OpenCL content to be avaliable. incase we want some real speed...
try:
  make_mod('manager_cl', os.path.dirname(__file__), ['manager_cl.h', 'manager_cl.c'], openCL=True)
  import manager_cl
except:
  manager_cl = None



class Manager:
  """Simple class that manages a bunch of objects of type VideoNode - is given a bunch of these objects and then provides a nextFrame method. This method calls the nextFrame method for each object, but does so in an order that satisfies the dependencies. For conveniance it also provides a run method for use with the ViewVideo objects - it calls the cv.WaitKey function as well as nextFrame, and optionally keeps the framerate correct - makes simple visualisations constructed with ReadVideo objects easy to do. It also manages the OpenCL context and queue, in the event that you are optimising the video processing as such, so that frames can be passed between nodes without leaving the graphics card - the useCL parameter allows OpenCL optimisation to be switched off."""
  def __init__(self, useCL = True):
    self.videos = []
    self.dirty = True
    self.profile = defaultdict(float)
    self.profileRuncount = defaultdict(int)

    self.cl = None
Пример #8
0
# 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 <http://www.gnu.org/licenses/>.

import os.path
import math
import numpy

from utils.make import make_mod
from video_node import *

# The C version - we require that this be built, even if not used...
make_mod('backsub_dp_c', os.path.dirname(__file__), 'backsub_dp_c.c')
import backsub_dp_c

# The OpenCL version - try to compile it, and use it if at all possible...
try:
    make_mod('backsub_dp_cl',
             os.path.dirname(__file__),
             ['manager_cl.h', 'open_cl_help.h', 'backsub_dp_cl.c'],
             openCL=True)
    import backsub_dp_cl
except:
    backsub_dp_cl = None


# The python wrapper around BackSubCore, to give it the right interface etc.
class BackSubDP(VideoNode):
Пример #9
0
try:
  import scipy.weave as weave
except:
  weave = None

from utils.start_cpp import start_cpp
from utils.make import make_mod

from video_node import *



# The OpenCL version - try to compile it, and use it if at all possible...
try:
  make_mod('colour_bias_cl', os.path.dirname(__file__), ['manager_cl.h', 'open_cl_help.h', 'colour_bias_cl.c'], openCL=True)
  import colour_bias_cl
except:
  colour_bias_cl = None



class ColourBias(VideoNode):
  """This converts rgb colour to a luminance/chromaticity colour space - nothing special, specific or well defined. Its trick is that you can choose the scale of the luminance channel, to adjust distance in the space to emphasis differences in colour or lightness. Luminance is put into the red channel with chromaticity in green and blue. Done such that the volume of the colour space always remains as 1."""
  def __init__(self, lumScale = 1.0, noiseFloor = 0.2, cl = None):
    """lumScale is how much to bias the luminance - high makes luminance matter, low makes chromaticity matter; 1 is no bias at all. noiseFloor stabalises the variance when it gets darker than the provided value, to prevent noise resulting in unstable chromaticity information - it must not exceed sqrt(3)/3. cl is the return value from getCL() on the manager object - if not provided OpenCL will not be used."""
    self.chromaScale = 0.7176 * math.pow(1.0/lumScale,1.0/3.0)
    self.lumScale = lumScale * self.chromaScale

    self.noiseFloor = noiseFloor
Пример #10
0
# Copyright 2016 Tom SF Haines

# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# Compile the code if need be...
from utils.make import make_mod
import os.path

make_mod('transform_c',
         os.path.dirname(__file__),
         ['bspline.h', 'bspline.c', 'transform_c.h', 'transform_c.c'],
         numpy=True)

del make_mod

# Import the code...
from transform_c import *
Пример #11
0
#   http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import os.path
import unittest

import math
import numpy

from utils.make import make_mod



# Compile the code if need be...
make_mod('maxflow_c', os.path.dirname(__file__), ['maxflow_c.h', 'maxflow_c.c'])



# Import the compiled module into this space, so we can pretend they are one and the same, just with automatic compilation...
from maxflow_c import *



# Some unit testing...
class TestMaxFlow(unittest.TestCase):
  def test_degenerate(self):
    mf = MaxFlow(2,1)
    mf.set_source(0)
    mf.set_sink(1)
    mf.set_edges(numpy.array([0]), numpy.array([1]))
Пример #12
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os.path
import time
from collections import defaultdict

import cv

from utils.make import make_mod
from video_node import VideoNode

# Arrange for the Python module that does iniail setup for the OpenCL content to be avaliable. incase we want some real speed...
try:
    make_mod('manager_cl',
             os.path.dirname(__file__), ['manager_cl.h', 'manager_cl.c'],
             openCL=True)
    import manager_cl
except:
    manager_cl = None


class Manager:
    """Simple class that manages a bunch of objects of type VideoNode - is given a bunch of these objects and then provides a nextFrame method. This method calls the nextFrame method for each object, but does so in an order that satisfies the dependencies. For conveniance it also provides a run method for use with the ViewVideo objects - it calls the cv.WaitKey function as well as nextFrame, and optionally keeps the framerate correct - makes simple visualisations constructed with ReadVideo objects easy to do. It also manages the OpenCL context and queue, in the event that you are optimising the video processing as such, so that frames can be passed between nodes without leaving the graphics card - the useCL parameter allows OpenCL optimisation to be switched off."""
    def __init__(self, useCL=True):
        self.videos = []
        self.dirty = True
        self.profile = defaultdict(float)
        self.profileRuncount = defaultdict(int)

        self.cl = None