CVB++ 15.0
Loading...
Searching...
No Matches
Cvb::PyScript Namespace Reference

Namespace for the python scripting package. More...

Classes

class  Context
 Global python scripting context. More...
 
struct  InterpreterVersion
 Active interpreter version. More...
 
class  Object
 Variant like python object. More...
 

Typedefs

using ContextPtr = std::shared_ptr<Context>
 Convenience shared pointer for Context.
 
using ObjectPtr = std::shared_ptr<Object>
 Convenience shared pointer for Object.
 

Detailed Description

Namespace for the python scripting package.

Remarks
CMake users: Link to imported target CVB::CvbPyScript

Data between c++ and python is transferred through generic a Object. This module provides support for generic data types as well as for various CVB types. Depending on the type, instances are transported either using shared the ownership or a a deep copy. Types may loose the status of some cached members. For pointer based types always the most derived type is used for storage in the object. When retrieving pointer based types always an instance of the most derived type is created and automatically cast to the requested type. Enum classes are stored as 64 bit integer.

Example
Using a python for some flexible image processing (process.py). Here pixel format conversion is implmented in python.
import cvb
class Converter:
def __init__(self, src_format, dst_format, size):
self._converter = cvb.PixelFormatConverter(src_format, dst_format)
self._dst_image = cvb.Image.from_pixel_format(size, dst_format)
def run(self, src_image):
self._converter.execute(src_image, self._dst_image)
return self._dst_image

Using the converter form C++ is done like this:

context->AppendToSysPath(processPath); // now process.py is found for importing
auto processModule = context->Import(CVB_LIT("process"));
auto typeObj = processModule->Attribute(CVB_LIT("Converter"));
auto converterArgs = PyScript::Object::MakeTuple(PfncFormat::BayerBG10, PfncFormat::RGB8, Size2D<int>(640, 480));
auto converterObj = typeObj->Run(*converterArgs);
auto runMethod = converterObj->Attribute(CVB_LIT("run"));
auto runArgs = PyScript::Object::MakeTuple(*srcImage);
auto dstImage = runMethod->Run(*runArgs)->As<Cvb::ImagePtr>();
static ContextPtr CreateOrGet()
Creates a context.
Definition decl_context.hpp:50
static ObjectPtr MakeTuple(T &&...args)
Creates tuple with the given types.
Definition decl_object.hpp:682
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86
Interface
List of supported types to transfer from and to python.

Special type:

  • list: dynamic list (see Object for details)
  • tuple: argument passing (see Object for details)

Generic types:

  • bool: copy 1 byte
  • integer: copy 8 byte
  • unsigned integer: copy 8 byte
  • floating point: copy 8 byte
  • string: both byte or wide are supported, with terminator

CVB types: