github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/swig/pycv/pycv.swigcxx (about) 1 //go:build ignore 2 /* swig -go -cgo -c++ -intgosize 64 pycv.swigcxx */ 3 4 %module(directors="1") pycv 5 %include <typemaps.i> 6 %include <std_map.i> 7 %include <std_string.i> 8 %include <std_vector.i> 9 %include <exception.i> 10 %{ 11 #include "pycv.h" 12 %} 13 14 %exception { 15 try { 16 $action; 17 } catch (const std::exception& e) { 18 _swig_gopanic(e.what()); 19 } 20 } 21 22 %rename(Wrapped_PyImage) PyImage; 23 %rename(Wrapped_PyImage_LocalInit) LocalInit; 24 %rename(Wrapped_PyImage_Do) Do; 25 26 %header %{ 27 28 %} 29 %include "pycv.h" 30 31 %go_import("fmt") 32 %insert(go_wrapper) %{ 33 34 type PyImage interface { 35 Wrapped_PyImage 36 LocalInit(LocalInitRequest) (LocalInitResponse, error); 37 Do(DoRequest) (DoResponse, error); 38 } 39 40 func NewPyImage() PyImage { 41 e := NewWrapped_PyImage() 42 return e.(PyImage) 43 } 44 45 // catch will recover from a panic and store the recover message to the error 46 // parameter. The error must be passed by reference in order to be returned to the 47 // calling function. 48 func catch(err *error) { 49 if r := recover(); r != nil { 50 *err = fmt.Errorf("%v", r) 51 } 52 } 53 54 func GlobalInit(model_dir string, gpu_id int) (err error) { 55 defer catch(&err) 56 Wrapped_PyImageGlobalInit(model_dir, gpu_id) 57 return 58 } 59 60 func GlobalRelease() (err error){ 61 defer catch(&err) 62 Wrapped_PyImageGlobalRelease() 63 return 64 } 65 66 func (arg SwigcptrWrapped_PyImage) LocalInit(req LocalInitRequest) (resp LocalInitResponse, err error) { 67 defer catch(&err) 68 resp = NewLocalInitResponse() 69 arg.Wrapped_PyImage_LocalInit(req, resp) 70 return 71 } 72 73 func (arg SwigcptrWrapped_PyImage) Do(req DoRequest) (resp DoResponse, err error) { 74 defer catch(&err) 75 resp = NewDoResponse() 76 arg.Wrapped_PyImage_Do(req, resp) 77 return 78 } 79 80 %}