...
 
Commits (26)
......@@ -133,3 +133,10 @@ cdef extern from "kvideo.h":
FF_COLOR_YUV
FF_COLOR_YUV_JPEG
FF_COLOR_XYZ
cdef extern from "kblock.h":
KObject* kblock_new (const char* block_type)
KErrorCode kblock_set_input (KObject* block, const char* key, KObject* io_buffer)
KErrorCode kblock_set_option (KObject* block, const char* key, ...)
KObject* kblock_get_output (KObject* block, const char* key)
KErrorCode kblock_execute (KObject* block)
include "capi.pxi"
# Parent class: KClass (KObject)
cdef class KClass:
cdef KObject* kobj
# Extension Type: File
cdef class File:
pass
# Extension Type: Image
cdef class Image:
cdef KObject* kobj
cdef class Image(KClass):
pass
cdef class ImageCoordIter:
cdef KImageIterator kiter
......@@ -22,11 +26,10 @@ cdef class ImageNeighborhoodIter:
cdef KObject* kimg
cdef Image nhood
# Extension Type: Video
cdef class Video:
cdef KObject* kobj
cdef class Video(KClass):
pass
# Dell Monitor Support
# (800) 822-8965
# 1 to 2 business days
# 10 times
cdef class Block(KClass):
pass
......@@ -14,15 +14,21 @@ cdef _pythonize_kimage (KObject* img):
"""
Get a new Image() instance and wrap it around the supplied KObject*
"""
if not img:
return None
kimg = Image(blank=True)
kimg.kobj = img
return kimg
cdef _pythonize_kvideo (KObject* vid):
"""
Get a new Video() instance and wrap it around the supplied KObject*
"""
if not vid:
return None
kvid = Video(blank=True)
kvid.kobj = vid
......@@ -117,7 +123,11 @@ cdef class File:
raise Exception (kerror(UNSUPPORTED_FORMAT))
cdef class Image:
cdef class KClass:
pass
cdef class Image(KClass):
"""
Represents an Image with an arbitrary number of spatial dimensions
and channels. Internal pixel buffer is mutable both in value and
......@@ -572,6 +582,7 @@ cdef class ImageNeighborhoodIter:
kobject_release (self.kimg)
raise StopIteration
cdef class Video:
"""
Represents an Video, loaded from FFMPEG
......@@ -601,7 +612,7 @@ cdef class Video:
def frame_to_image_decoded(self):
return _pythonize_kimage (kvideo_frame_to_kimage_decoded(self.kobj))
def frame_qp_table(self):
return _pythonize_kimage (kvideo_frame_qp_table(self.kobj))
......@@ -622,14 +633,14 @@ cdef class Video:
if sys.version_info[0] is 3:
return kvideo_frame_next_type(self.kobj, <char>str.encode(ftype_target[0])[0])
else:
return kvideo_frame_next_type(self.kobj, <char>ord(ftype_target.encode()[0]))
return kvideo_frame_next_type(self.kobj, <char>ord(ftype_target.encode()[0]))
def frame_type(self):
return chr(kvideo_frame_type(self.kobj))
def codec_name(self):
return kvideo_codec_name(self.kobj).decode()
def fps(self):
return kvideo_fps(self.kobj)
......@@ -673,3 +684,62 @@ cdef class Video:
d = self.duration()
return "Kaze Video: %dx%d duration: %d " % (h,w,d)
cdef class Block(KClass):
def __cinit__ (self, blockname):
cdef KObject* kobj = kblock_new(blockname)
if kobj == NULL:
raise Exception ("block not found:" + blockname)
self.kobj = kobj
def __dealloc__ (self):
kobject_release (self.kobj)
def set_input(self, key, KClass kobject):
cdef KErrorCode err
err = kblock_set_input (self.kobj, key, kobject.kobj)
if err != SUCCESS:
raise Exception (kerror(err))
def set_option(self, key, value):
cdef KErrorCode err
cdef char* strval
cdef int intval
cdef float floatval
t = type(value)
if t is str:
strval = value
err = kblock_set_option (self.kobj, key, strval)
elif t is int:
intval = value
err = kblock_set_option (self.kobj, key, intval)
elif t is float:
floatval = value
err = kblock_set_option (self.kobj, key, floatval)
else:
raise Exception ("value must be str, int, or float")
if err != SUCCESS:
raise Exception (kerror(err))
def execute(self):
cdef KErrorCode err
err = kblock_execute (self.kobj)
return err
def get_output(self, key):
cdef KObject* kobj = kblock_get_output (self.kobj, key)
if kobj == NULL:
return None
if (KOBJECT_IMAGE == kobject_type(kobj)):
return _pythonize_kimage (kobj)
else:
kobject_release (kobj)
raise Exception (kerror(UNSUPPORTED_FORMAT))
......@@ -10,6 +10,7 @@ set (EXAMPLE_IMAGES
set (EXAMPLE_PYTHON
median.py
cython_average.py
)
if (BUILD_EXAMPLES)
......
#!/usr/bin/env python
import os
import sys
#temp fix until python has an install command
sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib"))
import kazepy as K
img = K.File.read('images/lena.png')
averageblock = K.Block("average")
averageblock.set_input("input",img)
averageblock.set_option("radius", 7)
averageblock.execute()
averaged = averageblock.get_output("output")
averaged.write('cython_average.png')
#!/usr/bin/env python
import os
import sys
#temp fix until python has an install command
sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib"))
import kazepy as K
......
This diff is collapsed.