├── .gitignore ├── README.md ├── examples ├── pil-to-halcon.py ├── test-blobs.py ├── test-data-import.py └── test-qrcode.py ├── hirsch-logo.png ├── hirsch-logo.svg ├── hirsch ├── __init__.py └── giv.py ├── license.md ├── maja-contour.png ├── qrblobexample.png ├── setup.py ├── src ├── HParseTypes.py ├── create-stub.py ├── h-parse.py ├── haffinetrans2d_autogen_methods_declarations.i ├── haffinetrans2d_autogen_methods_list.i ├── hbarcode_autogen_methods_declarations.i ├── hbarcode_autogen_methods_list.i ├── hcircle_autogen_methods_declarations.i ├── hcircle_autogen_methods_list.i ├── hdatacode2d_autogen_methods_declarations.i ├── hdatacode2d_autogen_methods_list.i ├── hdpoint2d_autogen_methods_declarations.i ├── hdpoint2d_autogen_methods_list.i ├── hellipse_autogen_methods_declarations.i ├── hellipse_autogen_methods_list.i ├── himage_autogen_methods_declarations.i ├── himage_autogen_methods_list.i ├── himagearray_autogen_methods_declarations.i ├── himagearray_autogen_methods_list.i ├── hline2d_autogen_methods_declarations.i ├── hline2d_autogen_methods_list.i ├── hline_autogen_methods_declarations.i ├── hline_autogen_methods_list.i ├── hpixval_autogen_methods_declarations.i ├── hpixval_autogen_methods_list.i ├── hpoint2d_autogen_methods_declarations.i ├── hpoint2d_autogen_methods_list.i ├── hrectangle1_autogen_methods_declarations.i ├── hrectangle1_autogen_methods_list.i ├── hrectangle2_autogen_methods_declarations.i ├── hrectangle2_autogen_methods_list.i ├── hregion_autogen_methods_declarations.i ├── hregion_autogen_methods_list.i ├── hregionarray_autogen_methods_declarations.i ├── hregionarray_autogen_methods_list.i ├── hrootobject_autogen_methods_declarations.i ├── hrootobject_autogen_methods_list.i ├── hspatialobject_autogen_methods_declarations.i ├── hspatialobject_autogen_methods_list.i ├── htemplate_autogen_methods_declarations.i ├── htemplate_autogen_methods_list.i ├── htuple_autogen_methods_declarations.i ├── htuple_autogen_methods_list.i ├── hxld_autogen_methods_declarations.i ├── hxld_autogen_methods_list.i ├── hxldarray_autogen_methods_declarations.i ├── hxldarray_autogen_methods_list.i ├── hxldcont_autogen_methods_declarations.i ├── hxldcont_autogen_methods_list.i ├── hxldcontarray_autogen_methods_declarations.i ├── hxldcontarray_autogen_methods_list.i ├── pyhaffinetrans2d.cc ├── pyhaffinetrans2d.h ├── pyhbarcode.cc ├── pyhbarcode.h ├── pyhcircle.cc ├── pyhcircle.h ├── pyhdatacode2d.cc ├── pyhdatacode2d.h ├── pyhdpoint2d.cc ├── pyhdpoint2d.h ├── pyhellipse.cc ├── pyhellipse.h ├── pyhimage.cc ├── pyhimage.h ├── pyhimagearray.cc ├── pyhimagearray.h ├── pyhirsch.cc ├── pyhirsch.h ├── pyhline2d.cc ├── pyhline2d.h ├── pyhpixval.cc ├── pyhpixval.h ├── pyhpoint2d.cc ├── pyhpoint2d.h ├── pyhrectangle1.cc ├── pyhrectangle1.h ├── pyhrectangle2.cc ├── pyhrectangle2.h ├── pyhregion.cc ├── pyhregion.h ├── pyhregionarray.cc ├── pyhregionarray.h ├── pyhtemplate.cc ├── pyhtemplate.h ├── pyhtuple.cc ├── pyhtuple.h ├── pyhtuple_util.cc ├── pyhtuple_util.h ├── pyhxld.cc ├── pyhxld.h ├── pyhxldarray.cc ├── pyhxldarray.h ├── pyhxldcont.cc ├── pyhxldcont.h ├── pyhxldcontarray.cc └── pyhxldcontarray.h ├── test_data ├── maja.png └── qrfoo.tif └── tests ├── code39.png ├── test-barcode.py └── test-with-numpy.py /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.pyc 3 | *~ 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![HirschLogo](hirsch-logo.png?raw=true) 2 | 3 | # Hirsch - A python binding to the MvTec HALCON library 4 | 5 | * Author: Dov Grobgeld 6 | * Created: 2013-12-14 Sat 7 | * Keywords: Python, Halcon 8 | * URL: 9 | * Version: 0.1 10 | 11 | # Description 12 | 13 | Hirsch is a python binding to the MVTec proprietory image processing 14 | library HALCON, see: http://www.halcon.com/ . It has currently been tested with HALCON version 9.0 . 15 | 16 | Note about the name. Since HALCON is a proprietary name belonging to MVTec, I have decided to name this binding Hirsch. 17 | 18 | # Licence 19 | 20 | The use of Hirsch requires a licence to the HALCON library. Please refer to the HALCON End User Legal Agreement (EULA) for details. 21 | 22 | The licence of the Python binding is LGPL3 and of the automatic python generator, GPL3. 23 | 24 | See license.md for license details about Hirsch. 25 | 26 | 27 | # Building 28 | 29 | There are two steps concerning building the Hirsch binding: 30 | 31 | ## Creating python binding code 32 | 33 | This step parses the Halcon include files and generates python binding. It is run by doing: 34 | 35 | python h-parse.py 36 | 37 | Note that you will need to edit h-parse.py to set the halcon include directory at the top of the files. 38 | 39 | This distribution contains pregenerated bindings for halcon version 9, so this step may be skipped. 40 | 41 | ## Compiling the python binding 42 | 43 | Please edit setup.py to specify include and library paths for halcon. Install as standard python modules: 44 | 45 | python setup.py install 46 | 47 | # Testing 48 | 49 | Here is an example of how to use Hirsch: 50 | 51 | from hirsch import HImage, HDataCode2D 52 | 53 | Filename = 'qr.tiff' 54 | img = HImage.ReadImage(Filename) 55 | print "Image size=", img.Width(), img.Height() 56 | 57 | QrDetector = HDataCode2D("QR Code","default_parameters","enhanced_recognition") 58 | QRContours,Handles,DataStrings = QrDetector.FindDataCode2d(img,"stop_after_result_num",1) 59 | print DataStrings 60 | 61 | A few more examples are available in examples. 62 | 63 | # Interface with giv 64 | 65 | No effort has been made yet to do bindings for the built in visualization. Instead the library `hirsch.giv` provides a simple interface for using the 66 | image viewer `giv` for visualization, see: http://giv.sourceforge.net/giv/index.html . 67 | 68 | Here is an example of how to view blobs with blob info with giv. 69 | 70 | from hirsch import HImage, HDataCode2D 71 | import hirsch.giv as giv 72 | 73 | Filename = 'qrfoo.tif' 74 | img = HImage.ReadImage(Filename) 75 | blobs = img.Threshold(0,128).Connection().ErosionCircle(3) 76 | 77 | blobs = [b for b in blobs if b.Circularity() > 0.5] 78 | 79 | giv.ViewRegions(blobs,image=img, props=['Circularity','Area']) 80 | 81 | Here is the resulting giv image: 82 | 83 | ![QR blob detection](qrblobexample.png?raw=true) 84 | 85 | When hoovering over the red blobs, the Circularity and the Area properties for those blobs are shown in a popup window. 86 | 87 | # Interface with numpy 88 | 89 | `HImage` transparently and quickly converts to and from a `numpy.array`. 90 | I.e. the following code can be used for converting from a 2D 91 | `numpy.array` to an `HImage` and the other way around: 92 | 93 | my_array = numpy.array(my_himg, copy=0) 94 | my_himg1 = hirsch.HImage(my_array) 95 | 96 | Note that an `HImage` can be used directly whenever an `numpy.array` 97 | is expected. E.g. to show an `HImage` with pylab: 98 | 99 | imshow(my_himg) 100 | 101 | The option `copy=0` to `numpy.array()` specifies that `my_array` will 102 | be pointing to the same memory as is used by the `my_himg`. Omitting 103 | this option will copy this memory. See `numpy.array`. 104 | 105 | # Interaction with ipython 106 | 107 | One of the nice aspects of the python binding is that it works 108 | transparently with ipython (interactive python). In particular the 109 | ipython autocompletion and help system are great tools for working 110 | interactively with hirsch. Here is an example of an interactive 111 | session: 112 | 113 | In [1]: from hirsch import * 114 | 115 | In [2]: from hirsch.giv import * 116 | 117 | In [3]: img = HImage.Read 118 | HImage.ReadGraySe HImage.ReadImage HImage.ReadSequence 119 | 120 | In [3]: img = HImage.ReadImage('test_data/ 121 | test_data/maja.png 122 | test_data/qrfoo.tif 123 | 124 | In [3]: img = HImage.ReadImage('test_data/maja.png') 125 | 126 | In [5]: img.Ed 127 | img.EdgesColor img.EdgesImage 128 | img.EdgesColorSubPix img.EdgesSubPix 129 | 130 | # The help text is the comment above the corresponding 131 | # method in the C++ h-file. 132 | In [5]: img.EdgesSubPix? 133 | Type: builtin_function_or_method 134 | String Form: 135 | Docstring: 136 | EdgesSubPix(Filter,Alpha,Low,High) 137 | 138 | Extract sub-pixel precise edges using Deriche, Lanser, Shen, or Canny 139 | filters. 140 | 141 | In [6]: edges = img.EdgesSubPix('canny',2,1,10) 142 | 143 | In [7]: len(edges) 144 | Out[7]: 432 145 | 146 | In [8]: ViewContours(edges,image=img,color='red',linewidth=2) 147 | 148 | ![QR blob detection](maja-contour.png?raw=true) 149 | 150 | In [9]: edges[0] 151 | 152 | Out[9]: 153 | 154 | # Note: Need to assign to a variable to use completion of an array. 155 | In [10]: e = edges[0] 156 | 157 | In [11]: e.MomentsXld? 158 | Type: builtin_function_or_method 159 | String Form: 160 | Docstring: 161 | MomentsXld() 162 | 163 | Geometric moments M20, M02, and M11 of contours or polygons. 164 | 165 | In [11]: e.MomentsXld() 166 | Out[11]: (-5002.824723977863, 2913.0275057177496, 10901.533649534855) 167 | 168 | In [12]: e.LengthXld() 169 | Out[12]: 56.4611522953062 170 | 171 | In [13]: max([e.LengthXld() for e in edges]) 172 | Out[13]: 327.5589860358794 173 | 174 | In [14]: LongEdges = [e for e in edges if e.LengthXld()>300] 175 | 176 | In [15]: ViewContours(LongEdges,image=img,color='red',linewidth=2) 177 | 178 | 179 | # Implementation notes 180 | 181 | The autogenerated codes resides in .i files. There are two such files for each Hirsch class. One containing the "list" code that define the mapping between python method names, the c-function implementation, and its documentation. The second contains the implementation of the c-functions. 182 | 183 | I have tried to make the binding as pythonesque as possible. This means that I have tried to use python structures as much as possible. E.g. for functions taking both HTuple and pod (plain old data) as input, the HTuple versions were skipped. 184 | 185 | One problem that I have not satisfactory solved are functions that return scalars by HTuple's. There is no indication in the header files that the returned value is a scalar and not an arbitrary length array. In these cases I return a Python Tuple as a return value and the user must dereference it. 186 | 187 | I have succesfully taken care of operator overloading. 188 | -------------------------------------------------------------------------------- /examples/pil-to-halcon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from hirsch import HImage 4 | import ctypes 5 | from PIL import Image 6 | 7 | def PILImageToHImage(img): 8 | """Convert a PIL image to a halcon image. Currently only works with 8-bit gray images""" 9 | # Convert it to Halcon 10 | if img.mode != 'L': 11 | raise Exception('Currently only support PIL images of type L') 12 | data = ctypes.create_string_buffer(img.tobytes()) 13 | width,height = img.size 14 | return HImage.GenImage1("byte",width,height,ctypes.addressof(data)) 15 | 16 | 17 | # Create an image 18 | im = Image.new("L", (8,4), "white") 19 | im.putpixel((0,0),0x42) 20 | im.putpixel((1,0),0x43) 21 | 22 | # Convert it to Halcon 23 | hi = PILImageToHImage(im) 24 | print '0x%02x 0x%02x'%(hi.GetGrayval(0,0)[0], 25 | hi.GetGrayval(0,1)[0]) 26 | 27 | -------------------------------------------------------------------------------- /examples/test-blobs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from hirsch import HImage, HDataCode2D 4 | import hirsch.giv as giv 5 | 6 | Filename = 'qrfoo.tif' 7 | img = HImage.ReadImage(Filename) 8 | 9 | blobs = img.Threshold(0,128).Connection() 10 | 11 | # A pythonesque way of filtering the blobs 12 | blobs = [b for b in blobs if b.Circularity() > 0.5] 13 | 14 | giv.ViewRegions(blobs,image=img, props=['Circularity','Area']) 15 | -------------------------------------------------------------------------------- /examples/test-data-import.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from hirsch import HImage 4 | import ctypes 5 | 6 | # Externally create data and import into Halcon. Should 7 | # perhaps be supported by c-binding. 8 | Data = ctypes.create_string_buffer('AB'*(4*4)) 9 | hi = HImage.GenImage1("byte",8,4,ctypes.addressof(Data)) 10 | print '0x%02x 0x%02x'%(hi.GetGrayval(0,0)[0], 11 | hi.GetGrayval(0,1)[0]) 12 | 13 | -------------------------------------------------------------------------------- /examples/test-qrcode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from hirsch import HImage, HDataCode2D 4 | 5 | Filename = 'qrfoo.tif' 6 | img = HImage.ReadImage(Filename) 7 | print "Image size=", img.Width(), img.Height() 8 | 9 | QrDetector = HDataCode2D("QR Code","default_parameters","enhanced_recognition") 10 | Contours,Handles,DataStrings = QrDetector.FindDataCode2d(img,"stop_after_result_num",1) 11 | print DataStrings 12 | -------------------------------------------------------------------------------- /hirsch-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/hirsch-logo.png -------------------------------------------------------------------------------- /hirsch/__init__.py: -------------------------------------------------------------------------------- 1 | from _hirsch import * 2 | 3 | -------------------------------------------------------------------------------- /hirsch/giv.py: -------------------------------------------------------------------------------- 1 | # Dov Grobgeld 2 | # 2013-11-12 Tue 3 | # 4 | # Some utilities for displaying halcon through giv. 5 | 6 | import os 7 | 8 | def RegionToGiv(region, color='red', balloon=None, path=None): 9 | polygons = '' 10 | for row,colStart,colEnd in zip(*region.GetRegionRuns()): 11 | polygons += ('m {colStart} {row}\n' 12 | '{colStart} {rowEnd}\n' 13 | '{colEnd} {rowEnd}\n' 14 | '{colEnd} {row}\n' 15 | '{colStart} {row}\n'.format 16 | (colStart = colStart, 17 | colEnd = colEnd+1, 18 | row = row, 19 | rowEnd = row+1)) 20 | header = ('$color {color}\n' 21 | '$polygon\n'.format(color=color)) 22 | 23 | if not balloon is None: 24 | header += '$balloon ' + balloon.replace('\n','\n$balloon ') + '\n' 25 | if not path is None: 26 | header += '$path ' + path + '\n' 27 | return (header 28 | + polygons 29 | + '\n' 30 | ) 31 | 32 | def ContourToGiv(contour, color='red', balloon=None, path=None, linewidth=1): 33 | curve = '' 34 | for row,col in zip(*contour.GetContourXld()): 35 | curve += '{col} {row}\n'.format(col=col+0.5,row=row+0.5) 36 | header = ('$color {color}\n' 37 | '$lw {linewidth}\n' 38 | .format(color=color, 39 | linewidth=linewidth)) 40 | 41 | if not balloon is None: 42 | header += '$balloon ' + balloon.replace('\n','\n$balloon ') + '\n' 43 | 44 | if not path is None: 45 | header += '$path ' + path + '\n' 46 | 47 | return (header 48 | + curve 49 | + '\n') 50 | 51 | def ViewRegions(regions, 52 | color='red/0.5', 53 | image=None, 54 | imageFilename=None, 55 | props=None, 56 | format='%.2f', 57 | givFilename = None): 58 | """Display regions on top of on image""" 59 | import tempfile 60 | 61 | if props is None: 62 | props = ['Area','X','Y'] 63 | 64 | if givFilename is None: 65 | givFilename = tempfile.NamedTemporaryFile(suffix='.giv').name 66 | unlinkGiv = True 67 | else: 68 | unlinkGiv = False 69 | 70 | fh = open(givFilename, 'w') 71 | if not image is None: 72 | ImgFilename = tempfile.NamedTemporaryFile(suffix='.tif').name 73 | image.WriteImage('tiff',0,ImgFilename) 74 | fh.write('$image ' + ImgFilename + '\n') 75 | elif not imageFilename is None: 76 | fh.write('$image ' + imageFilename + '\n') 77 | for i,blob in enumerate(regions): 78 | balloons = ['Blob id: %d'%i] 79 | for p in props: 80 | balloons += [p+': '+format%(eval('blob.'+p+'()'))] 81 | fh.write(RegionToGiv(blob, color,balloon='\n'.join(balloons))) 82 | fh.close() 83 | unlinkCommand = 'unlink ' + givFilename if unlinkGiv else '' 84 | os.system('(giv ' + givFilename + '; %s)&'%unlinkCommand) 85 | 86 | def ViewContours(contours, 87 | color='red/0.5', 88 | image=None, 89 | imageFilename=None, 90 | props=None, 91 | format='%.2f', 92 | linewidth=1, 93 | givFilename = None): 94 | """Display contours on top of on image""" 95 | import tempfile 96 | 97 | if props is None: 98 | props = ['LengthXld'] 99 | 100 | if givFilename is None: 101 | givFilename = tempfile.NamedTemporaryFile(suffix='.giv').name 102 | unlinkGiv = True 103 | else: 104 | unlinkGiv = False 105 | 106 | fh = open(givFilename, 'w') 107 | if not image is None: 108 | ImgFilename = tempfile.NamedTemporaryFile(suffix='.tif').name 109 | image.WriteImage('tiff',0,ImgFilename) 110 | fh.write('$image ' + ImgFilename + '\n') 111 | elif not imageFilename is None: 112 | fh.write('$image ' + imageFilename + '\n') 113 | for i,contour in enumerate(contours): 114 | balloons = ['Contour id: %d'%i] 115 | for p in props: 116 | balloons += [p+': '+ format%eval('contour.%s()'%p)] 117 | fh.write(ContourToGiv(contour, color,linewidth=linewidth,balloon='\n'.join(balloons))) 118 | fh.close() 119 | unlinkCommand = 'unlink ' + givFilename if unlinkGiv else '' 120 | os.system('(giv ' + givFilename + '; %s)&'%unlinkCommand) 121 | 122 | def ViewImg(img): 123 | import tempfile 124 | ImgFilename = tempfile.NamedTemporaryFile(suffix='.tif').name 125 | img.WriteImage('tiff',0,ImgFilename) 126 | unlinkCommand = 'unlink ' + ImgFilename 127 | os.system('(giv ' + ImgFilename + '; %s)&'%unlinkCommand) 128 | 129 | if __name__ == '__main__': 130 | import sys,os 131 | import platform 132 | sys.path.insert(0,'/home/dov/git/python-halcon/build/lib.linux-{machine}-2.7/'.\ 133 | format(machine=platform.machine())) 134 | import halcon 135 | 136 | Filename = '/home/dov/git/learning/halcon/maja.tif' 137 | img = halcon.HImage(Filename=Filename) 138 | 139 | ## Threshold the image 140 | region = img.Threshold(128,255) 141 | blobs = region.Connection() 142 | fh = open('/tmp/foo.giv','w') 143 | for i,blob in enumerate(blobs): 144 | fh.write('$image ' + Filename + '\n' 145 | + RegionToGiv(blob, 146 | color='green/0.8', 147 | balloon = 'Area=%d'%blob.Area(), 148 | path='Blobs/%d'%i)) 149 | 150 | edges = img.EdgesSubPix('canny', 2,1,10) 151 | for i,edge in enumerate(edges): 152 | fh.write(ContourToGiv(edge, 153 | balloon='Length=%.3f'%edge.LengthXld(), 154 | path='Contour/%d'%i 155 | )) 156 | 157 | os.system('giv /tmp/foo.giv') 158 | -------------------------------------------------------------------------------- /maja-contour.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/maja-contour.png -------------------------------------------------------------------------------- /qrblobexample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/qrblobexample.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from optparse import OptionParser 2 | from distutils.core import setup, Extension 3 | import sys 4 | 5 | # Set to include and library directory of halcon 6 | HalconIncludeDirs = ['/usr/local/halcon/include', 7 | '/usr/local/halcon/include/cpp'] 8 | HalconLibraryDir = '/usr/local/halcon/lib/x64-linux2.4-gcc40/' 9 | 10 | module1 = Extension('_hirsch', 11 | include_dirs = ['./src/'] + HalconIncludeDirs, 12 | library_dirs = [HalconLibraryDir], 13 | libraries=['halcon','halconcpp'], 14 | language = "c++", 15 | sources = ['src/pyhirsch.cc', 16 | 'src/pyhaffinetrans2d.cc', 17 | 'src/pyhellipse.cc', 18 | 'src/pyhcircle.cc', 19 | 'src/pyhrectangle1.cc', 20 | 'src/pyhrectangle2.cc', 21 | 'src/pyhpixval.cc', 22 | 'src/pyhtemplate.cc', 23 | 'src/pyhimagearray.cc', 24 | 'src/pyhpoint2d.cc', 25 | 'src/pyhdpoint2d.cc', 26 | 'src/pyhregion.cc', 27 | 'src/pyhregionarray.cc', 28 | 'src/pyhimage.cc', 29 | 'src/pyhxldcont.cc', 30 | 'src/pyhxldcontarray.cc', 31 | 'src/pyhtuple.cc', 32 | 'src/pyhdatacode2d.cc', 33 | 'src/pyhbarcode.cc', 34 | 'src/pyhxld.cc', 35 | 'src/pyhxldarray.cc', 36 | 'src/pyhline2d.cc', 37 | ], 38 | ) 39 | 40 | setup (name = 'Hirsch', 41 | version = '0.1', 42 | description = 'Python binding to MVTec HALCON', 43 | ext_modules = [module1], 44 | py_modules=['hirsch.giv'] 45 | ) 46 | 47 | -------------------------------------------------------------------------------- /src/create-stub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # This code should generates a header and a c++ file of the 4 | # requested type. 5 | 6 | import sys 7 | import os 8 | import re 9 | 10 | argp= 1 11 | 12 | do_pointer = 0 13 | do_iter = 0 14 | while argp < len(sys.argv) and sys.argv[argp][0:2]=='--': 15 | S_ = sys.argv[argp] 16 | argp+=1 17 | 18 | if S_=='--help': 19 | print '''create-stub - Create the stub of a halcon type 20 | 21 | Syntax: 22 | create-stub [--pointer] typename 23 | 24 | Options: 25 | --pointer Indicate that the type should be treated as a pointer. 26 | --iter Add iteration functions to the type. 27 | ''' 28 | exit(0) 29 | if S_=='--pointer': 30 | do_pointer = True 31 | continue 32 | if S_=='--iter': 33 | do_iter = True 34 | continue 35 | 36 | if argp >= len(sys.argv): 37 | type_name = 'HAffineTrans2D' # TBD: For debug! 38 | #print("Expected a type name!") 39 | #exit(-1) 40 | else: 41 | type_name = sys.argv[argp] 42 | 43 | # build the h-file 44 | basename = type_name.lower() 45 | py_type_name = re.sub('^H','PyHirsch',type_name) 46 | var_name = re.sub('^H','',type_name) 47 | h_filename = 'py'+basename + '.h' 48 | cc_filename = 'py'+basename + '.cc' 49 | print h_filename, cc_filename 50 | 51 | fh = open(h_filename, 'w') 52 | 53 | iter_h_line = ' int iter_pos;\n' if do_iter else '' 54 | maybe_pointer = '*' if do_pointer else '' 55 | maybe_pointer_deref = '->' if do_pointer else '.' 56 | maybe_address_of = '' if do_pointer else '&' 57 | basename_upper = basename.upper() 58 | 59 | fh.write('// Autogenerated file for Halcon type {type_name}\n' 60 | '#ifndef PY{basename_upper}_H\n' 61 | '#define {basename_upper}_H\n' 62 | '\n' 63 | '#include \n' 64 | '#include \n' 65 | '\n' 66 | 'PyObject *{py_type_name}_From{type_name}(Halcon::{type_name} {var_name});\n' 67 | '\n' 68 | 'typedef struct {{\n' 69 | ' PyObject_HEAD;\n' 70 | ' Halcon::{type_name} {maybe_pointer}{var_name};\n{iter_h_line}' 71 | '}} {py_type_name};\n' 72 | '\n' 73 | '#define {py_type_name}_Check(op) \\\n' 74 | ' PyObject_TypeCheck(op, &{py_type_name}Type)\n' 75 | '\n' 76 | 'void {py_type_name}AddToModule(PyObject *m);\n' 77 | '\n' 78 | 'extern PyTypeObject {py_type_name}Type;\n' 79 | '\n' 80 | '#endif\n' 81 | .format(**locals())) 82 | 83 | 84 | fh.close() 85 | 86 | # build the c-file 87 | free_var = (' if(self->{var_name})\n' 88 | ' delete self->{var_name};\n' 89 | ).format(**locals()) if do_pointer else ( 90 | ' // Explicit call to destructor.\n' 91 | ' self->{var_name}.~{type_name}();\n' 92 | ).format(**locals()) 93 | 94 | AllocateMember = (' self->{var_name}=new Halcon::{type_name};\n'.format(**locals()) 95 | if do_pointer else '') 96 | fh = open(cc_filename, 'w') 97 | fh.write('// Autogenerated file for halcon type {type_name}\n' 98 | '\n' 99 | '#include "pyhirsch.h"\n' 100 | '\n' 101 | 'static void\n' 102 | '{py_type_name}_dealloc({py_type_name}* self)\n' 103 | '{{\n' 104 | '{free_var}' 105 | ' Py_TYPE(self)->tp_free((PyObject*)self);\n' 106 | '}}\n' 107 | '\n' 108 | 'static int\n' 109 | '{py_type_name}_init({py_type_name} */*self*/, PyObject */*args*/, PyObject */*kwds*/)\n' 110 | '{{\n' 111 | ' // TBD - Use PyArg_ParseTupleAndKeywords() to do special initialziation\n' 112 | '{AllocateMember}' 113 | ' return 0;\n' 114 | '}}\n' 115 | '\n' 116 | '#include "{basename}_autogen_methods_declarations.i"\n' 117 | '\n' 118 | 'static PyMethodDef {py_type_name}_methods[] = {{\n' 119 | '#include "{basename}_autogen_methods_list.i"\n' 120 | ' {{NULL}} /* Sentinel */\n' 121 | '}};\n\n' 122 | .format(**locals())) 123 | 124 | if do_iter: 125 | fh.write('' 126 | 'Py_ssize_t {py_type_name}_Length(PyObject */*o*/)\n' 127 | '{{\n' 128 | ' Halcon::{type_name} *{var_name} = {maybe_address_of}((({py_type_name}*)o)->{var_name});\n' 129 | ' return {var_name}->Num(); // Return the length of the sequence\n' 130 | '}}\n' 131 | '\n' 132 | 'PyObject *\n' 133 | '{py_type_name}_GetItem(PyObject *o, Py_ssize_t i)\n' 134 | '{{\n' 135 | ' Halcon::{type_name} *{var_name} = {maybe_address_of}((({py_type_name}*)o)->{var_name});\n' 136 | ' double ret;\n' 137 | '\n' 138 | ' // TBD return value at pos i or NULL if out of bounds' 139 | '\n' 140 | ' return PyFloat_FromDouble(ret);\n' 141 | '}}\n' 142 | '\n' 143 | 'static PySequenceMethods {py_type_name}_sequence_methods = {{\n' 144 | ' {py_type_name}_Length, /* sq_length */\n' 145 | ' 0, /* sq_concat */\n' 146 | ' 0, /* sq_repeat */\n' 147 | ' {py_type_name}_GetItem, /* sq_item */\n' 148 | '}};\n' 149 | '\n' 150 | '\n' 151 | 'PyObject* {py_type_name}_iter(PyObject *self)\n' 152 | '{{\n' 153 | ' Py_INCREF(self);\n' 154 | ' (({py_type_name}*)self)->iter_pos = 0;\n' 155 | ' return self;\n' 156 | '}}\n' 157 | '\n' 158 | 'PyObject* {py_type_name}_iternext(PyObject *self)\n' 159 | '{{\n' 160 | ' {py_type_name} *p = ({py_type_name} *)self;\n' 161 | ' Halcon::{type_name} *{var_name} = {maybe_address_of}(p->{var_name});\n' 162 | '\n' 163 | ' if (p->iter_pos < {var_name}->Num()) {{\n' 164 | ' int i=p->iter_pos; // shortcut\n' 165 | ' p->iter_pos+=1;\n' 166 | ' // TBD initialize and return the value at pos i\n' 167 | ' double ret = 0;\n' 168 | '\n' 169 | ' return PyFloat_FromDouble(ret);\n' 170 | ' }}\n' 171 | ' else {{\n' 172 | ' /* Raising of standard StopIteration exception with empty value. */\n' 173 | ' PyErr_SetNone(PyExc_StopIteration);\n' 174 | ' return NULL;\n' 175 | ' }}\n' 176 | '}}\n' 177 | '\n' 178 | .format(**locals()) 179 | ) 180 | 181 | if do_pointer: 182 | new_method = 'PyType_GenericNew' 183 | else: 184 | fh.write('static PyObject *\n' 185 | '{py_type_name}_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/)\n' 186 | '{{\n' 187 | ' {py_type_name} *self;\n' 188 | '\n' 189 | ' self = ({py_type_name} *)type->tp_alloc(type, 0);\n' 190 | ' // Explicit call to constructor placement new\n' 191 | ' new(&self->{var_name}) Halcon::{type_name}();\n' 192 | ' \n' 193 | ' return (PyObject *)self;\n' 194 | '}}\n\n' 195 | .format(**locals())) 196 | new_method = '{py_type_name}_new'.format(**locals()) 197 | 198 | fh.write('PyObject *{py_type_name}_From{type_name}(Halcon::{type_name} {var_name})\n' 199 | '{{\n' 200 | ' {py_type_name} *self = ({py_type_name}*){new_method}(&{py_type_name}Type,NULL,NULL);\n' 201 | .format(**locals())) 202 | fh.write((' self->{var_name} = new Halcon::{type_name}({var_name});\n' 203 | if do_pointer else 204 | ' self->{var_name} = {var_name};\n') 205 | .format(**locals())) 206 | fh.write(' return (PyObject*)self;\n' 207 | '}}\n\n'.format(**locals())) 208 | 209 | if do_iter: 210 | sequence_methods = '&{py_type_name}_sequence_methods'.format(**locals()) 211 | iter_method = '&{py_type_name}_iter'.format(**locals()) 212 | iternext_method = '&{py_type_name}_iternext'.format(**locals()) 213 | iter_flags = '|Py_TPFLAGS_HAVE_ITER' 214 | else: 215 | sequence_methods = '0' 216 | iter_flags = '' 217 | iter_method = '0' 218 | iternext_method = '0' 219 | 220 | fh.write('PyTypeObject {py_type_name}Type = {{\n' 221 | ' PyVarObject_HEAD_INIT(NULL, 0)\n' 222 | ' 0, /*ob_size*/\n' 223 | ' "Halcon.{py_type_name}", /*tp_name*/\n' 224 | ' sizeof({py_type_name}), /*tp_basicsize*/\n' 225 | ' 0, /*tp_itemsize*/\n' 226 | ' (destructor){py_type_name}_dealloc, /*tp_dealloc*/\n' 227 | ' 0, /*tp_print*/\n' 228 | ' 0, /*tp_getattr*/\n' 229 | ' 0, /*tp_setattr*/\n' 230 | ' 0, /*tp_compare*/\n' 231 | ' 0, /*tp_repr*/\n' 232 | ' 0, /*tp_as_number*/\n' 233 | ' {sequence_methods}, /*tp_as_sequence*/\n' 234 | ' 0, /*tp_as_mapping*/\n' 235 | ' 0, /*tp_hash */\n' 236 | ' 0, /*tp_call*/\n' 237 | ' 0, /*tp_str*/\n' 238 | ' 0, /*tp_getattro*/\n' 239 | ' 0, /*tp_setattro*/\n' 240 | ' 0, /*tp_as_buffer*/\n' 241 | ' Py_TPFLAGS_DEFAULT{iter_flags}, /*tp_flags*/\n' 242 | ' "{py_type_name}", /* tp_doc */\n' 243 | ' 0, /* tp_traverse */\n' 244 | ' 0, /* tp_clear */\n' 245 | ' 0, /* tp_richcompare */\n' 246 | ' 0, /* tp_weaklistoffset */\n' 247 | ' {iter_method}, /* tp_iter */\n' 248 | ' {iternext_method}, /* tp_iternext */\n' 249 | ' {py_type_name}_methods, /* tp_methods */\n' 250 | ' 0, /* tp_members */\n' 251 | ' 0, /* tp_getset */\n' 252 | ' 0, /* tp_base */\n' 253 | ' 0, /* tp_dict */\n' 254 | ' 0, /* tp_descr_get */\n' 255 | ' 0, /* tp_descr_set */\n' 256 | ' 0, /* tp_dictoffset */\n' 257 | ' (initproc){py_type_name}_init, /* tp_init */\n' 258 | ' 0, /* tp_alloc */\n' 259 | ' {new_method}, /* tp_new */\n' 260 | '}};\n' 261 | '\n\n'.format(**locals())) 262 | 263 | fh.write('void {py_type_name}AddToModule(PyObject *m)\n' 264 | '{{\n' 265 | ' Py_INCREF(&{py_type_name}Type);\n' 266 | ' if (PyType_Ready(&{py_type_name}Type) < 0)\n' 267 | ' return;\n' 268 | ' PyModule_AddObject(m, "H{var_name}", (PyObject *)&{py_type_name}Type);\n' 269 | '}}\n\n'.format(**locals())); 270 | fh.close() 271 | -------------------------------------------------------------------------------- /src/h-parse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # This file is part of the Hirsch binding to the halcon image 4 | # processing library. It is licensed under GPL3.0 with the 5 | # additional restriction that the code it generates must be 6 | # licensed under LGPL3. 7 | # 8 | # Dov Grobgeld 9 | # dov.grobgeld@gmail.com 10 | # 2013-12-13 Fri 11 | 12 | import sys 13 | import CppHeaderParser 14 | import re 15 | import glob 16 | import json 17 | import HParseTypes 18 | 19 | HalconIncludeDirectory = '/home/dov/git/SolarJet/3rdParty/Halcon/' 20 | 21 | headersToParse = ['HCPPUtil', 22 | 'HImage', 23 | 'HImageArray', 24 | 'HRectangle', 25 | 'HPrimitives', 26 | 'HRegion', 27 | 'HRegionArray', 28 | 'HXLD', 29 | 'HXLDArray', 30 | 'HXLDCont', 31 | 'HXLDContArray', 32 | 'HTuple', 33 | 'HBarCode', 34 | 'HDataCode2D', 35 | 'HTemplate', 36 | 'HPixVal', 37 | ] 38 | myClasses = {} 39 | headerAsArray = {} 40 | classToFile = {} 41 | 42 | 43 | # Parse an h-file and automatically generate bindings. 44 | for headerType in headersToParse: 45 | headerFilename = HalconIncludeDirectory + headerType + '.h' 46 | # print 'Parsing ', headerFilename 47 | try: 48 | # Clean up the header file a bit 49 | headerStringList = list(open(headerFilename)) 50 | headerString = re.sub(r'LIntExport\s*','', ''.join(headerStringList)) 51 | cppHeader = CppHeaderParser.CppHeader(headerString, argType='string') 52 | except CppHeaderParser.CppParseError, e: 53 | print e 54 | sys.exit(1) 55 | 56 | for className,klass in cppHeader.classes.iteritems(): 57 | if not className in HParseTypes.knownClasses: 58 | continue 59 | hClass = HParseTypes.PyHalconClass(className, headerStringList) 60 | myClasses[className] = (klass,hClass) 61 | 62 | for className in myClasses.keys(): 63 | klass,hClass = myClasses[className] 64 | 65 | print ">>>> Processing ", className 66 | 67 | # Add all parents methods. 68 | public_methods = klass['methods']['public'] 69 | methodDoc = [] # List of same size as the public method 70 | for pm in public_methods: 71 | doc = hClass.extractMethodDoc(pm) 72 | methodDoc += [hClass.extractMethodDoc(pm)] 73 | 74 | private_methods = [m['name'] for m in klass['methods']['private']] 75 | k = klass 76 | ancestors = [] 77 | # This logic should move to HParseTypes! 78 | seen = set() 79 | ancestors = [kl['class'] for kl in k['inherits']] 80 | 81 | while len(ancestors): 82 | kn, ancestors = ancestors[0], ancestors[1:] 83 | 84 | if kn in seen: 85 | continue 86 | 87 | seen.add(kn) 88 | 89 | if not kn in HParseTypes.knownClasses: 90 | continue 91 | 92 | print 'Processing ancestor of', className, ':', kn 93 | 94 | k,hk = myClasses[kn] 95 | ancestors += [kl['class'] for kl in k['inherits'] 96 | if not kl['class'] in seen] 97 | 98 | for m in k['methods']['public']: 99 | if (not m['name'] in private_methods 100 | and not m['name']==kn): 101 | public_methods += [m] 102 | methodDoc += [hk.extractMethodDoc(m)] 103 | 104 | private_methods += [m['name'] for m in k['methods']['private']] 105 | 106 | for pm,doc in zip(public_methods,methodDoc): 107 | hClass.addMethod(pm,doc) 108 | 109 | hClass.pruneRedundantMethods() 110 | 111 | filename = '%s_autogen_methods_declarations.i'%className.lower() 112 | print 'Generating', filename 113 | with open(filename,'w') as fh: 114 | fh.write(hClass.getAllFunctionCode()) 115 | filename = '%s_autogen_methods_list.i'%className.lower() 116 | print 'Generating', filename 117 | with open(filename,'w') as fh: 118 | fh.write(hClass.getAllFunctionListCode()) 119 | 120 | # Coverage 121 | boundMethodsCount,allNonConstructMethodsCount = \ 122 | hClass.boundMethodsCount,hClass.allNonConstructMethodsCount 123 | if allNonConstructMethodsCount == 0: 124 | Coverage = '-' 125 | else: 126 | Coverage = '%.0f%%'%(100.0*boundMethodsCount/allNonConstructMethodsCount) 127 | print 'Coverage[%s] = %d/%d = %s'%(className, 128 | boundMethodsCount, 129 | allNonConstructMethodsCount, 130 | Coverage) 131 | -------------------------------------------------------------------------------- /src/haffinetrans2d_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschAffineTrans2D_Rotate(PyHirschAffineTrans2D*self, PyObject *args) 3 | { 4 | double phi; 5 | 6 | try { 7 | if (PyArg_ParseTuple(args, "d", &phi)) { 8 | self->AffineTrans2D.Rotate(phi); 9 | Py_INCREF(Py_None); 10 | return Py_None; 11 | } 12 | PyErr_Clear(); 13 | 14 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HAffineTrans2D.Rotate()"); 15 | return NULL; 16 | } 17 | catch (Halcon::HException &except) { 18 | PyErr_SetString(PyExc_RuntimeError, except.message); 19 | return NULL; 20 | } 21 | } 22 | 23 | PyObject * 24 | PyHirschAffineTrans2D_Identity(PyHirschAffineTrans2D*self, PyObject *) 25 | { 26 | try { 27 | self->AffineTrans2D.Identity(); 28 | Py_INCREF(Py_None); 29 | return Py_None; 30 | } 31 | catch (Halcon::HException &except) { 32 | PyErr_SetString(PyExc_RuntimeError, except.message); 33 | return NULL; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/haffinetrans2d_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Rotate", (PyCFunction)PyHirschAffineTrans2D_Rotate, METH_VARARGS, "Rotate(phi)\n\n" }, 2 | {"Identity", (PyCFunction)PyHirschAffineTrans2D_Identity, METH_NOARGS, "Identity()\n\n" }, -------------------------------------------------------------------------------- /src/hbarcode_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschBarCode_FindBarCode(PyHirschBarCode*self, PyObject *args) 3 | { 4 | PyObject* Image1; 5 | PyObject* Image; 6 | char* CodeType1; 7 | PyObject* CodeType; 8 | 9 | try { 10 | if (PyArg_ParseTuple(args, "OO", &Image,&CodeType)) { 11 | if (PyHirschImage_Check(Image) && PyHirschTuple_Check(CodeType)) { 12 | Halcon::HTuple DecodedDataStrings; 13 | PyObject *ret = PyTuple_New(2); 14 | PyTuple_SET_ITEM(ret, 0, PyHirschRegionArray_FromHRegionArray(self->BarCode->FindBarCode(*(((PyHirschImage*)Image)->Image),*(((PyHirschTuple*)CodeType)->Tuple),&DecodedDataStrings))); 15 | PyTuple_SET_ITEM(ret, 1, PyHirschTuple_FromHTuple(DecodedDataStrings)); 16 | 17 | return ret; 18 | } 19 | } 20 | PyErr_Clear(); 21 | if (PyArg_ParseTuple(args, "Os", &Image1,&CodeType1)) { 22 | if (PyHirschImage_Check(Image1)) { 23 | Halcon::HTuple DecodedDataStrings1; 24 | PyObject *ret = PyTuple_New(2); 25 | PyTuple_SET_ITEM(ret, 0, PyHirschRegionArray_FromHRegionArray(self->BarCode->FindBarCode(*(((PyHirschImage*)Image1)->Image),CodeType1,&DecodedDataStrings1))); 26 | PyTuple_SET_ITEM(ret, 1, PyHirschTuple_FromHTuple(DecodedDataStrings1)); 27 | 28 | return ret; 29 | } 30 | } 31 | PyErr_Clear(); 32 | 33 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HBarCode.FindBarCode()"); 34 | return NULL; 35 | } 36 | catch (Halcon::HException &except) { 37 | PyErr_SetString(PyExc_RuntimeError, except.message); 38 | return NULL; 39 | } 40 | } 41 | 42 | PyObject * 43 | PyHirschBarCode_CreateBarCodeModel(PyHirschBarCode*self, PyObject *args) 44 | { 45 | PyObject* GenParamNames; 46 | double GenParamValues1; 47 | char* GenParamNames1; 48 | PyObject* GenParamValues; 49 | 50 | try { 51 | if (PyArg_ParseTuple(args, "sd", &GenParamNames1,&GenParamValues1)) { 52 | self->BarCode->CreateBarCodeModel(GenParamNames1,GenParamValues1); 53 | Py_INCREF(Py_None); 54 | return Py_None; 55 | } 56 | PyErr_Clear(); 57 | if (PyArg_ParseTuple(args, "OO", &GenParamNames,&GenParamValues)) { 58 | if (PyHirschTuple_Check(GenParamNames) && PyHirschTuple_Check(GenParamValues)) { 59 | self->BarCode->CreateBarCodeModel(*(((PyHirschTuple*)GenParamNames)->Tuple),*(((PyHirschTuple*)GenParamValues)->Tuple)); 60 | Py_INCREF(Py_None); 61 | return Py_None; 62 | } 63 | } 64 | PyErr_Clear(); 65 | 66 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HBarCode.CreateBarCodeModel()"); 67 | return NULL; 68 | } 69 | catch (Halcon::HException &except) { 70 | PyErr_SetString(PyExc_RuntimeError, except.message); 71 | return NULL; 72 | } 73 | } 74 | 75 | PyObject * 76 | PyHirschBarCode_SetBarCodeParam(PyHirschBarCode*self, PyObject *args) 77 | { 78 | PyObject* GenParamNames; 79 | double GenParamValues1; 80 | char* GenParamNames1; 81 | PyObject* GenParamValues; 82 | 83 | try { 84 | if (PyArg_ParseTuple(args, "sd", &GenParamNames1,&GenParamValues1)) { 85 | self->BarCode->SetBarCodeParam(GenParamNames1,GenParamValues1); 86 | Py_INCREF(Py_None); 87 | return Py_None; 88 | } 89 | PyErr_Clear(); 90 | if (PyArg_ParseTuple(args, "OO", &GenParamNames,&GenParamValues)) { 91 | if (PyHirschTuple_Check(GenParamNames) && PyHirschTuple_Check(GenParamValues)) { 92 | self->BarCode->SetBarCodeParam(*(((PyHirschTuple*)GenParamNames)->Tuple),*(((PyHirschTuple*)GenParamValues)->Tuple)); 93 | Py_INCREF(Py_None); 94 | return Py_None; 95 | } 96 | } 97 | PyErr_Clear(); 98 | 99 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HBarCode.SetBarCodeParam()"); 100 | return NULL; 101 | } 102 | catch (Halcon::HException &except) { 103 | PyErr_SetString(PyExc_RuntimeError, except.message); 104 | return NULL; 105 | } 106 | } 107 | 108 | PyObject * 109 | PyHirschBarCode_SetHandle(PyHirschBarCode*self, PyObject *args) 110 | { 111 | long ID; 112 | 113 | try { 114 | if (PyArg_ParseTuple(args, "l", &ID)) { 115 | self->BarCode->SetHandle(ID); 116 | Py_INCREF(Py_None); 117 | return Py_None; 118 | } 119 | PyErr_Clear(); 120 | 121 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HBarCode.SetHandle()"); 122 | return NULL; 123 | } 124 | catch (Halcon::HException &except) { 125 | PyErr_SetString(PyExc_RuntimeError, except.message); 126 | return NULL; 127 | } 128 | } 129 | 130 | PyObject * 131 | PyHirschBarCode_GetBarCodeResult(PyHirschBarCode*self, PyObject *args) 132 | { 133 | PyObject* CandidateHandle; 134 | PyObject* ResultName; 135 | 136 | try { 137 | if (PyArg_ParseTuple(args, "OO", &CandidateHandle,&ResultName)) { 138 | if (PyHirschTuple_Check(CandidateHandle) && PyHirschTuple_Check(ResultName)) { 139 | return PyHirschTuple_FromHTuple(self->BarCode->GetBarCodeResult(*(((PyHirschTuple*)CandidateHandle)->Tuple),*(((PyHirschTuple*)ResultName)->Tuple))); 140 | } 141 | } 142 | PyErr_Clear(); 143 | 144 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HBarCode.GetBarCodeResult()"); 145 | return NULL; 146 | } 147 | catch (Halcon::HException &except) { 148 | PyErr_SetString(PyExc_RuntimeError, except.message); 149 | return NULL; 150 | } 151 | } 152 | 153 | PyObject * 154 | PyHirschBarCode_GetBarCodeParam(PyHirschBarCode*self, PyObject *args) 155 | { 156 | PyObject* GenParamNames; 157 | char* GenParamNames1; 158 | 159 | try { 160 | if (PyArg_ParseTuple(args, "s", &GenParamNames1)) { 161 | return PyHirschTuple_FromHTuple(self->BarCode->GetBarCodeParam(GenParamNames1)); 162 | } 163 | PyErr_Clear(); 164 | if (PyArg_ParseTuple(args, "O", &GenParamNames)) { 165 | if (PyHirschTuple_Check(GenParamNames)) { 166 | return PyHirschTuple_FromHTuple(self->BarCode->GetBarCodeParam(*(((PyHirschTuple*)GenParamNames)->Tuple))); 167 | } 168 | } 169 | PyErr_Clear(); 170 | 171 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HBarCode.GetBarCodeParam()"); 172 | return NULL; 173 | } 174 | catch (Halcon::HException &except) { 175 | PyErr_SetString(PyExc_RuntimeError, except.message); 176 | return NULL; 177 | } 178 | } 179 | 180 | #if PY_MAJOR_VERSION >= 3 181 | #define PyInt_FromLong PyLong_FromLong 182 | #endif 183 | 184 | PyObject * 185 | PyHirschBarCode_GetHandle(PyHirschBarCode*self, PyObject *) 186 | { 187 | try { 188 | return PyInt_FromLong(long(self->BarCode->GetHandle())); 189 | } 190 | catch (Halcon::HException &except) { 191 | PyErr_SetString(PyExc_RuntimeError, except.message); 192 | return NULL; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /src/hbarcode_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"FindBarCode", (PyCFunction)PyHirschBarCode_FindBarCode, METH_VARARGS, "FindBarCode(Image,CodeType)\n\nDetect and read bar code symbols in an image." }, 2 | {"CreateBarCodeModel", (PyCFunction)PyHirschBarCode_CreateBarCodeModel, METH_VARARGS, "CreateBarCodeModel(GenParamNames,GenParamValues)\n\nCreate a model of a bar code reader." }, 3 | {"SetBarCodeParam", (PyCFunction)PyHirschBarCode_SetBarCodeParam, METH_VARARGS, "SetBarCodeParam(GenParamNames,GenParamValues)\n\nSet selected parameters of the bar code model." }, 4 | {"SetHandle", (PyCFunction)PyHirschBarCode_SetHandle, METH_VARARGS, "SetHandle(ID)\n\n" }, 5 | {"GetBarCodeResult", (PyCFunction)PyHirschBarCode_GetBarCodeResult, METH_VARARGS, "GetBarCodeResult(CandidateHandle,ResultName)\n\nGet the alphanumerical results that were accumulated during the\ndecoding of bar code symbols." }, 6 | {"GetBarCodeParam", (PyCFunction)PyHirschBarCode_GetBarCodeParam, METH_VARARGS, "GetBarCodeParam(GenParamNames)\n\nGet one or several parameters that describe the bar code model." }, 7 | {"GetHandle", (PyCFunction)PyHirschBarCode_GetHandle, METH_NOARGS, "GetHandle()\n\n" }, -------------------------------------------------------------------------------- /src/hcircle_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschCircle_Phi(PyHirschCircle*self, PyObject *) 3 | { 4 | try { 5 | return PyFloat_FromDouble(self->Circle.Phi()); 6 | } 7 | catch (Halcon::HException &except) { 8 | PyErr_SetString(PyExc_RuntimeError, except.message); 9 | return NULL; 10 | } 11 | } 12 | 13 | PyObject * 14 | PyHirschCircle_Radius(PyHirschCircle*self, PyObject *) 15 | { 16 | try { 17 | return PyFloat_FromDouble(self->Circle.Radius()); 18 | } 19 | catch (Halcon::HException &except) { 20 | PyErr_SetString(PyExc_RuntimeError, except.message); 21 | return NULL; 22 | } 23 | } 24 | 25 | PyObject * 26 | PyHirschCircle_Center(PyHirschCircle*self, PyObject *) 27 | { 28 | try { 29 | return PyHirschPoint2D_FromHPoint2D(self->Circle.Center()); 30 | } 31 | catch (Halcon::HException &except) { 32 | PyErr_SetString(PyExc_RuntimeError, except.message); 33 | return NULL; 34 | } 35 | } 36 | 37 | PyObject * 38 | PyHirschCircle_Rb(PyHirschCircle*self, PyObject *) 39 | { 40 | try { 41 | return PyFloat_FromDouble(self->Circle.Rb()); 42 | } 43 | catch (Halcon::HException &except) { 44 | PyErr_SetString(PyExc_RuntimeError, except.message); 45 | return NULL; 46 | } 47 | } 48 | 49 | PyObject * 50 | PyHirschCircle_Ra(PyHirschCircle*self, PyObject *) 51 | { 52 | try { 53 | return PyFloat_FromDouble(self->Circle.Ra()); 54 | } 55 | catch (Halcon::HException &except) { 56 | PyErr_SetString(PyExc_RuntimeError, except.message); 57 | return NULL; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/hcircle_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Phi", (PyCFunction)PyHirschCircle_Phi, METH_NOARGS, "Phi()\n\n" }, 2 | {"Radius", (PyCFunction)PyHirschCircle_Radius, METH_NOARGS, "Radius()\n\n" }, 3 | {"Center", (PyCFunction)PyHirschCircle_Center, METH_NOARGS, "Center()\n\n" }, 4 | {"Rb", (PyCFunction)PyHirschCircle_Rb, METH_NOARGS, "Rb()\n\n" }, 5 | {"Ra", (PyCFunction)PyHirschCircle_Ra, METH_NOARGS, "Ra()\n\n" }, -------------------------------------------------------------------------------- /src/hdatacode2d_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"CreateDataCode2dModel", (PyCFunction)PyHirschDataCode2D_CreateDataCode2dModel, METH_VARARGS, "CreateDataCode2dModel(SymbolType,GenParamNames,GenParamValues)\n\nCreate a model of a 2D data code class." }, 2 | {"FindDataCode2d", (PyCFunction)PyHirschDataCode2D_FindDataCode2d, METH_VARARGS, "FindDataCode2d(Image,GenParamNames,GenParamValues)\n\nDetect and read 2D data code symbols in an image or\ntrain the 2D data code model." }, 3 | {"WriteDataCode2dModel", (PyCFunction)PyHirschDataCode2D_WriteDataCode2dModel, METH_VARARGS, "WriteDataCode2dModel(FileName)\n\nWrites a 2D data code model into a file." }, 4 | {"ReadDataCode2dModel", (PyCFunction)PyHirschDataCode2D_ReadDataCode2dModel, METH_VARARGS, "ReadDataCode2dModel(FileName)\n\nRead a 2D data code model from a file and create a new model." }, 5 | {"GetDataCode2dResults", (PyCFunction)PyHirschDataCode2D_GetDataCode2dResults, METH_VARARGS, "GetDataCode2dResults(CandidateHandle,ResultNames)\n\nGet the alphanumerical results that were accumulated during the\nsearch for 2D data code symbols." }, 6 | {"SetDataCode2dParam", (PyCFunction)PyHirschDataCode2D_SetDataCode2dParam, METH_VARARGS, "SetDataCode2dParam(GenParamNames,GenParamValues)\n\nSet selected parameters of the 2D data code model." }, 7 | {"SetHandle", (PyCFunction)PyHirschDataCode2D_SetHandle, METH_VARARGS, "SetHandle(ID)\n\n" }, 8 | {"QueryDataCode2dParams", (PyCFunction)PyHirschDataCode2D_QueryDataCode2dParams, METH_VARARGS, "QueryDataCode2dParams(QueryName)\n\nGet for a given 2D data code model the names of the generic\nparameters or objects that can be used in the other 2D data code\noperators." }, 9 | {"GetDataCode2dParam", (PyCFunction)PyHirschDataCode2D_GetDataCode2dParam, METH_VARARGS, "GetDataCode2dParam(GenParamNames)\n\nGet one or several parameters that describe the 2D data code model." }, 10 | {"GetHandle", (PyCFunction)PyHirschDataCode2D_GetHandle, METH_NOARGS, "GetHandle()\n\n" }, -------------------------------------------------------------------------------- /src/hdpoint2d_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | #if PY_MAJOR_VERSION >= 3 2 | #define PyInt_FromLong PyLong_FromLong 3 | #endif 4 | 5 | PyObject * 6 | PyHirschDPoint2D_Y(PyHirschDPoint2D*self, PyObject *) 7 | { 8 | try { 9 | return PyInt_FromLong(long(self->DPoint2D.Y())); 10 | } 11 | catch (Halcon::HException &except) { 12 | PyErr_SetString(PyExc_RuntimeError, except.message); 13 | return NULL; 14 | } 15 | } 16 | 17 | #if PY_MAJOR_VERSION >= 3 18 | #define PyInt_FromLong PyLong_FromLong 19 | #endif 20 | 21 | PyObject * 22 | PyHirschDPoint2D_X(PyHirschDPoint2D*self, PyObject *) 23 | { 24 | try { 25 | return PyInt_FromLong(long(self->DPoint2D.X())); 26 | } 27 | catch (Halcon::HException &except) { 28 | PyErr_SetString(PyExc_RuntimeError, except.message); 29 | return NULL; 30 | } 31 | } 32 | 33 | PyObject * 34 | PyHirschDPoint2D_Inside(PyHirschDPoint2D*self, PyObject *args) 35 | { 36 | PyObject* pp; 37 | PyObject* lr; 38 | 39 | try { 40 | if (PyArg_ParseTuple(args, "OO", &pp,&lr)) { 41 | if (PyHirschDPoint2D_Check(pp) && PyHirschDPoint2D_Check(lr)) { 42 | return PyBool_FromLong(self->DPoint2D.Inside(Halcon::HDPoint2D((((PyHirschDPoint2D*)pp)->DPoint2D)),Halcon::HDPoint2D((((PyHirschDPoint2D*)lr)->DPoint2D)))); 43 | } 44 | } 45 | PyErr_Clear(); 46 | 47 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HDPoint2D.Inside()"); 48 | return NULL; 49 | } 50 | catch (Halcon::HException &except) { 51 | PyErr_SetString(PyExc_RuntimeError, except.message); 52 | return NULL; 53 | } 54 | } 55 | 56 | #if PY_MAJOR_VERSION >= 3 57 | #define PyInt_FromLong PyLong_FromLong 58 | #endif 59 | 60 | PyObject * 61 | PyHirschDPoint2D_Z(PyHirschDPoint2D*self, PyObject *) 62 | { 63 | try { 64 | return PyInt_FromLong(long(self->DPoint2D.Z())); 65 | } 66 | catch (Halcon::HException &except) { 67 | PyErr_SetString(PyExc_RuntimeError, except.message); 68 | return NULL; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/hdpoint2d_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Y", (PyCFunction)PyHirschDPoint2D_Y, METH_NOARGS, "Y()\n\n" }, 2 | {"X", (PyCFunction)PyHirschDPoint2D_X, METH_NOARGS, "X()\n\n" }, 3 | {"Inside", (PyCFunction)PyHirschDPoint2D_Inside, METH_VARARGS, "Inside(pp,lr)\n\n" }, 4 | {"Z", (PyCFunction)PyHirschDPoint2D_Z, METH_NOARGS, "Z()\n\n" }, -------------------------------------------------------------------------------- /src/hellipse_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschEllipse_Phi(PyHirschEllipse*self, PyObject *) 3 | { 4 | try { 5 | return PyFloat_FromDouble(self->Ellipse.Phi()); 6 | } 7 | catch (Halcon::HException &except) { 8 | PyErr_SetString(PyExc_RuntimeError, except.message); 9 | return NULL; 10 | } 11 | } 12 | 13 | PyObject * 14 | PyHirschEllipse_Center(PyHirschEllipse*self, PyObject *) 15 | { 16 | try { 17 | return PyHirschPoint2D_FromHPoint2D(self->Ellipse.Center()); 18 | } 19 | catch (Halcon::HException &except) { 20 | PyErr_SetString(PyExc_RuntimeError, except.message); 21 | return NULL; 22 | } 23 | } 24 | 25 | PyObject * 26 | PyHirschEllipse_Rb(PyHirschEllipse*self, PyObject *) 27 | { 28 | try { 29 | return PyFloat_FromDouble(self->Ellipse.Rb()); 30 | } 31 | catch (Halcon::HException &except) { 32 | PyErr_SetString(PyExc_RuntimeError, except.message); 33 | return NULL; 34 | } 35 | } 36 | 37 | PyObject * 38 | PyHirschEllipse_Ra(PyHirschEllipse*self, PyObject *) 39 | { 40 | try { 41 | return PyFloat_FromDouble(self->Ellipse.Ra()); 42 | } 43 | catch (Halcon::HException &except) { 44 | PyErr_SetString(PyExc_RuntimeError, except.message); 45 | return NULL; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/hellipse_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Phi", (PyCFunction)PyHirschEllipse_Phi, METH_NOARGS, "Phi()\n\n" }, 2 | {"Center", (PyCFunction)PyHirschEllipse_Center, METH_NOARGS, "Center()\n\n" }, 3 | {"Rb", (PyCFunction)PyHirschEllipse_Rb, METH_NOARGS, "Rb()\n\n" }, 4 | {"Ra", (PyCFunction)PyHirschEllipse_Ra, METH_NOARGS, "Ra()\n\n" }, -------------------------------------------------------------------------------- /src/hline2d_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschLine2D_Distance(PyHirschLine2D*self, PyObject *args) 3 | { 4 | PyObject* line; 5 | 6 | try { 7 | if (PyArg_ParseTuple(args, "O", &line)) { 8 | if (PyHirschLine2D_Check(line)) { 9 | return PyFloat_FromDouble(self->Line2D.Distance(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 10 | } 11 | } 12 | PyErr_Clear(); 13 | 14 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HLine2D.Distance()"); 15 | return NULL; 16 | } 17 | catch (Halcon::HException &except) { 18 | PyErr_SetString(PyExc_RuntimeError, except.message); 19 | return NULL; 20 | } 21 | } 22 | 23 | PyObject * 24 | PyHirschLine2D_Direction(PyHirschLine2D*self, PyObject *) 25 | { 26 | try { 27 | return PyFloat_FromDouble(self->Line2D.Direction()); 28 | } 29 | catch (Halcon::HException &except) { 30 | PyErr_SetString(PyExc_RuntimeError, except.message); 31 | return NULL; 32 | } 33 | } 34 | 35 | PyObject * 36 | PyHirschLine2D_End(PyHirschLine2D*self, PyObject *) 37 | { 38 | try { 39 | return PyHirschPoint2D_FromHPoint2D(self->Line2D.End()); 40 | } 41 | catch (Halcon::HException &except) { 42 | PyErr_SetString(PyExc_RuntimeError, except.message); 43 | return NULL; 44 | } 45 | } 46 | 47 | PyObject * 48 | PyHirschLine2D_Start(PyHirschLine2D*self, PyObject *) 49 | { 50 | try { 51 | return PyHirschPoint2D_FromHPoint2D(self->Line2D.Start()); 52 | } 53 | catch (Halcon::HException &except) { 54 | PyErr_SetString(PyExc_RuntimeError, except.message); 55 | return NULL; 56 | } 57 | } 58 | 59 | PyObject * 60 | PyHirschLine2D_Length(PyHirschLine2D*self, PyObject *) 61 | { 62 | try { 63 | return PyFloat_FromDouble(self->Line2D.Length()); 64 | } 65 | catch (Halcon::HException &except) { 66 | PyErr_SetString(PyExc_RuntimeError, except.message); 67 | return NULL; 68 | } 69 | } 70 | 71 | PyObject * 72 | PyHirschLine2D_PerpLinePoint(PyHirschLine2D*self, PyObject *args) 73 | { 74 | PyObject* p; 75 | 76 | try { 77 | if (PyArg_ParseTuple(args, "O", &p)) { 78 | if (PyHirschPoint2D_Check(p)) { 79 | return PyHirschPoint2D_FromHPoint2D(self->Line2D.PerpLinePoint(Halcon::HPoint2D((((PyHirschPoint2D*)p)->Point2D)))); 80 | } 81 | } 82 | PyErr_Clear(); 83 | 84 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HLine2D.PerpLinePoint()"); 85 | return NULL; 86 | } 87 | catch (Halcon::HException &except) { 88 | PyErr_SetString(PyExc_RuntimeError, except.message); 89 | return NULL; 90 | } 91 | } 92 | 93 | PyObject * 94 | PyHirschLine2D_Intersection(PyHirschLine2D*self, PyObject *args) 95 | { 96 | PyObject* line; 97 | 98 | try { 99 | if (PyArg_ParseTuple(args, "O", &line)) { 100 | if (PyHirschLine2D_Check(line)) { 101 | return PyHirschPoint2D_FromHPoint2D(self->Line2D.Intersection(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 102 | } 103 | } 104 | PyErr_Clear(); 105 | 106 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HLine2D.Intersection()"); 107 | return NULL; 108 | } 109 | catch (Halcon::HException &except) { 110 | PyErr_SetString(PyExc_RuntimeError, except.message); 111 | return NULL; 112 | } 113 | } 114 | 115 | PyObject * 116 | PyHirschLine2D_Parameter(PyHirschLine2D*self, PyObject *args) 117 | { 118 | PyObject* p; 119 | 120 | try { 121 | if (PyArg_ParseTuple(args, "O", &p)) { 122 | if (PyHirschPoint2D_Check(p)) { 123 | return PyFloat_FromDouble(self->Line2D.Parameter(Halcon::HPoint2D((((PyHirschPoint2D*)p)->Point2D)))); 124 | } 125 | } 126 | PyErr_Clear(); 127 | 128 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HLine2D.Parameter()"); 129 | return NULL; 130 | } 131 | catch (Halcon::HException &except) { 132 | PyErr_SetString(PyExc_RuntimeError, except.message); 133 | return NULL; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/hline2d_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Distance", (PyCFunction)PyHirschLine2D_Distance, METH_VARARGS, "Distance(line)\n\n" }, 2 | {"Direction", (PyCFunction)PyHirschLine2D_Direction, METH_NOARGS, "Direction()\n\n" }, 3 | {"End", (PyCFunction)PyHirschLine2D_End, METH_NOARGS, "End()\n\n" }, 4 | {"Start", (PyCFunction)PyHirschLine2D_Start, METH_NOARGS, "Start()\n\n" }, 5 | {"Length", (PyCFunction)PyHirschLine2D_Length, METH_NOARGS, "Length()\n\n" }, 6 | {"PerpLinePoint", (PyCFunction)PyHirschLine2D_PerpLinePoint, METH_VARARGS, "PerpLinePoint(p)\n\n" }, 7 | {"Intersection", (PyCFunction)PyHirschLine2D_Intersection, METH_VARARGS, "Intersection(line)\n\n" }, 8 | {"Parameter", (PyCFunction)PyHirschLine2D_Parameter, METH_VARARGS, "Parameter(p)\n\n" }, -------------------------------------------------------------------------------- /src/hline_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschLine_Length(PyHirschLine*self, PyObject *) 3 | { 4 | try { 5 | return PyFloat_FromDouble(self->Line.Length()); 6 | } 7 | catch (Halcon::HException &except) { 8 | PyErr_SetString(PyExc_RuntimeError, except.message); 9 | return NULL; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/hline_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Length", (PyCFunction)PyHirschLine_Length, METH_NOARGS, "Length()\n\n" }, -------------------------------------------------------------------------------- /src/hpixval_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschPixVal_ToByte(PyHirschPixVal*self, PyObject *) 3 | { 4 | try { 5 | self->PixVal->ToByte(); 6 | Py_INCREF(Py_None); 7 | return Py_None; 8 | } 9 | catch (Halcon::HException &except) { 10 | PyErr_SetString(PyExc_RuntimeError, except.message); 11 | return NULL; 12 | } 13 | } 14 | 15 | PyObject * 16 | PyHirschPixVal_ToFloat(PyHirschPixVal*self, PyObject *) 17 | { 18 | try { 19 | self->PixVal->ToFloat(); 20 | Py_INCREF(Py_None); 21 | return Py_None; 22 | } 23 | catch (Halcon::HException &except) { 24 | PyErr_SetString(PyExc_RuntimeError, except.message); 25 | return NULL; 26 | } 27 | } 28 | 29 | PyObject * 30 | PyHirschPixVal_ToInt1(PyHirschPixVal*self, PyObject *) 31 | { 32 | try { 33 | self->PixVal->ToInt1(); 34 | Py_INCREF(Py_None); 35 | return Py_None; 36 | } 37 | catch (Halcon::HException &except) { 38 | PyErr_SetString(PyExc_RuntimeError, except.message); 39 | return NULL; 40 | } 41 | } 42 | 43 | PyObject * 44 | PyHirschPixVal_ToInt4(PyHirschPixVal*self, PyObject *) 45 | { 46 | try { 47 | self->PixVal->ToInt4(); 48 | Py_INCREF(Py_None); 49 | return Py_None; 50 | } 51 | catch (Halcon::HException &except) { 52 | PyErr_SetString(PyExc_RuntimeError, except.message); 53 | return NULL; 54 | } 55 | } 56 | 57 | PyObject * 58 | PyHirschPixVal_ToUInt2(PyHirschPixVal*self, PyObject *) 59 | { 60 | try { 61 | self->PixVal->ToUInt2(); 62 | Py_INCREF(Py_None); 63 | return Py_None; 64 | } 65 | catch (Halcon::HException &except) { 66 | PyErr_SetString(PyExc_RuntimeError, except.message); 67 | return NULL; 68 | } 69 | } 70 | 71 | PyObject * 72 | PyHirschPixVal_ToComplexD(PyHirschPixVal*self, PyObject *) 73 | { 74 | try { 75 | self->PixVal->ToComplexD(); 76 | Py_INCREF(Py_None); 77 | return Py_None; 78 | } 79 | catch (Halcon::HException &except) { 80 | PyErr_SetString(PyExc_RuntimeError, except.message); 81 | return NULL; 82 | } 83 | } 84 | 85 | PyObject * 86 | PyHirschPixVal_ToInt2(PyHirschPixVal*self, PyObject *) 87 | { 88 | try { 89 | self->PixVal->ToInt2(); 90 | Py_INCREF(Py_None); 91 | return Py_None; 92 | } 93 | catch (Halcon::HException &except) { 94 | PyErr_SetString(PyExc_RuntimeError, except.message); 95 | return NULL; 96 | } 97 | } 98 | 99 | PyObject * 100 | PyHirschPixVal_Delete(PyHirschPixVal*self, PyObject *) 101 | { 102 | try { 103 | self->PixVal->Delete(); 104 | Py_INCREF(Py_None); 105 | return Py_None; 106 | } 107 | catch (Halcon::HException &except) { 108 | PyErr_SetString(PyExc_RuntimeError, except.message); 109 | return NULL; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/hpixval_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"ToByte", (PyCFunction)PyHirschPixVal_ToByte, METH_NOARGS, "ToByte()\n\n" }, 2 | {"ToFloat", (PyCFunction)PyHirschPixVal_ToFloat, METH_NOARGS, "ToFloat()\n\n" }, 3 | {"ToInt1", (PyCFunction)PyHirschPixVal_ToInt1, METH_NOARGS, "ToInt1()\n\n" }, 4 | {"ToInt4", (PyCFunction)PyHirschPixVal_ToInt4, METH_NOARGS, "ToInt4()\n\n" }, 5 | {"ToUInt2", (PyCFunction)PyHirschPixVal_ToUInt2, METH_NOARGS, "ToUInt2()\n\n" }, 6 | {"ToComplexD", (PyCFunction)PyHirschPixVal_ToComplexD, METH_NOARGS, "ToComplexD()\n\n" }, 7 | {"ToInt2", (PyCFunction)PyHirschPixVal_ToInt2, METH_NOARGS, "ToInt2()\n\n" }, 8 | {"Delete", (PyCFunction)PyHirschPixVal_Delete, METH_NOARGS, "Delete()\n\n" }, -------------------------------------------------------------------------------- /src/hpoint2d_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschPoint2D_Y(PyHirschPoint2D*self, PyObject *) 3 | { 4 | try { 5 | return PyFloat_FromDouble(self->Point2D.Y()); 6 | } 7 | catch (Halcon::HException &except) { 8 | PyErr_SetString(PyExc_RuntimeError, except.message); 9 | return NULL; 10 | } 11 | } 12 | 13 | PyObject * 14 | PyHirschPoint2D_X(PyHirschPoint2D*self, PyObject *) 15 | { 16 | try { 17 | return PyFloat_FromDouble(self->Point2D.X()); 18 | } 19 | catch (Halcon::HException &except) { 20 | PyErr_SetString(PyExc_RuntimeError, except.message); 21 | return NULL; 22 | } 23 | } 24 | 25 | PyObject * 26 | PyHirschPoint2D_Inside(PyHirschPoint2D*self, PyObject *args) 27 | { 28 | PyObject* pp; 29 | PyObject* lr; 30 | 31 | try { 32 | if (PyArg_ParseTuple(args, "OO", &pp,&lr)) { 33 | if (PyHirschPoint2D_Check(pp) && PyHirschPoint2D_Check(lr)) { 34 | return PyBool_FromLong(self->Point2D.Inside(Halcon::HPoint2D((((PyHirschPoint2D*)pp)->Point2D)),Halcon::HPoint2D((((PyHirschPoint2D*)lr)->Point2D)))); 35 | } 36 | } 37 | PyErr_Clear(); 38 | 39 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HPoint2D.Inside()"); 40 | return NULL; 41 | } 42 | catch (Halcon::HException &except) { 43 | PyErr_SetString(PyExc_RuntimeError, except.message); 44 | return NULL; 45 | } 46 | } 47 | 48 | PyObject * 49 | PyHirschPoint2D_Z(PyHirschPoint2D*self, PyObject *) 50 | { 51 | try { 52 | return PyFloat_FromDouble(self->Point2D.Z()); 53 | } 54 | catch (Halcon::HException &except) { 55 | PyErr_SetString(PyExc_RuntimeError, except.message); 56 | return NULL; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/hpoint2d_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Y", (PyCFunction)PyHirschPoint2D_Y, METH_NOARGS, "Y()\n\n" }, 2 | {"X", (PyCFunction)PyHirschPoint2D_X, METH_NOARGS, "X()\n\n" }, 3 | {"Inside", (PyCFunction)PyHirschPoint2D_Inside, METH_VARARGS, "Inside(pp,lr)\n\n" }, 4 | {"Z", (PyCFunction)PyHirschPoint2D_Z, METH_NOARGS, "Z()\n\n" }, -------------------------------------------------------------------------------- /src/hrectangle1_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschRectangle1_Overlaps(PyHirschRectangle1*self, PyObject *args) 3 | { 4 | PyObject* w; 5 | 6 | try { 7 | if (PyArg_ParseTuple(args, "O", &w)) { 8 | if (PyHirschRectangle1_Check(w)) { 9 | return PyBool_FromLong(self->Rectangle1.Overlaps(Halcon::HRectangle1((((PyHirschRectangle1*)w)->Rectangle1)))); 10 | } 11 | } 12 | PyErr_Clear(); 13 | 14 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle1.Overlaps()"); 15 | return NULL; 16 | } 17 | catch (Halcon::HException &except) { 18 | PyErr_SetString(PyExc_RuntimeError, except.message); 19 | return NULL; 20 | } 21 | } 22 | 23 | PyObject * 24 | PyHirschRectangle1_Distance(PyHirschRectangle1*self, PyObject *args) 25 | { 26 | PyObject* line; 27 | PyObject* point; 28 | 29 | try { 30 | if (PyArg_ParseTuple(args, "O", &point)) { 31 | if (PyHirschPoint2D_Check(point)) { 32 | return PyFloat_FromDouble(self->Rectangle1.Distance(Halcon::HPoint2D((((PyHirschPoint2D*)point)->Point2D)))); 33 | } 34 | } 35 | PyErr_Clear(); 36 | if (PyArg_ParseTuple(args, "O", &line)) { 37 | if (PyHirschLine2D_Check(line)) { 38 | return PyFloat_FromDouble(self->Rectangle1.Distance(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 39 | } 40 | } 41 | PyErr_Clear(); 42 | 43 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle1.Distance()"); 44 | return NULL; 45 | } 46 | catch (Halcon::HException &except) { 47 | PyErr_SetString(PyExc_RuntimeError, except.message); 48 | return NULL; 49 | } 50 | } 51 | 52 | PyObject * 53 | PyHirschRectangle1_Center(PyHirschRectangle1*self, PyObject *) 54 | { 55 | try { 56 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle1.Center()); 57 | } 58 | catch (Halcon::HException &except) { 59 | PyErr_SetString(PyExc_RuntimeError, except.message); 60 | return NULL; 61 | } 62 | } 63 | 64 | PyObject * 65 | PyHirschRectangle1_UpperLeft(PyHirschRectangle1*self, PyObject *) 66 | { 67 | try { 68 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle1.UpperLeft()); 69 | } 70 | catch (Halcon::HException &except) { 71 | PyErr_SetString(PyExc_RuntimeError, except.message); 72 | return NULL; 73 | } 74 | } 75 | 76 | PyObject * 77 | PyHirschRectangle1_Area(PyHirschRectangle1*self, PyObject *) 78 | { 79 | try { 80 | return PyFloat_FromDouble(self->Rectangle1.Area()); 81 | } 82 | catch (Halcon::HException &except) { 83 | PyErr_SetString(PyExc_RuntimeError, except.message); 84 | return NULL; 85 | } 86 | } 87 | 88 | PyObject * 89 | PyHirschRectangle1_CenterDistance(PyHirschRectangle1*self, PyObject *args) 90 | { 91 | PyObject* line; 92 | PyObject* point; 93 | 94 | try { 95 | if (PyArg_ParseTuple(args, "O", &point)) { 96 | if (PyHirschPoint2D_Check(point)) { 97 | return PyFloat_FromDouble(self->Rectangle1.CenterDistance(Halcon::HPoint2D((((PyHirschPoint2D*)point)->Point2D)))); 98 | } 99 | } 100 | PyErr_Clear(); 101 | if (PyArg_ParseTuple(args, "O", &line)) { 102 | if (PyHirschLine2D_Check(line)) { 103 | return PyFloat_FromDouble(self->Rectangle1.CenterDistance(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 104 | } 105 | } 106 | PyErr_Clear(); 107 | 108 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle1.CenterDistance()"); 109 | return NULL; 110 | } 111 | catch (Halcon::HException &except) { 112 | PyErr_SetString(PyExc_RuntimeError, except.message); 113 | return NULL; 114 | } 115 | } 116 | 117 | PyObject * 118 | PyHirschRectangle1_Includes(PyHirschRectangle1*self, PyObject *args) 119 | { 120 | PyObject* line; 121 | PyObject* point; 122 | 123 | try { 124 | if (PyArg_ParseTuple(args, "O", &point)) { 125 | if (PyHirschPoint2D_Check(point)) { 126 | return PyBool_FromLong(self->Rectangle1.Includes(Halcon::HPoint2D((((PyHirschPoint2D*)point)->Point2D)))); 127 | } 128 | } 129 | PyErr_Clear(); 130 | if (PyArg_ParseTuple(args, "O", &line)) { 131 | if (PyHirschLine2D_Check(line)) { 132 | return PyBool_FromLong(self->Rectangle1.Includes(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 133 | } 134 | } 135 | PyErr_Clear(); 136 | 137 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle1.Includes()"); 138 | return NULL; 139 | } 140 | catch (Halcon::HException &except) { 141 | PyErr_SetString(PyExc_RuntimeError, except.message); 142 | return NULL; 143 | } 144 | } 145 | 146 | PyObject * 147 | PyHirschRectangle1_LowerRight(PyHirschRectangle1*self, PyObject *) 148 | { 149 | try { 150 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle1.LowerRight()); 151 | } 152 | catch (Halcon::HException &except) { 153 | PyErr_SetString(PyExc_RuntimeError, except.message); 154 | return NULL; 155 | } 156 | } 157 | 158 | PyObject * 159 | PyHirschRectangle1_Height(PyHirschRectangle1*self, PyObject *) 160 | { 161 | try { 162 | return PyFloat_FromDouble(self->Rectangle1.Height()); 163 | } 164 | catch (Halcon::HException &except) { 165 | PyErr_SetString(PyExc_RuntimeError, except.message); 166 | return NULL; 167 | } 168 | } 169 | 170 | PyObject * 171 | PyHirschRectangle1_Width(PyHirschRectangle1*self, PyObject *) 172 | { 173 | try { 174 | return PyFloat_FromDouble(self->Rectangle1.Width()); 175 | } 176 | catch (Halcon::HException &except) { 177 | PyErr_SetString(PyExc_RuntimeError, except.message); 178 | return NULL; 179 | } 180 | } 181 | 182 | PyObject * 183 | PyHirschRectangle1_HMax(PyHirschRectangle1*self, PyObject *args) 184 | { 185 | PyObject* w; 186 | 187 | try { 188 | if (PyArg_ParseTuple(args, "O", &w)) { 189 | if (PyHirschRectangle1_Check(w)) { 190 | return PyHirschRectangle1_FromHRectangle1(self->Rectangle1.HMax(Halcon::HRectangle1((((PyHirschRectangle1*)w)->Rectangle1)))); 191 | } 192 | } 193 | PyErr_Clear(); 194 | 195 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle1.HMax()"); 196 | return NULL; 197 | } 198 | catch (Halcon::HException &except) { 199 | PyErr_SetString(PyExc_RuntimeError, except.message); 200 | return NULL; 201 | } 202 | } 203 | 204 | PyObject * 205 | PyHirschRectangle1_IsEmpty(PyHirschRectangle1*self, PyObject *) 206 | { 207 | try { 208 | return PyBool_FromLong(self->Rectangle1.IsEmpty()); 209 | } 210 | catch (Halcon::HException &except) { 211 | PyErr_SetString(PyExc_RuntimeError, except.message); 212 | return NULL; 213 | } 214 | } 215 | 216 | PyObject * 217 | PyHirschRectangle1_Intersection(PyHirschRectangle1*self, PyObject *args) 218 | { 219 | PyObject* w; 220 | PyObject* line; 221 | 222 | try { 223 | if (PyArg_ParseTuple(args, "O", &w)) { 224 | if (PyHirschRectangle1_Check(w)) { 225 | return PyHirschRectangle1_FromHRectangle1(self->Rectangle1.Intersection(Halcon::HRectangle1((((PyHirschRectangle1*)w)->Rectangle1)))); 226 | } 227 | } 228 | PyErr_Clear(); 229 | if (PyArg_ParseTuple(args, "O", &line)) { 230 | if (PyHirschLine2D_Check(line)) { 231 | Halcon::HLine2D clipping(Halcon::HPoint2D(0,0), Halcon::HPoint2D(0,0)); 232 | PyObject *ret = PyTuple_New(2); 233 | PyTuple_SET_ITEM(ret, 0, PyBool_FromLong(self->Rectangle1.Intersection(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)),clipping))); 234 | PyTuple_SET_ITEM(ret, 1, PyHirschLine2D_FromHLine2D(clipping)); 235 | 236 | return ret; 237 | } 238 | } 239 | PyErr_Clear(); 240 | 241 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle1.Intersection()"); 242 | return NULL; 243 | } 244 | catch (Halcon::HException &except) { 245 | PyErr_SetString(PyExc_RuntimeError, except.message); 246 | return NULL; 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /src/hrectangle1_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Overlaps", (PyCFunction)PyHirschRectangle1_Overlaps, METH_VARARGS, "Overlaps(w)\n\n" }, 2 | {"Distance", (PyCFunction)PyHirschRectangle1_Distance, METH_VARARGS, "Distance(point)\n\n" }, 3 | {"Center", (PyCFunction)PyHirschRectangle1_Center, METH_NOARGS, "Center()\n\n" }, 4 | {"UpperLeft", (PyCFunction)PyHirschRectangle1_UpperLeft, METH_NOARGS, "UpperLeft()\n\n" }, 5 | {"Area", (PyCFunction)PyHirschRectangle1_Area, METH_NOARGS, "Area()\n\n" }, 6 | {"CenterDistance", (PyCFunction)PyHirschRectangle1_CenterDistance, METH_VARARGS, "CenterDistance(point)\n\n" }, 7 | {"Includes", (PyCFunction)PyHirschRectangle1_Includes, METH_VARARGS, "Includes(point)\n\n" }, 8 | {"LowerRight", (PyCFunction)PyHirschRectangle1_LowerRight, METH_NOARGS, "LowerRight()\n\n" }, 9 | {"Height", (PyCFunction)PyHirschRectangle1_Height, METH_NOARGS, "Height()\n\n" }, 10 | {"Width", (PyCFunction)PyHirschRectangle1_Width, METH_NOARGS, "Width()\n\n" }, 11 | {"HMax", (PyCFunction)PyHirschRectangle1_HMax, METH_VARARGS, "HMax(w)\n\n" }, 12 | {"IsEmpty", (PyCFunction)PyHirschRectangle1_IsEmpty, METH_NOARGS, "IsEmpty()\n\n" }, 13 | {"Intersection", (PyCFunction)PyHirschRectangle1_Intersection, METH_VARARGS, "Intersection(w)\n\n" }, -------------------------------------------------------------------------------- /src/hrectangle2_autogen_methods_declarations.i: -------------------------------------------------------------------------------- 1 | PyObject * 2 | PyHirschRectangle2_Overlaps(PyHirschRectangle2*self, PyObject *args) 3 | { 4 | PyObject* w; 5 | 6 | try { 7 | if (PyArg_ParseTuple(args, "O", &w)) { 8 | if (PyHirschRectangle2_Check(w)) { 9 | return PyBool_FromLong(self->Rectangle2.Overlaps(Halcon::HRectangle2((((PyHirschRectangle2*)w)->Rectangle2)))); 10 | } 11 | } 12 | PyErr_Clear(); 13 | 14 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle2.Overlaps()"); 15 | return NULL; 16 | } 17 | catch (Halcon::HException &except) { 18 | PyErr_SetString(PyExc_RuntimeError, except.message); 19 | return NULL; 20 | } 21 | } 22 | 23 | PyObject * 24 | PyHirschRectangle2_Distance(PyHirschRectangle2*self, PyObject *args) 25 | { 26 | PyObject* line; 27 | PyObject* point; 28 | 29 | try { 30 | if (PyArg_ParseTuple(args, "O", &point)) { 31 | if (PyHirschPoint2D_Check(point)) { 32 | return PyFloat_FromDouble(self->Rectangle2.Distance(Halcon::HPoint2D((((PyHirschPoint2D*)point)->Point2D)))); 33 | } 34 | } 35 | PyErr_Clear(); 36 | if (PyArg_ParseTuple(args, "O", &line)) { 37 | if (PyHirschLine2D_Check(line)) { 38 | return PyFloat_FromDouble(self->Rectangle2.Distance(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 39 | } 40 | } 41 | PyErr_Clear(); 42 | 43 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle2.Distance()"); 44 | return NULL; 45 | } 46 | catch (Halcon::HException &except) { 47 | PyErr_SetString(PyExc_RuntimeError, except.message); 48 | return NULL; 49 | } 50 | } 51 | 52 | PyObject * 53 | PyHirschRectangle2_Phi(PyHirschRectangle2*self, PyObject *) 54 | { 55 | try { 56 | return PyFloat_FromDouble(self->Rectangle2.Phi()); 57 | } 58 | catch (Halcon::HException &except) { 59 | PyErr_SetString(PyExc_RuntimeError, except.message); 60 | return NULL; 61 | } 62 | } 63 | 64 | PyObject * 65 | PyHirschRectangle2_Center(PyHirschRectangle2*self, PyObject *) 66 | { 67 | try { 68 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle2.Center()); 69 | } 70 | catch (Halcon::HException &except) { 71 | PyErr_SetString(PyExc_RuntimeError, except.message); 72 | return NULL; 73 | } 74 | } 75 | 76 | PyObject * 77 | PyHirschRectangle2_CenterDistance(PyHirschRectangle2*self, PyObject *args) 78 | { 79 | PyObject* line; 80 | PyObject* point; 81 | 82 | try { 83 | if (PyArg_ParseTuple(args, "O", &point)) { 84 | if (PyHirschPoint2D_Check(point)) { 85 | return PyFloat_FromDouble(self->Rectangle2.CenterDistance(Halcon::HPoint2D((((PyHirschPoint2D*)point)->Point2D)))); 86 | } 87 | } 88 | PyErr_Clear(); 89 | if (PyArg_ParseTuple(args, "O", &line)) { 90 | if (PyHirschLine2D_Check(line)) { 91 | return PyFloat_FromDouble(self->Rectangle2.CenterDistance(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 92 | } 93 | } 94 | PyErr_Clear(); 95 | 96 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle2.CenterDistance()"); 97 | return NULL; 98 | } 99 | catch (Halcon::HException &except) { 100 | PyErr_SetString(PyExc_RuntimeError, except.message); 101 | return NULL; 102 | } 103 | } 104 | 105 | PyObject * 106 | PyHirschRectangle2_Includes(PyHirschRectangle2*self, PyObject *args) 107 | { 108 | PyObject* w; 109 | PyObject* line; 110 | PyObject* point; 111 | 112 | try { 113 | if (PyArg_ParseTuple(args, "O", &w)) { 114 | if (PyHirschRectangle2_Check(w)) { 115 | return PyBool_FromLong(self->Rectangle2.Includes(Halcon::HRectangle2((((PyHirschRectangle2*)w)->Rectangle2)))); 116 | } 117 | } 118 | PyErr_Clear(); 119 | if (PyArg_ParseTuple(args, "O", &point)) { 120 | if (PyHirschPoint2D_Check(point)) { 121 | return PyBool_FromLong(self->Rectangle2.Includes(Halcon::HPoint2D((((PyHirschPoint2D*)point)->Point2D)))); 122 | } 123 | } 124 | PyErr_Clear(); 125 | if (PyArg_ParseTuple(args, "O", &line)) { 126 | if (PyHirschLine2D_Check(line)) { 127 | return PyBool_FromLong(self->Rectangle2.Includes(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)))); 128 | } 129 | } 130 | PyErr_Clear(); 131 | 132 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle2.Includes()"); 133 | return NULL; 134 | } 135 | catch (Halcon::HException &except) { 136 | PyErr_SetString(PyExc_RuntimeError, except.message); 137 | return NULL; 138 | } 139 | } 140 | 141 | PyObject * 142 | PyHirschRectangle2_Point1(PyHirschRectangle2*self, PyObject *) 143 | { 144 | try { 145 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle2.Point1()); 146 | } 147 | catch (Halcon::HException &except) { 148 | PyErr_SetString(PyExc_RuntimeError, except.message); 149 | return NULL; 150 | } 151 | } 152 | 153 | PyObject * 154 | PyHirschRectangle2_Point2(PyHirschRectangle2*self, PyObject *) 155 | { 156 | try { 157 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle2.Point2()); 158 | } 159 | catch (Halcon::HException &except) { 160 | PyErr_SetString(PyExc_RuntimeError, except.message); 161 | return NULL; 162 | } 163 | } 164 | 165 | PyObject * 166 | PyHirschRectangle2_Point3(PyHirschRectangle2*self, PyObject *) 167 | { 168 | try { 169 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle2.Point3()); 170 | } 171 | catch (Halcon::HException &except) { 172 | PyErr_SetString(PyExc_RuntimeError, except.message); 173 | return NULL; 174 | } 175 | } 176 | 177 | PyObject * 178 | PyHirschRectangle2_Point4(PyHirschRectangle2*self, PyObject *) 179 | { 180 | try { 181 | return PyHirschPoint2D_FromHPoint2D(self->Rectangle2.Point4()); 182 | } 183 | catch (Halcon::HException &except) { 184 | PyErr_SetString(PyExc_RuntimeError, except.message); 185 | return NULL; 186 | } 187 | } 188 | 189 | PyObject * 190 | PyHirschRectangle2_Ra(PyHirschRectangle2*self, PyObject *) 191 | { 192 | try { 193 | return PyFloat_FromDouble(self->Rectangle2.Ra()); 194 | } 195 | catch (Halcon::HException &except) { 196 | PyErr_SetString(PyExc_RuntimeError, except.message); 197 | return NULL; 198 | } 199 | } 200 | 201 | PyObject * 202 | PyHirschRectangle2_Rb(PyHirschRectangle2*self, PyObject *) 203 | { 204 | try { 205 | return PyFloat_FromDouble(self->Rectangle2.Rb()); 206 | } 207 | catch (Halcon::HException &except) { 208 | PyErr_SetString(PyExc_RuntimeError, except.message); 209 | return NULL; 210 | } 211 | } 212 | 213 | PyObject * 214 | PyHirschRectangle2_IsEmpty(PyHirschRectangle2*self, PyObject *) 215 | { 216 | try { 217 | return PyBool_FromLong(self->Rectangle2.IsEmpty()); 218 | } 219 | catch (Halcon::HException &except) { 220 | PyErr_SetString(PyExc_RuntimeError, except.message); 221 | return NULL; 222 | } 223 | } 224 | 225 | PyObject * 226 | PyHirschRectangle2_Intersection(PyHirschRectangle2*self, PyObject *args) 227 | { 228 | PyObject* line; 229 | 230 | try { 231 | if (PyArg_ParseTuple(args, "O", &line)) { 232 | if (PyHirschLine2D_Check(line)) { 233 | Halcon::HLine2D clipping(Halcon::HPoint2D(0,0), Halcon::HPoint2D(0,0)); 234 | PyObject *ret = PyTuple_New(2); 235 | PyTuple_SET_ITEM(ret, 0, PyBool_FromLong(self->Rectangle2.Intersection(Halcon::HLine2D((((PyHirschLine2D*)line)->Line2D)),clipping))); 236 | PyTuple_SET_ITEM(ret, 1, PyHirschLine2D_FromHLine2D(clipping)); 237 | 238 | return ret; 239 | } 240 | } 241 | PyErr_Clear(); 242 | 243 | PyErr_SetString(PyExc_TypeError, "Illegal parameters in call to HRectangle2.Intersection()"); 244 | return NULL; 245 | } 246 | catch (Halcon::HException &except) { 247 | PyErr_SetString(PyExc_RuntimeError, except.message); 248 | return NULL; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /src/hrectangle2_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Overlaps", (PyCFunction)PyHirschRectangle2_Overlaps, METH_VARARGS, "Overlaps(w)\n\n" }, 2 | {"Distance", (PyCFunction)PyHirschRectangle2_Distance, METH_VARARGS, "Distance(point)\n\n" }, 3 | {"Phi", (PyCFunction)PyHirschRectangle2_Phi, METH_NOARGS, "Phi()\n\n" }, 4 | {"Center", (PyCFunction)PyHirschRectangle2_Center, METH_NOARGS, "Center()\n\n" }, 5 | {"CenterDistance", (PyCFunction)PyHirschRectangle2_CenterDistance, METH_VARARGS, "CenterDistance(point)\n\n" }, 6 | {"Includes", (PyCFunction)PyHirschRectangle2_Includes, METH_VARARGS, "Includes(w)\n\n" }, 7 | {"Point1", (PyCFunction)PyHirschRectangle2_Point1, METH_NOARGS, "Point1()\n\n" }, 8 | {"Point2", (PyCFunction)PyHirschRectangle2_Point2, METH_NOARGS, "Point2()\n\n" }, 9 | {"Point3", (PyCFunction)PyHirschRectangle2_Point3, METH_NOARGS, "Point3()\n\n" }, 10 | {"Point4", (PyCFunction)PyHirschRectangle2_Point4, METH_NOARGS, "Point4()\n\n" }, 11 | {"Ra", (PyCFunction)PyHirschRectangle2_Ra, METH_NOARGS, "Ra()\n\n" }, 12 | {"Rb", (PyCFunction)PyHirschRectangle2_Rb, METH_NOARGS, "Rb()\n\n" }, 13 | {"IsEmpty", (PyCFunction)PyHirschRectangle2_IsEmpty, METH_NOARGS, "IsEmpty()\n\n" }, 14 | {"Intersection", (PyCFunction)PyHirschRectangle2_Intersection, METH_VARARGS, "Intersection(line)\n\n" }, -------------------------------------------------------------------------------- /src/hrootobject_autogen_methods_declarations.i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/src/hrootobject_autogen_methods_declarations.i -------------------------------------------------------------------------------- /src/hrootobject_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | , -------------------------------------------------------------------------------- /src/hspatialobject_autogen_methods_declarations.i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/src/hspatialobject_autogen_methods_declarations.i -------------------------------------------------------------------------------- /src/hspatialobject_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | , -------------------------------------------------------------------------------- /src/htemplate_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"WriteTemplate", (PyCFunction)PyHirschTemplate_WriteTemplate, METH_VARARGS, "WriteTemplate(FileName)\n\nWriting a template to file." }, 2 | {"AdaptTemplate", (PyCFunction)PyHirschTemplate_AdaptTemplate, METH_VARARGS, "AdaptTemplate(Image)\n\nAdapting a template to the size of an image." }, 3 | {"CreateTemplate", (PyCFunction)PyHirschTemplate_CreateTemplate, METH_VARARGS, "CreateTemplate(Template,FirstError,NumLevel,Optimize,GrayValues)\n\nPreparing a pattern for template matching." }, 4 | {"ReadTemplate", (PyCFunction)PyHirschTemplate_ReadTemplate, METH_VARARGS, "ReadTemplate(FileName)\n\nReading a template from file." }, 5 | {"SetOffsetTemplate", (PyCFunction)PyHirschTemplate_SetOffsetTemplate, METH_VARARGS, "SetOffsetTemplate(GrayOffset)\n\nGray value offset for template." }, 6 | {"SetHandle", (PyCFunction)PyHirschTemplate_SetHandle, METH_VARARGS, "SetHandle(ID)\n\n" }, 7 | {"BestMatchMg", (PyCFunction)PyHirschTemplate_BestMatchMg, METH_VARARGS, "BestMatchMg(Image,MaxError,SubPixel,NumLevels,WhichLevels)\n\nSearching the best grayvalue matches in a pyramid." }, 8 | {"FastMatchMg", (PyCFunction)PyHirschTemplate_FastMatchMg, METH_VARARGS, "FastMatchMg(Image,MaxError,NumLevel)\n\nSearching all good grayvalue matches in a pyramid." }, 9 | {"BestMatch", (PyCFunction)PyHirschTemplate_BestMatch, METH_VARARGS, "BestMatch(Image,MaxError,SubPixel)\n\nSearching the best matching of a template and an image." }, 10 | {"SetReferenceTemplate", (PyCFunction)PyHirschTemplate_SetReferenceTemplate, METH_VARARGS, "SetReferenceTemplate(Row,Column)\n\nDefine reference position for a matching template." }, 11 | {"BestMatchRot", (PyCFunction)PyHirschTemplate_BestMatchRot, METH_VARARGS, "BestMatchRot(Image,AngleStart,AngleExtend,MaxError,SubPixel)\n\nSearching the best matching of a template and an image with rotation." }, 12 | {"CreateTemplateRot", (PyCFunction)PyHirschTemplate_CreateTemplateRot, METH_VARARGS, "CreateTemplateRot(Template,NumLevel,AngleStart,AngleExtend,AngleStep,Optimize,GrayValues)\n\nPreparing a pattern for template matching with rotation." }, 13 | {"BestMatchRotMg", (PyCFunction)PyHirschTemplate_BestMatchRotMg, METH_VARARGS, "BestMatchRotMg(Image,AngleStart,AngleExtend,MaxError,SubPixel,NumLevels)\n\nSearching the best matching of a template and a pyramid with rotation." }, 14 | {"FastMatch", (PyCFunction)PyHirschTemplate_FastMatch, METH_VARARGS, "FastMatch(Image,MaxError)\n\nSearching all good matches of a template and an image." }, 15 | {"BestMatchPreMg", (PyCFunction)PyHirschTemplate_BestMatchPreMg, METH_VARARGS, "BestMatchPreMg(ImagePyramid,MaxError,SubPixel,NumLevels,WhichLevels)\n\nSearching the best grayvalue matches in a pre generated pyramid." }, 16 | {"GetHandle", (PyCFunction)PyHirschTemplate_GetHandle, METH_NOARGS, "GetHandle()\n\n" }, -------------------------------------------------------------------------------- /src/htuple_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"Strchr", (PyCFunction)PyHirschTuple_Strchr, METH_VARARGS, "Strchr(pattern)\n\n" }, 2 | {"Asin", (PyCFunction)PyHirschTuple_Asin, METH_NOARGS, "Asin()\n\n" }, 3 | {"Chrt", (PyCFunction)PyHirschTuple_Chrt, METH_NOARGS, "Chrt()\n\n" }, 4 | {"Xor", (PyCFunction)PyHirschTuple_Xor, METH_VARARGS, "Xor(pattern)\n\n" }, 5 | {"Log", (PyCFunction)PyHirschTuple_Log, METH_NOARGS, "Log()\n\n" }, 6 | {"Min", (PyCFunction)PyHirschTuple_Min, METH_NOARGS, "Min()\n\n" }, 7 | {"Sum", (PyCFunction)PyHirschTuple_Sum, METH_NOARGS, "Sum()\n\n" }, 8 | {"Sqrt", (PyCFunction)PyHirschTuple_Sqrt, METH_NOARGS, "Sqrt()\n\n" }, 9 | {"Strrstr", (PyCFunction)PyHirschTuple_Strrstr, METH_VARARGS, "Strrstr(pattern)\n\n" }, 10 | {"Chr", (PyCFunction)PyHirschTuple_Chr, METH_NOARGS, "Chr()\n\n" }, 11 | {"Inverse", (PyCFunction)PyHirschTuple_Inverse, METH_NOARGS, "Inverse()\n\n" }, 12 | {"Split", (PyCFunction)PyHirschTuple_Split, METH_VARARGS, "Split(pattern)\n\n" }, 13 | {"Strrchr", (PyCFunction)PyHirschTuple_Strrchr, METH_VARARGS, "Strrchr(pattern)\n\n" }, 14 | {"Ceil", (PyCFunction)PyHirschTuple_Ceil, METH_NOARGS, "Ceil()\n\n" }, 15 | {"Ords", (PyCFunction)PyHirschTuple_Ords, METH_NOARGS, "Ords()\n\n" }, 16 | {"Sin", (PyCFunction)PyHirschTuple_Sin, METH_NOARGS, "Sin()\n\n" }, 17 | {"RegexpTest", (PyCFunction)PyHirschTuple_RegexpTest, METH_VARARGS, "RegexpTest(expression)\n\n" }, 18 | {"Deviation", (PyCFunction)PyHirschTuple_Deviation, METH_NOARGS, "Deviation()\n\n" }, 19 | {"RegexpMatch", (PyCFunction)PyHirschTuple_RegexpMatch, METH_VARARGS, "RegexpMatch(expression)\n\n" }, 20 | {"Atan", (PyCFunction)PyHirschTuple_Atan, METH_NOARGS, "Atan()\n\n" }, 21 | {"Max", (PyCFunction)PyHirschTuple_Max, METH_NOARGS, "Max()\n\n" }, 22 | {"Cumul", (PyCFunction)PyHirschTuple_Cumul, METH_NOARGS, "Cumul()\n\n" }, 23 | {"Floor", (PyCFunction)PyHirschTuple_Floor, METH_NOARGS, "Floor()\n\n" }, 24 | {"Getenv", (PyCFunction)PyHirschTuple_Getenv, METH_NOARGS, "Getenv()\n\n" }, 25 | {"Log10", (PyCFunction)PyHirschTuple_Log10, METH_NOARGS, "Log10()\n\n" }, 26 | {"Sort", (PyCFunction)PyHirschTuple_Sort, METH_NOARGS, "Sort()\n\n" }, 27 | {"Sinh", (PyCFunction)PyHirschTuple_Sinh, METH_NOARGS, "Sinh()\n\n" }, 28 | {"Fmod", (PyCFunction)PyHirschTuple_Fmod, METH_VARARGS, "Fmod(op)\n\n" }, 29 | {"Ord", (PyCFunction)PyHirschTuple_Ord, METH_NOARGS, "Ord()\n\n" }, 30 | {"Mean", (PyCFunction)PyHirschTuple_Mean, METH_NOARGS, "Mean()\n\n" }, 31 | {"Concat", (PyCFunction)PyHirschTuple_Concat, METH_VARARGS, "Concat(t)\n\n" }, 32 | {"Reset", (PyCFunction)PyHirschTuple_Reset, METH_NOARGS, "Reset()\n\n" }, 33 | {"Real", (PyCFunction)PyHirschTuple_Real, METH_NOARGS, "Real()\n\n" }, 34 | {"Cos", (PyCFunction)PyHirschTuple_Cos, METH_NOARGS, "Cos()\n\n" }, 35 | {"Strstr", (PyCFunction)PyHirschTuple_Strstr, METH_VARARGS, "Strstr(pattern)\n\n" }, 36 | {"Tanh", (PyCFunction)PyHirschTuple_Tanh, METH_NOARGS, "Tanh()\n\n" }, 37 | {"Max2", (PyCFunction)PyHirschTuple_Max2, METH_VARARGS, "Max2(op)\n\n" }, 38 | {"StrBitSelect", (PyCFunction)PyHirschTuple_StrBitSelect, METH_VARARGS, "StrBitSelect(index)\n\n" }, 39 | {"Median", (PyCFunction)PyHirschTuple_Median, METH_NOARGS, "Median()\n\n" }, 40 | {"Remove", (PyCFunction)PyHirschTuple_Remove, METH_VARARGS, "Remove(index)\n\n" }, 41 | {"Atan2", (PyCFunction)PyHirschTuple_Atan2, METH_VARARGS, "Atan2(op)\n\n" }, 42 | {"Continue", (PyCFunction)PyHirschTuple_Continue, METH_VARARGS, "Continue(FinalValue,Increment)\n\n" }, 43 | {"RegexpReplace", (PyCFunction)PyHirschTuple_RegexpReplace, METH_VARARGS, "RegexpReplace(expression,replace)\n\n" }, 44 | {"Exp", (PyCFunction)PyHirschTuple_Exp, METH_NOARGS, "Exp()\n\n" }, 45 | {"Acos", (PyCFunction)PyHirschTuple_Acos, METH_NOARGS, "Acos()\n\n" }, 46 | {"Round", (PyCFunction)PyHirschTuple_Round, METH_NOARGS, "Round()\n\n" }, 47 | {"Deg", (PyCFunction)PyHirschTuple_Deg, METH_NOARGS, "Deg()\n\n" }, 48 | {"Subset", (PyCFunction)PyHirschTuple_Subset, METH_VARARGS, "Subset(index)\n\n" }, 49 | {"Rand", (PyCFunction)PyHirschTuple_Rand, METH_NOARGS, "Rand()\n\n" }, 50 | {"Rad", (PyCFunction)PyHirschTuple_Rad, METH_NOARGS, "Rad()\n\n" }, 51 | {"Uniq", (PyCFunction)PyHirschTuple_Uniq, METH_NOARGS, "Uniq()\n\n" }, 52 | {"State", (PyCFunction)PyHirschTuple_State, METH_NOARGS, "State()\n\n" }, 53 | {"Int", (PyCFunction)PyHirschTuple_Int, METH_NOARGS, "Int()\n\n" }, 54 | {"Pow", (PyCFunction)PyHirschTuple_Pow, METH_VARARGS, "Pow(op)\n\n" }, 55 | {"SortIndex", (PyCFunction)PyHirschTuple_SortIndex, METH_NOARGS, "SortIndex()\n\n" }, 56 | {"RegexpSelect", (PyCFunction)PyHirschTuple_RegexpSelect, METH_VARARGS, "RegexpSelect(expression)\n\n" }, 57 | {"Number", (PyCFunction)PyHirschTuple_Number, METH_NOARGS, "Number()\n\n" }, 58 | {"Cosh", (PyCFunction)PyHirschTuple_Cosh, METH_NOARGS, "Cosh()\n\n" }, 59 | {"Ldexp", (PyCFunction)PyHirschTuple_Ldexp, METH_VARARGS, "Ldexp(op)\n\n" }, 60 | {"SelectRank", (PyCFunction)PyHirschTuple_SelectRank, METH_VARARGS, "SelectRank(index)\n\n" }, 61 | {"Abs", (PyCFunction)PyHirschTuple_Abs, METH_NOARGS, "Abs()\n\n" }, 62 | {"Append", (PyCFunction)PyHirschTuple_Append, METH_VARARGS, "Append(t)\n\n" }, 63 | {"Sgn", (PyCFunction)PyHirschTuple_Sgn, METH_NOARGS, "Sgn()\n\n" }, 64 | {"ToString", (PyCFunction)PyHirschTuple_ToString, METH_VARARGS, "ToString(pattern)\n\n" }, 65 | {"Tan", (PyCFunction)PyHirschTuple_Tan, METH_NOARGS, "Tan()\n\n" }, 66 | {"IsNumber", (PyCFunction)PyHirschTuple_IsNumber, METH_NOARGS, "IsNumber()\n\n" }, 67 | {"Strlen", (PyCFunction)PyHirschTuple_Strlen, METH_NOARGS, "Strlen()\n\n" }, 68 | {"Find", (PyCFunction)PyHirschTuple_Find, METH_VARARGS, "Find(op)\n\n" }, 69 | {"Substring", (PyCFunction)PyHirschTuple_Substring, METH_VARARGS, "Substring(index1,index2)\n\n" }, 70 | {"Min2", (PyCFunction)PyHirschTuple_Min2, METH_VARARGS, "Min2(op)\n\n" }, -------------------------------------------------------------------------------- /src/hxld_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"SmallestCircleXld", (PyCFunction)PyHirschXLD_SmallestCircleXld, METH_NOARGS, "SmallestCircleXld()\n\nSmallest enclosing circle of contours or polygons." }, 2 | {"EccentricityXld", (PyCFunction)PyHirschXLD_EccentricityXld, METH_NOARGS, "EccentricityXld()\n\nShape features derived from the ellipse parameters of contours or polygons." }, 3 | {"AreaCenterXld", (PyCFunction)PyHirschXLD_AreaCenterXld, METH_NOARGS, "AreaCenterXld()\n\nArea and center of gravity (centroid) of contours and polygons." }, 4 | {"TestXldPoint", (PyCFunction)PyHirschXLD_TestXldPoint, METH_VARARGS, "TestXldPoint(Row,Column)\n\nTest whether one or more contours or polygons enclose the given point(s)." }, 5 | {"CompactnessXld", (PyCFunction)PyHirschXLD_CompactnessXld, METH_NOARGS, "CompactnessXld()\n\nShape factor for the compactness of contours or polygons." }, 6 | {"OrientationXld", (PyCFunction)PyHirschXLD_OrientationXld, METH_NOARGS, "OrientationXld()\n\nOrientation of contours or polygons." }, 7 | {"EccentricityPointsXld", (PyCFunction)PyHirschXLD_EccentricityPointsXld, METH_NOARGS, "EccentricityPointsXld()\n\nAnisometry of contours or polygons treated as point clouds." }, 8 | {"OrientationPointsXld", (PyCFunction)PyHirschXLD_OrientationPointsXld, METH_NOARGS, "OrientationPointsXld()\n\nOrientation of contours or polygons treated as point clouds." }, 9 | {"Shared", (PyCFunction)PyHirschXLD_Shared, METH_NOARGS, "Shared()\n\n" }, 10 | {"SelectXldPoint", (PyCFunction)PyHirschXLD_SelectXldPoint, METH_VARARGS, "SelectXldPoint(Row,Column)\n\nChoose all contours or polygons containing a given point." }, 11 | {"GetParallelsXld", (PyCFunction)PyHirschXLD_GetParallelsXld, METH_NOARGS, "GetParallelsXld()\n\nReturn an XLD parallel's data (as lines)." }, 12 | {"MomentsAnyXld", (PyCFunction)PyHirschXLD_MomentsAnyXld, METH_VARARGS, "MomentsAnyXld(Mode,PointOrder,Area,CenterRow,CenterCol,P,Q)\n\nArbitrary geometric moments of contours or polygons." }, 13 | {"PaintXld", (PyCFunction)PyHirschXLD_PaintXld, METH_VARARGS, "PaintXld(Image,Grayval)\n\nPaint XLD objects into an image." }, 14 | {"SmallestRectangle2Xld", (PyCFunction)PyHirschXLD_SmallestRectangle2Xld, METH_NOARGS, "SmallestRectangle2Xld()\n\nSmallest enclosing rectangle with arbitrary orientation of contours or \npolygons." }, 15 | {"MomentsAnyPointsXld", (PyCFunction)PyHirschXLD_MomentsAnyPointsXld, METH_VARARGS, "MomentsAnyPointsXld(Mode,Area,CenterRow,CenterCol,P,Q)\n\nArbitrary geometric moments of contours or polygons treated as point\nclouds." }, 16 | {"TestSelfIntersectionXld", (PyCFunction)PyHirschXLD_TestSelfIntersectionXld, METH_VARARGS, "TestSelfIntersectionXld(CloseXLD)\n\nTest XLD contours or polygons for self intersection." }, 17 | {"EllipticAxisXld", (PyCFunction)PyHirschXLD_EllipticAxisXld, METH_NOARGS, "EllipticAxisXld()\n\nParameters of the equivalent ellipse of contours or polygons." }, 18 | {"GetCirclePose", (PyCFunction)PyHirschXLD_GetCirclePose, METH_VARARGS, "GetCirclePose(CamParam,Radius,OutputType)\n\nDetermine the 3D pose of a circle from its perspective 2D projection." }, 19 | {"MomentsXld", (PyCFunction)PyHirschXLD_MomentsXld, METH_NOARGS, "MomentsXld()\n\nGeometric moments M20, M02, and \nM11 of contours or polygons." }, 20 | {"AreaCenterPointsXld", (PyCFunction)PyHirschXLD_AreaCenterPointsXld, METH_NOARGS, "AreaCenterPointsXld()\n\nArea and center of gravity (centroid) of contours and polygons\ntreated as point clouds." }, 21 | {"DiameterXld", (PyCFunction)PyHirschXLD_DiameterXld, METH_NOARGS, "DiameterXld()\n\nMaximum distance between two contour or polygon points." }, 22 | {"InstClassName", (PyCFunction)PyHirschXLD_InstClassName, METH_NOARGS, "InstClassName()\n\n" }, 23 | {"CircularityXld", (PyCFunction)PyHirschXLD_CircularityXld, METH_NOARGS, "CircularityXld()\n\nShape factor for the circularity (similarity to a circle) of contours or \npolygons." }, 24 | {"ShapeTransXld", (PyCFunction)PyHirschXLD_ShapeTransXld, METH_VARARGS, "ShapeTransXld(Type)\n\nTransform the shape of contours or polygons." }, 25 | {"HClassName", (PyCFunction)PyHirschXLD_HClassName, METH_NOARGS, "HClassName()\n\nTools" }, 26 | {"LengthXld", (PyCFunction)PyHirschXLD_LengthXld, METH_NOARGS, "LengthXld()\n\nLength of contours or polygons." }, 27 | {"MomentsPointsXld", (PyCFunction)PyHirschXLD_MomentsPointsXld, METH_NOARGS, "MomentsPointsXld()\n\nGeometric moments M20, M02, and M11\nof contours or polygons treated as point clouds." }, 28 | {"EllipticAxisPointsXld", (PyCFunction)PyHirschXLD_EllipticAxisPointsXld, METH_NOARGS, "EllipticAxisPointsXld()\n\nParameters of the equivalent ellipse of contours or polygons treated as \npoint clouds." }, 29 | {"GetRectanglePose", (PyCFunction)PyHirschXLD_GetRectanglePose, METH_VARARGS, "GetRectanglePose(CamParam,Width,Height,WeightingMode,ClippingFactor)\n\nDetermine the 3D pose of a rectangle from its perspective 2D\nprojection" }, 30 | {"ConvexityXld", (PyCFunction)PyHirschXLD_ConvexityXld, METH_NOARGS, "ConvexityXld()\n\nShape factor for the convexity of contours or polygons." }, 31 | {"SmallestRectangle1Xld", (PyCFunction)PyHirschXLD_SmallestRectangle1Xld, METH_NOARGS, "SmallestRectangle1Xld()\n\nEnclosing rectangle parallel to the coordinate axes of contours or polygons." }, -------------------------------------------------------------------------------- /src/hxldarray_autogen_methods_list.i: -------------------------------------------------------------------------------- 1 | {"SmallestCircleXld", (PyCFunction)PyHirschXLDArray_SmallestCircleXld, METH_NOARGS, "SmallestCircleXld()\n\nSmallest enclosing circle of contours or polygons." }, 2 | {"CopyHXLDArray", (PyCFunction)PyHirschXLDArray_CopyHXLDArray, METH_VARARGS, "CopyHXLDArray(in)\n\n" }, 3 | {"EccentricityXld", (PyCFunction)PyHirschXLDArray_EccentricityXld, METH_NOARGS, "EccentricityXld()\n\nShape features derived from the ellipse parameters of contours or polygons." }, 4 | {"AreaCenterXld", (PyCFunction)PyHirschXLDArray_AreaCenterXld, METH_NOARGS, "AreaCenterXld()\n\nArea and center of gravity (centroid) of contours and polygons." }, 5 | {"TestXldPoint", (PyCFunction)PyHirschXLDArray_TestXldPoint, METH_VARARGS, "TestXldPoint(Row,Column)\n\nTest whether one or more contours or polygons enclose the given point(s)." }, 6 | {"CompactnessXld", (PyCFunction)PyHirschXLDArray_CompactnessXld, METH_NOARGS, "CompactnessXld()\n\nShape factor for the compactness of contours or polygons." }, 7 | {"OrientationXld", (PyCFunction)PyHirschXLDArray_OrientationXld, METH_NOARGS, "OrientationXld()\n\nOrientation of contours or polygons." }, 8 | {"EccentricityPointsXld", (PyCFunction)PyHirschXLDArray_EccentricityPointsXld, METH_NOARGS, "EccentricityPointsXld()\n\nAnisometry of contours or polygons treated as point clouds." }, 9 | {"OrientationPointsXld", (PyCFunction)PyHirschXLDArray_OrientationPointsXld, METH_NOARGS, "OrientationPointsXld()\n\nOrientation of contours or polygons treated as point clouds." }, 10 | {"SelectXldPoint", (PyCFunction)PyHirschXLDArray_SelectXldPoint, METH_VARARGS, "SelectXldPoint(Row,Column)\n\nChoose all contours or polygons containing a given point." }, 11 | {"MomentsAnyXld", (PyCFunction)PyHirschXLDArray_MomentsAnyXld, METH_VARARGS, "MomentsAnyXld(Mode,PointOrder,Area,CenterRow,CenterCol,P,Q)\n\nArbitrary geometric moments of contours or polygons." }, 12 | {"PaintXld", (PyCFunction)PyHirschXLDArray_PaintXld, METH_VARARGS, "PaintXld(Image,Grayval)\n\nPaint XLD objects into an image." }, 13 | {"SmallestRectangle2Xld", (PyCFunction)PyHirschXLDArray_SmallestRectangle2Xld, METH_NOARGS, "SmallestRectangle2Xld()\n\nSmallest enclosing rectangle with arbitrary orientation of contours or \npolygons." }, 14 | {"SelectShapeXld", (PyCFunction)PyHirschXLDArray_SelectShapeXld, METH_VARARGS, "SelectShapeXld(Features,Operation,Min,Max)\n\nSelect contours or polygons using shape features." }, 15 | {"MomentsAnyPointsXld", (PyCFunction)PyHirschXLDArray_MomentsAnyPointsXld, METH_VARARGS, "MomentsAnyPointsXld(Mode,Area,CenterRow,CenterCol,P,Q)\n\nArbitrary geometric moments of contours or polygons treated as point\nclouds." }, 16 | {"TestSelfIntersectionXld", (PyCFunction)PyHirschXLDArray_TestSelfIntersectionXld, METH_VARARGS, "TestSelfIntersectionXld(CloseXLD)\n\nTest XLD contours or polygons for self intersection." }, 17 | {"Elem", (PyCFunction)PyHirschXLDArray_Elem, METH_VARARGS, "Elem(index)\n\nAccessing array elements without index checking -> fast AND risky" }, 18 | {"EllipticAxisXld", (PyCFunction)PyHirschXLDArray_EllipticAxisXld, METH_NOARGS, "EllipticAxisXld()\n\nParameters of the equivalent ellipse of contours or polygons." }, 19 | {"GetCirclePose", (PyCFunction)PyHirschXLDArray_GetCirclePose, METH_VARARGS, "GetCirclePose(CamParam,Radius,OutputType)\n\nDetermine the 3D pose of a circle from its perspective 2D projection." }, 20 | {"MomentsXld", (PyCFunction)PyHirschXLDArray_MomentsXld, METH_NOARGS, "MomentsXld()\n\nGeometric moments M20, M02, and \nM11 of contours or polygons." }, 21 | {"InstClassName", (PyCFunction)PyHirschXLDArray_InstClassName, METH_NOARGS, "InstClassName()\n\n" }, 22 | {"DiameterXld", (PyCFunction)PyHirschXLDArray_DiameterXld, METH_NOARGS, "DiameterXld()\n\nMaximum distance between two contour or polygon points." }, 23 | {"AreaCenterPointsXld", (PyCFunction)PyHirschXLDArray_AreaCenterPointsXld, METH_NOARGS, "AreaCenterPointsXld()\n\nArea and center of gravity (centroid) of contours and polygons\ntreated as point clouds." }, 24 | {"CircularityXld", (PyCFunction)PyHirschXLDArray_CircularityXld, METH_NOARGS, "CircularityXld()\n\nShape factor for the circularity (similarity to a circle) of contours or \npolygons." }, 25 | {"ShapeTransXld", (PyCFunction)PyHirschXLDArray_ShapeTransXld, METH_VARARGS, "ShapeTransXld(Type)\n\nTransform the shape of contours or polygons." }, 26 | {"HClassName", (PyCFunction)PyHirschXLDArray_HClassName, METH_NOARGS, "HClassName()\n\nTools" }, 27 | {"LengthXld", (PyCFunction)PyHirschXLDArray_LengthXld, METH_NOARGS, "LengthXld()\n\nLength of contours or polygons." }, 28 | {"MomentsPointsXld", (PyCFunction)PyHirschXLDArray_MomentsPointsXld, METH_NOARGS, "MomentsPointsXld()\n\nGeometric moments M20, M02, and M11\nof contours or polygons treated as point clouds." }, 29 | {"EllipticAxisPointsXld", (PyCFunction)PyHirschXLDArray_EllipticAxisPointsXld, METH_NOARGS, "EllipticAxisPointsXld()\n\nParameters of the equivalent ellipse of contours or polygons treated as \npoint clouds." }, 30 | {"DispXld", (PyCFunction)PyHirschXLDArray_DispXld, METH_VARARGS, "DispXld(WindowHandle)\n\nDisplay an XLD object." }, 31 | {"GetRectanglePose", (PyCFunction)PyHirschXLDArray_GetRectanglePose, METH_VARARGS, "GetRectanglePose(CamParam,Width,Height,WeightingMode,ClippingFactor)\n\nDetermine the 3D pose of a rectangle from its perspective 2D\nprojection" }, 32 | {"ConvexityXld", (PyCFunction)PyHirschXLDArray_ConvexityXld, METH_NOARGS, "ConvexityXld()\n\nShape factor for the convexity of contours or polygons." }, 33 | {"DeleteArray", (PyCFunction)PyHirschXLDArray_DeleteArray, METH_NOARGS, "DeleteArray()\n\n" }, 34 | {"SmallestRectangle1Xld", (PyCFunction)PyHirschXLDArray_SmallestRectangle1Xld, METH_NOARGS, "SmallestRectangle1Xld()\n\nEnclosing rectangle parallel to the coordinate axes of contours or polygons." }, 35 | {"Append", (PyCFunction)PyHirschXLDArray_Append, METH_VARARGS, "Append(xld)\n\n" }, -------------------------------------------------------------------------------- /src/pyhaffinetrans2d.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HAffineTrans2D 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschAffineTrans2D_dealloc(PyHirschAffineTrans2D* self) 7 | { 8 | // Explicit call to destructor. 9 | self->AffineTrans2D.~HAffineTrans2D(); 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschAffineTrans2D_init(PyHirschAffineTrans2D */*self*/, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | // TBD - Use PyArg_ParseTupleAndKeywords() to do special initialziation 17 | return 0; 18 | } 19 | 20 | #include "haffinetrans2d_autogen_methods_declarations.i" 21 | 22 | static PyMethodDef PyHirschAffineTrans2D_methods[] = { 23 | #include "haffinetrans2d_autogen_methods_list.i" 24 | {NULL} /* Sentinel */ 25 | }; 26 | 27 | static PyObject * 28 | PyHirschAffineTrans2D_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 29 | { 30 | PyHirschAffineTrans2D *self; 31 | 32 | self = (PyHirschAffineTrans2D *)type->tp_alloc(type, 0); 33 | // Explicit call to constructor placement new 34 | new(&self->AffineTrans2D) Halcon::HAffineTrans2D(); 35 | 36 | return (PyObject *)self; 37 | } 38 | 39 | PyObject *PyHirschAffineTrans2D_FromHAffineTrans2D(Halcon::HAffineTrans2D AffineTrans2D) 40 | { 41 | PyHirschAffineTrans2D *self = (PyHirschAffineTrans2D*)PyHirschAffineTrans2D_new(&PyHirschAffineTrans2DType,NULL,NULL); 42 | self->AffineTrans2D = AffineTrans2D; 43 | return (PyObject*)self; 44 | } 45 | 46 | PyTypeObject PyHirschAffineTrans2DType = { 47 | PyVarObject_HEAD_INIT(NULL, 0) 48 | "Hirsch.PyHirschAffineTrans2D", /*tp_name*/ 49 | sizeof(PyHirschAffineTrans2D), /*tp_basicsize*/ 50 | 0, /*tp_itemsize*/ 51 | (destructor)PyHirschAffineTrans2D_dealloc, /*tp_dealloc*/ 52 | 0, /*tp_print*/ 53 | 0, /*tp_getattr*/ 54 | 0, /*tp_setattr*/ 55 | 0, /*tp_compare*/ 56 | 0, /*tp_repr*/ 57 | 0, /*tp_as_number*/ 58 | 0, /*tp_as_sequence*/ 59 | 0, /*tp_as_mapping*/ 60 | 0, /*tp_hash */ 61 | 0, /*tp_call*/ 62 | 0, /*tp_str*/ 63 | 0, /*tp_getattro*/ 64 | 0, /*tp_setattro*/ 65 | 0, /*tp_as_buffer*/ 66 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 67 | "PyHirschAffineTrans2D", /* tp_doc */ 68 | 0, /* tp_traverse */ 69 | 0, /* tp_clear */ 70 | 0, /* tp_richcompare */ 71 | 0, /* tp_weaklistoffset */ 72 | 0, /* tp_iter */ 73 | 0, /* tp_iternext */ 74 | PyHirschAffineTrans2D_methods, /* tp_methods */ 75 | 0, /* tp_members */ 76 | 0, /* tp_getset */ 77 | 0, /* tp_base */ 78 | 0, /* tp_dict */ 79 | 0, /* tp_descr_get */ 80 | 0, /* tp_descr_set */ 81 | 0, /* tp_dictoffset */ 82 | (initproc)PyHirschAffineTrans2D_init, /* tp_init */ 83 | 0, /* tp_alloc */ 84 | PyHirschAffineTrans2D_new, /* tp_new */ 85 | }; 86 | 87 | 88 | void PyHirschAffineTrans2DAddToModule(PyObject *m) 89 | { 90 | Py_INCREF(&PyHirschAffineTrans2DType); 91 | if (PyType_Ready(&PyHirschAffineTrans2DType) < 0) 92 | return; 93 | PyModule_AddObject(m, "HAffineTrans2D", (PyObject *)&PyHirschAffineTrans2DType); 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/pyhaffinetrans2d.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HAffineTrans2D 2 | #ifndef PYHAFFINETRANS2D_H 3 | #define HAFFINETRANS2D_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschAffineTrans2D_FromHAffineTrans2D(Halcon::HAffineTrans2D AffineTrans2D); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HAffineTrans2D AffineTrans2D; 13 | } PyHirschAffineTrans2D; 14 | 15 | #define PyHirschAffineTrans2D_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschAffineTrans2DType) 17 | 18 | void PyHirschAffineTrans2DAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschAffineTrans2DType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhbarcode.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HBarCode 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschBarCode_dealloc(PyHirschBarCode* self) 7 | { 8 | if(self->BarCode) 9 | delete self->BarCode; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschBarCode_init(PyHirschBarCode *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | self->BarCode = new Halcon::HBarCode(); 17 | 18 | return 0; 19 | } 20 | 21 | #include "hbarcode_autogen_methods_declarations.i" 22 | 23 | static PyMethodDef PyHirschBarCode_methods[] = { 24 | #include "hbarcode_autogen_methods_list.i" 25 | {NULL} /* Sentinel */ 26 | }; 27 | 28 | PyObject *PyHirschBarCode_FromHBarCode(Halcon::HBarCode BarCode) 29 | { 30 | PyHirschBarCode *v = (PyHirschBarCode*)PyObject_New(PyHirschBarCode, &PyHirschBarCodeType); 31 | v->BarCode = new Halcon::HBarCode(BarCode); 32 | return (PyObject*)v; 33 | } 34 | 35 | PyTypeObject PyHirschBarCodeType = { 36 | PyVarObject_HEAD_INIT(NULL, 0) 37 | "Hirsch.HBarCode", /*tp_name*/ 38 | sizeof(PyHirschBarCode), /*tp_basicsize*/ 39 | 0, /*tp_itemsize*/ 40 | (destructor)PyHirschBarCode_dealloc, /*tp_dealloc*/ 41 | 0, /*tp_print*/ 42 | 0, /*tp_getattr*/ 43 | 0, /*tp_setattr*/ 44 | 0, /*tp_compare*/ 45 | 0, /*tp_repr*/ 46 | 0, /*tp_as_number*/ 47 | 0, /*tp_as_sequence*/ 48 | 0, /*tp_as_mapping*/ 49 | 0, /*tp_hash */ 50 | 0, /*tp_call*/ 51 | 0, /*tp_str*/ 52 | 0, /*tp_getattro*/ 53 | 0, /*tp_setattro*/ 54 | 0, /*tp_as_buffer*/ 55 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 | "PyHirschBarCode", /* tp_doc */ 57 | 0, /* tp_traverse */ 58 | 0, /* tp_clear */ 59 | 0, /* tp_richcompare */ 60 | 0, /* tp_weaklistoffset */ 61 | 0, /* tp_iter */ 62 | 0, /* tp_iternext */ 63 | PyHirschBarCode_methods, /* tp_methods */ 64 | 0, /* tp_members */ 65 | 0, /* tp_getset */ 66 | 0, /* tp_base */ 67 | 0, /* tp_dict */ 68 | 0, /* tp_descr_get */ 69 | 0, /* tp_descr_set */ 70 | 0, /* tp_dictoffset */ 71 | (initproc)PyHirschBarCode_init, /* tp_init */ 72 | 0, /* tp_alloc */ 73 | PyType_GenericNew, /* tp_new */ 74 | }; 75 | 76 | 77 | void PyHirschBarCodeAddToModule(PyObject *m) 78 | { 79 | Py_INCREF(&PyHirschBarCodeType); 80 | if (PyType_Ready(&PyHirschBarCodeType) < 0) 81 | return; 82 | PyModule_AddObject(m, "HBarCode", (PyObject *)&PyHirschBarCodeType); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/pyhbarcode.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HBarCode 2 | #ifndef PYHBARCODE_H 3 | #define HBARCODE_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschBarCode_FromHBarCode(Halcon::HBarCode BarCode); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HBarCode *BarCode; 13 | } PyHirschBarCode; 14 | 15 | #define PyHirschBarCode_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschBarCodeType) 17 | 18 | void PyHirschBarCodeAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschBarCodeType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhcircle.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HCircle 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschCircle_dealloc(PyHirschCircle* self) 7 | { 8 | self->Circle.~HCircle(); 9 | PyObject_Del(self); 10 | } 11 | 12 | static int 13 | PyHirschCircle_init(PyHirschCircle *self, PyObject *args, PyObject */*kwds*/) 14 | { 15 | double centerX=0,centerY=0,radius=0; 16 | 17 | if (PyArg_ParseTuple(args,"|(dd)d",¢erX,¢erY,&radius)) 18 | self->Circle = Halcon::HCircle(Halcon::HPoint2D(centerX,centerY), 19 | radius); 20 | return 0; 21 | } 22 | 23 | #include "hcircle_autogen_methods_declarations.i" 24 | 25 | static PyMethodDef PyHirschCircle_methods[] = { 26 | #include "hcircle_autogen_methods_list.i" 27 | {NULL} /* Sentinel */ 28 | }; 29 | 30 | static PyObject * 31 | PyHirschCircle_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 32 | { 33 | PyHirschCircle *self; 34 | 35 | self = (PyHirschCircle *)type->tp_alloc(type, 0); 36 | // Explicit call to constructor placement new 37 | new(&self->Circle) Halcon::HCircle(); 38 | 39 | return (PyObject *)self; 40 | } 41 | 42 | PyObject *PyHirschCircle_FromHCircle(Halcon::HCircle Circle) 43 | { 44 | PyHirschCircle *self = (PyHirschCircle*)PyHirschCircle_new(&PyHirschCircleType, NULL, NULL); 45 | self->Circle = Halcon::HCircle(Circle); 46 | return (PyObject*)self; 47 | } 48 | 49 | static PyObject * 50 | PyHirschCircle_str(PyObject *ob) 51 | { 52 | PyHirschCircle *self = (PyHirschCircle *)ob; 53 | Halcon::HPoint2D Center = self->Circle.Center(); 54 | double r = self->Circle.Radius(); 55 | PyObject *Tuple = Py_BuildValue("Od", 56 | PyHirschPoint2D_FromHPoint2D(Center), 57 | r); 58 | PyObject *Ret = PyObject_Str(Tuple); 59 | Py_DECREF(Tuple); 60 | 61 | return Ret; 62 | } 63 | 64 | PyTypeObject PyHirschCircleType = { 65 | PyVarObject_HEAD_INIT(NULL, 0) 66 | "Hirsch.HCircle", /*tp_name*/ 67 | sizeof(PyHirschCircle), /*tp_basicsize*/ 68 | 0, /*tp_itemsize*/ 69 | (destructor)PyHirschCircle_dealloc, /*tp_dealloc*/ 70 | 0, /*tp_print*/ 71 | 0, /*tp_getattr*/ 72 | 0, /*tp_setattr*/ 73 | 0, /*tp_compare*/ 74 | PyHirschCircle_str, /*tp_repr*/ 75 | 0, /*tp_as_number*/ 76 | 0, /*tp_as_sequence*/ 77 | 0, /*tp_as_mapping*/ 78 | 0, /*tp_hash */ 79 | 0, /*tp_call*/ 80 | PyHirschCircle_str, /*tp_str*/ 81 | 0, /*tp_getattro*/ 82 | 0, /*tp_setattro*/ 83 | 0, /*tp_as_buffer*/ 84 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 85 | "PyHirschCircle", /* tp_doc */ 86 | 0, /* tp_traverse */ 87 | 0, /* tp_clear */ 88 | 0, /* tp_richcompare */ 89 | 0, /* tp_weaklistoffset */ 90 | 0, /* tp_iter */ 91 | 0, /* tp_iternext */ 92 | PyHirschCircle_methods, /* tp_methods */ 93 | 0, /* tp_members */ 94 | 0, /* tp_getset */ 95 | 0, /* tp_base */ 96 | 0, /* tp_dict */ 97 | 0, /* tp_descr_get */ 98 | 0, /* tp_descr_set */ 99 | 0, /* tp_dictoffset */ 100 | (initproc)PyHirschCircle_init, /* tp_init */ 101 | 0, /* tp_alloc */ 102 | PyHirschCircle_new /* tp_new */ 103 | }; 104 | 105 | 106 | void PyHirschCircleAddToModule(PyObject *m) 107 | { 108 | Py_INCREF(&PyHirschCircleType); 109 | if (PyType_Ready(&PyHirschCircleType) < 0) 110 | return; 111 | PyModule_AddObject(m, "HCircle", (PyObject *)&PyHirschCircleType); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /src/pyhcircle.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HCircle 2 | #ifndef PYHCIRCLE_H 3 | #define HCIRCLE_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschCircle_FromHCircle(Halcon::HCircle Circle); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HCircle Circle; 13 | } PyHirschCircle; 14 | 15 | #define PyHirschCircle_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschCircleType) 17 | 18 | void PyHirschCircleAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschCircleType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhdatacode2d.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HDataCode2D 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschDataCode2D_dealloc(PyHirschDataCode2D* self) 7 | { 8 | if(self->DataCode2D) 9 | delete self->DataCode2D; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschDataCode2D_init(PyHirschDataCode2D *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | const char *SymbolType; 17 | const char *GenParamNames; 18 | const char *GenParamValues; 19 | if (PyArg_ParseTuple(args, "sss", 20 | &SymbolType, 21 | &GenParamNames, 22 | &GenParamValues)) 23 | self->DataCode2D = new Halcon::HDataCode2D(SymbolType, GenParamNames, GenParamValues); 24 | else 25 | self->DataCode2D = new Halcon::HDataCode2D(); 26 | 27 | return 0; 28 | } 29 | 30 | #include "hdatacode2d_autogen_methods_declarations.i" 31 | 32 | static PyMethodDef PyHirschDataCode2D_methods[] = { 33 | #include "hdatacode2d_autogen_methods_list.i" 34 | {NULL} /* Sentinel */ 35 | }; 36 | 37 | PyObject *PyHirschDataCode2D_FromHDataCode2D(Halcon::HDataCode2D DataCode2D) 38 | { 39 | PyHirschDataCode2D *v = (PyHirschDataCode2D*)PyObject_New(PyHirschDataCode2D, &PyHirschDataCode2DType); 40 | v->DataCode2D = new Halcon::HDataCode2D(DataCode2D); 41 | return (PyObject*)v; 42 | } 43 | 44 | PyTypeObject PyHirschDataCode2DType = { 45 | PyVarObject_HEAD_INIT(NULL, 0) 46 | "Hirsch.HDataCode2D", /*tp_name*/ 47 | sizeof(PyHirschDataCode2D), /*tp_basicsize*/ 48 | 0, /*tp_itemsize*/ 49 | (destructor)PyHirschDataCode2D_dealloc, /*tp_dealloc*/ 50 | 0, /*tp_print*/ 51 | 0, /*tp_getattr*/ 52 | 0, /*tp_setattr*/ 53 | 0, /*tp_compare*/ 54 | 0, /*tp_repr*/ 55 | 0, /*tp_as_number*/ 56 | 0, /*tp_as_sequence*/ 57 | 0, /*tp_as_mapping*/ 58 | 0, /*tp_hash */ 59 | 0, /*tp_call*/ 60 | 0, /*tp_str*/ 61 | 0, /*tp_getattro*/ 62 | 0, /*tp_setattro*/ 63 | 0, /*tp_as_buffer*/ 64 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 65 | "PyHirschDataCode2D", /* tp_doc */ 66 | 0, /* tp_traverse */ 67 | 0, /* tp_clear */ 68 | 0, /* tp_richcompare */ 69 | 0, /* tp_weaklistoffset */ 70 | 0, /* tp_iter */ 71 | 0, /* tp_iternext */ 72 | PyHirschDataCode2D_methods, /* tp_methods */ 73 | 0, /* tp_members */ 74 | 0, /* tp_getset */ 75 | 0, /* tp_base */ 76 | 0, /* tp_dict */ 77 | 0, /* tp_descr_get */ 78 | 0, /* tp_descr_set */ 79 | 0, /* tp_dictoffset */ 80 | (initproc)PyHirschDataCode2D_init, /* tp_init */ 81 | 0, /* tp_alloc */ 82 | PyType_GenericNew, /* tp_new */ 83 | }; 84 | 85 | 86 | void PyHirschDataCode2DAddToModule(PyObject *m) 87 | { 88 | Py_INCREF(&PyHirschDataCode2DType); 89 | if (PyType_Ready(&PyHirschDataCode2DType) < 0) 90 | return; 91 | PyModule_AddObject(m, "HDataCode2D", (PyObject *)&PyHirschDataCode2DType); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /src/pyhdatacode2d.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HDataCode2D 2 | #ifndef PYHDATACODE2D_H 3 | #define HDATACODE2D_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschDataCode2D_FromHDataCode2D(Halcon::HDataCode2D DataCode2D); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HDataCode2D *DataCode2D; 13 | } PyHirschDataCode2D; 14 | 15 | #define PyHirschDataCode2D_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschDataCode2DType) 17 | 18 | void PyHirschDataCode2DAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschDataCode2DType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhdpoint2d.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HDPoint2D 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschDPoint2D_dealloc(PyHirschDPoint2D* self) 7 | { 8 | // Explicit call to destructor. 9 | self->DPoint2D.~HDPoint2D(); 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschDPoint2D_init(PyHirschDPoint2D *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | int x,y; 17 | 18 | if (PyArg_ParseTuple(args,"(ii)",&x,&y)) 19 | self->DPoint2D = Halcon::HDPoint2D(x,y); 20 | else if (PyArg_ParseTuple(args,"ii",&x,&y)) 21 | self->DPoint2D = Halcon::HDPoint2D(x,y); 22 | else 23 | return -1; 24 | 25 | PyErr_Clear(); 26 | 27 | return 0; 28 | } 29 | 30 | #include "hdpoint2d_autogen_methods_declarations.i" 31 | 32 | static PyMethodDef PyHirschDPoint2D_methods[] = { 33 | #include "hdpoint2d_autogen_methods_list.i" 34 | {NULL} /* Sentinel */ 35 | }; 36 | 37 | Py_ssize_t PyHirschDPoint2D_Length(PyObject */*o*/) 38 | { 39 | return 4; // Return the length of the sequence 40 | } 41 | 42 | PyObject * 43 | PyHirschDPoint2D_GetItem(PyObject *self, Py_ssize_t i) 44 | { 45 | Halcon::HDPoint2D *DPoint2D = &(((PyHirschDPoint2D*)self)->DPoint2D); 46 | 47 | if (i==0) 48 | return PyFloat_FromDouble(DPoint2D->X()); 49 | else if (i==1) 50 | return PyFloat_FromDouble(DPoint2D->Y()); 51 | return NULL; 52 | 53 | } 54 | 55 | static PySequenceMethods PyHirschDPoint2D_sequence_methods = { 56 | PyHirschDPoint2D_Length, /* sq_length */ 57 | 0, /* sq_concat */ 58 | 0, /* sq_repeat */ 59 | PyHirschDPoint2D_GetItem, /* sq_item */ 60 | }; 61 | 62 | 63 | PyObject* PyHirschDPoint2D_iter(PyObject *self) 64 | { 65 | Py_INCREF(self); 66 | ((PyHirschDPoint2D*)self)->iter_pos = 0; 67 | return self; 68 | } 69 | 70 | PyObject* PyHirschDPoint2D_iternext(PyObject *self) 71 | { 72 | PyHirschDPoint2D *p = (PyHirschDPoint2D *)self; 73 | Halcon::HDPoint2D *DPoint2D = &(p->DPoint2D); 74 | 75 | if (p->iter_pos < 2) { 76 | int i=p->iter_pos; 77 | double ret; 78 | 79 | if (i==0) 80 | ret = DPoint2D->X(); 81 | else 82 | ret = DPoint2D->Y(); 83 | 84 | p->iter_pos+=1; 85 | 86 | return PyFloat_FromDouble(ret); 87 | } 88 | else { 89 | /* Raising of standard StopIteration exception with empty value. */ 90 | PyErr_SetNone(PyExc_StopIteration); 91 | return NULL; 92 | } 93 | } 94 | 95 | static PyObject * 96 | PyHirschDPoint2D_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 97 | { 98 | PyHirschDPoint2D *self; 99 | 100 | self = (PyHirschDPoint2D *)type->tp_alloc(type, 0); 101 | // Explicit call to constructor placement new 102 | new(&self->DPoint2D) Halcon::HPoint2D(); 103 | 104 | return (PyObject *)self; 105 | } 106 | 107 | PyObject *PyHirschDPoint2D_FromHDPoint2D(Halcon::HDPoint2D DPoint2D) 108 | { 109 | PyHirschDPoint2D *self = (PyHirschDPoint2D*)PyHirschDPoint2D_new(&PyHirschDPoint2DType, NULL, NULL); 110 | self->DPoint2D = DPoint2D; 111 | return (PyObject*)self; 112 | } 113 | 114 | #if PY_MAJOR_VERSION >= 3 115 | #define Py_TPFLAGS_HAVE_ITER 0 116 | #endif 117 | 118 | PyTypeObject PyHirschDPoint2DType = { 119 | PyVarObject_HEAD_INIT(NULL, 0) 120 | "Hirsch.DPoint2D", /*tp_name*/ 121 | sizeof(PyHirschDPoint2D), /*tp_basicsize*/ 122 | 0, /*tp_itemsize*/ 123 | (destructor)PyHirschDPoint2D_dealloc, /*tp_dealloc*/ 124 | 0, /*tp_print*/ 125 | 0, /*tp_getattr*/ 126 | 0, /*tp_setattr*/ 127 | 0, /*tp_compare*/ 128 | 0, /*tp_repr*/ 129 | 0, /*tp_as_number*/ 130 | &PyHirschDPoint2D_sequence_methods, /*tp_as_sequence*/ 131 | 0, /*tp_as_mapping*/ 132 | 0, /*tp_hash */ 133 | 0, /*tp_call*/ 134 | 0, /*tp_str*/ 135 | 0, /*tp_getattro*/ 136 | 0, /*tp_setattro*/ 137 | 0, /*tp_as_buffer*/ 138 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER, /*tp_flags*/ 139 | "PyHirschDPoint2D", /* tp_doc */ 140 | 0, /* tp_traverse */ 141 | 0, /* tp_clear */ 142 | 0, /* tp_richcompare */ 143 | 0, /* tp_weaklistoffset */ 144 | &PyHirschDPoint2D_iter, /* tp_iter */ 145 | &PyHirschDPoint2D_iternext, /* tp_iternext */ 146 | PyHirschDPoint2D_methods, /* tp_methods */ 147 | 0, /* tp_members */ 148 | 0, /* tp_getset */ 149 | 0, /* tp_base */ 150 | 0, /* tp_dict */ 151 | 0, /* tp_descr_get */ 152 | 0, /* tp_descr_set */ 153 | 0, /* tp_dictoffset */ 154 | (initproc)PyHirschDPoint2D_init, /* tp_init */ 155 | 0, /* tp_alloc */ 156 | PyHirschDPoint2D_new, /* tp_new */ 157 | }; 158 | 159 | 160 | void PyHirschDPoint2DAddToModule(PyObject *m) 161 | { 162 | Py_INCREF(&PyHirschDPoint2DType); 163 | if (PyType_Ready(&PyHirschDPoint2DType) < 0) 164 | return; 165 | PyModule_AddObject(m, "HDPoint2D", (PyObject *)&PyHirschDPoint2DType); 166 | } 167 | -------------------------------------------------------------------------------- /src/pyhdpoint2d.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HDPoint2D 2 | #ifndef HDPOINT2D_H 3 | #define HDPOINT2D_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschDPoint2D_FromHDPoint2D(Halcon::HDPoint2D DPoint2D); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HDPoint2D DPoint2D; 13 | int iter_pos; 14 | } PyHirschDPoint2D; 15 | 16 | #define PyHirschDPoint2D_Check(op) \ 17 | PyObject_TypeCheck(op, &PyHirschDPoint2DType) 18 | 19 | void PyHirschDPoint2DAddToModule(PyObject *m); 20 | 21 | extern PyTypeObject PyHirschDPoint2DType; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/pyhellipse.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HEllipse 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschEllipse_dealloc(PyHirschEllipse* self) 7 | { 8 | // Explicit call to destructor. 9 | self->Ellipse.~HEllipse(); 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschEllipse_init(PyHirschEllipse *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | double centerX,centerY,ra,rb,phi=0; 17 | PyHirschEllipse *rect; 18 | 19 | if (PyArg_ParseTuple(args,"(dd)dd|d",¢erX,¢erY,&ra,&rb,&phi)) 20 | self->Ellipse = Halcon::HEllipse(Halcon::HPoint2D(centerX,centerY), 21 | ra,rb,phi); 22 | 23 | else if (PyArg_ParseTuple(args,"O",&rect) 24 | && PyHirschEllipse_Check(rect) 25 | ) { 26 | self->Ellipse = Halcon::HEllipse(rect->Ellipse); 27 | } 28 | else 29 | // Empty rectangle 30 | self->Ellipse = Halcon::HEllipse(); 31 | 32 | PyErr_Clear(); 33 | 34 | return 0; 35 | } 36 | 37 | #include "hellipse_autogen_methods_declarations.i" 38 | 39 | static PyMethodDef PyHirschEllipse_methods[] = { 40 | #include "hellipse_autogen_methods_list.i" 41 | {NULL} /* Sentinel */ 42 | }; 43 | 44 | static PyObject * 45 | PyHirschEllipse_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 46 | { 47 | PyHirschEllipse *self; 48 | 49 | self = (PyHirschEllipse *)type->tp_alloc(type, 0); 50 | // Explicit call to constructor placement new 51 | new(&self->Ellipse) Halcon::HEllipse(); 52 | 53 | return (PyObject *)self; 54 | } 55 | 56 | PyObject *PyHirschEllipse_FromHEllipse(Halcon::HEllipse Ellipse) 57 | { 58 | PyHirschEllipse *self = (PyHirschEllipse*)PyHirschEllipse_new(&PyHirschEllipseType, NULL, NULL); 59 | self->Ellipse = Halcon::HEllipse(Ellipse); 60 | return (PyObject*)self; 61 | } 62 | 63 | static PyObject * 64 | PyHirschEllipse_str(PyObject *ob) 65 | { 66 | PyHirschEllipse *self = (PyHirschEllipse *)ob; 67 | Halcon::HPoint2D Center = self->Ellipse.Center(); 68 | double ra = self->Ellipse.Ra(); 69 | double rb = self->Ellipse.Rb(); 70 | double phi = self->Ellipse.Phi(); 71 | PyObject *Tuple = Py_BuildValue("Oddd", 72 | PyHirschPoint2D_FromHPoint2D(Center), 73 | ra,rb,phi); 74 | PyObject *Ret = PyObject_Str(Tuple); 75 | Py_DECREF(Tuple); 76 | 77 | return Ret; 78 | } 79 | 80 | PyTypeObject PyHirschEllipseType = { 81 | PyVarObject_HEAD_INIT(NULL, 0) 82 | "Hirsch.HEllipse", /*tp_name*/ 83 | sizeof(PyHirschEllipse), /*tp_basicsize*/ 84 | 0, /*tp_itemsize*/ 85 | (destructor)PyHirschEllipse_dealloc, /*tp_dealloc*/ 86 | 0, /*tp_print*/ 87 | 0, /*tp_getattr*/ 88 | 0, /*tp_setattr*/ 89 | 0, /*tp_compare*/ 90 | PyHirschEllipse_str, /*tp_str*/ 91 | 0, /*tp_as_number*/ 92 | 0, /*tp_as_sequence*/ 93 | 0, /*tp_as_mapping*/ 94 | 0, /*tp_hash */ 95 | 0, /*tp_call*/ 96 | PyHirschEllipse_str, /*tp_str*/ 97 | 0, /*tp_getattro*/ 98 | 0, /*tp_setattro*/ 99 | 0, /*tp_as_buffer*/ 100 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 101 | "PyHirschEllipse", /* tp_doc */ 102 | 0, /* tp_traverse */ 103 | 0, /* tp_clear */ 104 | 0, /* tp_richcompare */ 105 | 0, /* tp_weaklistoffset */ 106 | 0, /* tp_iter */ 107 | 0, /* tp_iternext */ 108 | PyHirschEllipse_methods, /* tp_methods */ 109 | 0, /* tp_members */ 110 | 0, /* tp_getset */ 111 | 0, /* tp_base */ 112 | 0, /* tp_dict */ 113 | 0, /* tp_descr_get */ 114 | 0, /* tp_descr_set */ 115 | 0, /* tp_dictoffset */ 116 | (initproc)PyHirschEllipse_init, /* tp_init */ 117 | 0, /* tp_alloc */ 118 | PyHirschEllipse_new /* tp_new */ 119 | }; 120 | 121 | 122 | void PyHirschEllipseAddToModule(PyObject *m) 123 | { 124 | Py_INCREF(&PyHirschEllipseType); 125 | if (PyType_Ready(&PyHirschEllipseType) < 0) 126 | return; 127 | PyModule_AddObject(m, "HEllipse", (PyObject *)&PyHirschEllipseType); 128 | } 129 | 130 | -------------------------------------------------------------------------------- /src/pyhellipse.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HEllipse 2 | #ifndef PYHELLIPSE_H 3 | #define HELLIPSE_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschEllipse_FromHEllipse(Halcon::HEllipse Ellipse); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HEllipse Ellipse; 13 | } PyHirschEllipse; 14 | 15 | #define PyHirschEllipse_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschEllipseType) 17 | 18 | void PyHirschEllipseAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschEllipseType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhimage.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HImage 2 | #ifndef HIMAGE_H 3 | #define HIMAGE_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschImage_FromHImage(Halcon::HImage Image); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HImage *Image; 13 | int iter_pos; 14 | int iter_size; 15 | int iter_width; 16 | Py_ssize_t buffer_shape[2]; 17 | Py_ssize_t buffer_strides[2]; 18 | } PyHirschImage; 19 | 20 | #define PyHirschImage_Check(op) \ 21 | PyObject_TypeCheck(op, &PyHirschImageType) 22 | 23 | void PyHirschImageAddToModule(PyObject *m); 24 | 25 | extern PyTypeObject PyHirschImageType; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/pyhimagearray.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HImageArray 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschImageArray_dealloc(PyHirschImageArray* self) 7 | { 8 | if(self->ImageArray) 9 | delete self->ImageArray; 10 | PyObject_Del(self); 11 | } 12 | 13 | #if PY_MAJOR_VERSION >= 3 14 | #define PyString_FromFormat PyUnicode_FromFormat 15 | #define PyString_AsString PyUnicode_AsUTF8 16 | #endif 17 | 18 | static int 19 | PyHirschImageArray_init(PyHirschImageArray *self, PyObject *args, PyObject */*kwds*/) 20 | { 21 | PyObject *v; 22 | 23 | self->ImageArray=new Halcon::HImageArray; 24 | 25 | if (PyArg_ParseTuple(args,"O",&v) && PySequence_Check(v)) { 26 | bool error = false; 27 | for (int i=0; iImageArray->Append(*(((PyHirschImage*)el)->Image)); 32 | else 33 | error = true; 34 | 35 | Py_DECREF(el); 36 | if (error) { 37 | PyObject *ErrorMessage = PyString_FromFormat("Unsupported type of element %d in sequence when initializing PyHTuple!", i+1); 38 | PyErr_SetString(PyExc_RuntimeError, PyString_AsString(ErrorMessage)); 39 | Py_DECREF(ErrorMessage); 40 | break; 41 | } 42 | } 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | #include "himagearray_autogen_methods_declarations.i" 49 | 50 | static PyMethodDef PyHirschImageArray_methods[] = { 51 | #include "himagearray_autogen_methods_list.i" 52 | {NULL} /* Sentinel */ 53 | }; 54 | 55 | static Py_ssize_t PyHirschImageArray_Length(PyObject *o) 56 | { 57 | Halcon::HImageArray *ImageArray = (((PyHirschImageArray*)o)->ImageArray); 58 | return ImageArray->Num(); // Return the length of the sequence 59 | } 60 | 61 | static PyObject * 62 | PyHirschImageArray_GetItem(PyObject *o, Py_ssize_t i) 63 | { 64 | Halcon::HImageArray *ImageArray = (((PyHirschImageArray*)o)->ImageArray); 65 | Halcon::HImage& Image((*ImageArray)[i]); 66 | return PyHirschImage_FromHImage(Image); 67 | } 68 | 69 | static PySequenceMethods PyHirschImageArray_sequence_methods = { 70 | PyHirschImageArray_Length, /* sq_length */ 71 | 0, /* sq_concat */ 72 | 0, /* sq_repeat */ 73 | PyHirschImageArray_GetItem, /* sq_item */ 74 | 0 75 | }; 76 | 77 | static PyObject* PyHirschImageArray_iter(PyObject *self) 78 | { 79 | Py_INCREF(self); 80 | ((PyHirschImageArray*)self)->iter_pos = 0; 81 | return self; 82 | } 83 | 84 | static PyObject* PyHirschImageArray_iternext(PyObject *self) 85 | { 86 | PyHirschImageArray *p = (PyHirschImageArray *)self; 87 | Halcon::HImageArray *ImageArray = p->ImageArray; 88 | 89 | if (p->iter_pos < ImageArray->Num()) { 90 | PyObject *ret = PyHirschImageArray_GetItem(self,p->iter_pos); 91 | p->iter_pos+=1; 92 | return ret; 93 | } 94 | else { 95 | /* Raising of standard StopIteration exception with empty value. */ 96 | PyErr_SetNone(PyExc_StopIteration); 97 | return NULL; 98 | } 99 | } 100 | 101 | PyObject *PyHirschImageArray_FromHImageArray(Halcon::HImageArray ImageArray) 102 | { 103 | PyHirschImageArray *v = (PyHirschImageArray*)PyObject_New(PyHirschImageArray, &PyHirschImageArrayType); 104 | v->ImageArray = new Halcon::HImageArray(ImageArray); 105 | return (PyObject*)v; 106 | } 107 | 108 | PyTypeObject PyHirschImageArrayType = { 109 | PyVarObject_HEAD_INIT(NULL, 0) 110 | "Hirsch.HImageArray", /*tp_name*/ 111 | sizeof(PyHirschImageArray), /*tp_basicsize*/ 112 | 0, /*tp_itemsize*/ 113 | (destructor)PyHirschImageArray_dealloc, /*tp_dealloc*/ 114 | 0, /*tp_print*/ 115 | 0, /*tp_getattr*/ 116 | 0, /*tp_setattr*/ 117 | 0, /*tp_compare*/ 118 | 0, /*tp_repr*/ 119 | 0, /*tp_as_number*/ 120 | &PyHirschImageArray_sequence_methods, /*tp_as_sequence*/ 121 | 0, /*tp_as_mapping*/ 122 | 0, /*tp_hash */ 123 | 0, /*tp_call*/ 124 | 0, /*tp_str*/ 125 | 0, /*tp_getattro*/ 126 | 0, /*tp_setattro*/ 127 | 0, /*tp_as_buffer*/ 128 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 129 | "PyHirschImageArray", /* tp_doc */ 130 | 0, /* tp_traverse */ 131 | 0, /* tp_clear */ 132 | 0, /* tp_richcompare */ 133 | 0, /* tp_weaklistoffset */ 134 | PyHirschImageArray_iter, /* tp_iter */ 135 | PyHirschImageArray_iternext, /* tp_iternext */ 136 | PyHirschImageArray_methods, /* tp_methods */ 137 | 0, /* tp_members */ 138 | 0, /* tp_getset */ 139 | 0, /* tp_base */ 140 | 0, /* tp_dict */ 141 | 0, /* tp_descr_get */ 142 | 0, /* tp_descr_set */ 143 | 0, /* tp_dictoffset */ 144 | (initproc)PyHirschImageArray_init, /* tp_init */ 145 | 0, /* tp_alloc */ 146 | PyType_GenericNew, /* tp_new */ 147 | }; 148 | 149 | 150 | void PyHirschImageArrayAddToModule(PyObject *m) 151 | { 152 | Py_INCREF(&PyHirschImageArrayType); 153 | if (PyType_Ready(&PyHirschImageArrayType) < 0) 154 | return; 155 | PyModule_AddObject(m, "HImageArray", (PyObject *)&PyHirschImageArrayType); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /src/pyhimagearray.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HImageArray 2 | #ifndef PYHIMAGEARRAY_H 3 | #define PYHIMAGEARRAY_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschImageArray_FromHImageArray(Halcon::HImageArray ImageArray); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HImageArray *ImageArray; 13 | int iter_pos; 14 | } PyHirschImageArray; 15 | 16 | #define PyHirschImageArray_Check(op) \ 17 | PyObject_TypeCheck(op, &PyHirschImageArrayType) 18 | 19 | void PyHirschImageArrayAddToModule(PyObject *m); 20 | 21 | extern PyTypeObject PyHirschImageArrayType; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/pyhirsch.cc: -------------------------------------------------------------------------------- 1 | // Python binding for halcon 2 | #include "pyhirsch.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct module_state { 9 | PyObject *error; 10 | }; 11 | 12 | static PyObject *HalconError; 13 | 14 | PyMethodDef PyHirschMethods[] = { 15 | {NULL, NULL, 0, NULL} /* Sentinel */ 16 | }; 17 | 18 | static void MyHalconExceptionHandler(const Halcon::HException& except) 19 | { 20 | throw except; 21 | } 22 | 23 | #if PY_MAJOR_VERSION >= 3 24 | #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) 25 | #else 26 | #define GETSTATE(m) (&_state) 27 | static struct module_state _state; 28 | #endif 29 | 30 | #if PY_MAJOR_VERSION >= 3 31 | static int myextension_traverse(PyObject *m, visitproc visit, void *arg) { 32 | Py_VISIT(GETSTATE(m)->error); 33 | return 0; 34 | } 35 | 36 | static int myextension_clear(PyObject *m) { 37 | Py_CLEAR(GETSTATE(m)->error); 38 | return 0; 39 | } 40 | 41 | static struct PyModuleDef moduledef = { 42 | PyModuleDef_HEAD_INIT, 43 | "_hirch", 44 | NULL, 45 | sizeof(struct module_state), 46 | PyHirschMethods, 47 | NULL, 48 | myextension_traverse, 49 | myextension_clear, 50 | NULL 51 | }; 52 | #endif 53 | 54 | #define INITERROR return NULL 55 | 56 | PyObject * 57 | pyhirsch_init_extension(void) 58 | { 59 | PyObject *m; 60 | 61 | #if PY_MAJOR_VERSION >= 3 62 | m = PyModule_Create(&moduledef); 63 | if (m == NULL) 64 | return NULL; 65 | #else 66 | m = Py_InitModule("_hirsch", PyHirschMethods); 67 | if (m == NULL) 68 | return; 69 | #endif 70 | 71 | PyHirschTupleAddToModule(m); 72 | PyHirschPoint2DAddToModule(m); 73 | PyHirschDPoint2DAddToModule(m); 74 | PyHirschRectangle1AddToModule(m); 75 | PyHirschRectangle2AddToModule(m); 76 | PyHirschRegionAddToModule(m); 77 | PyHirschRegionArrayAddToModule(m); 78 | PyHirschImageAddToModule(m); 79 | PyHirschImageArrayAddToModule(m); 80 | PyHirschXLDContArrayAddToModule(m); 81 | PyHirschXLDContAddToModule(m); 82 | PyHirschDataCode2DAddToModule(m); 83 | PyHirschBarCodeAddToModule(m); 84 | PyHirschLine2DAddToModule(m); 85 | PyHirschXLDAddToModule(m); 86 | PyHirschXLDArrayAddToModule(m); 87 | PyHirschCircleAddToModule(m); 88 | PyHirschEllipseAddToModule(m); 89 | PyHirschPixValAddToModule(m); 90 | 91 | HalconError = PyErr_NewException((char*)"halcon.error", NULL, NULL); 92 | Py_INCREF(HalconError); 93 | PyModule_AddObject(m, "HError", HalconError); 94 | 95 | return m; 96 | } 97 | 98 | static PyObject * 99 | moduleinit(void) 100 | { 101 | PyObject *m; 102 | 103 | Halcon::HException::InstallHHandler(&MyHalconExceptionHandler); 104 | 105 | return pyhirsch_init_extension(); 106 | } 107 | 108 | #if PY_MAJOR_VERSION < 3 109 | PyMODINIT_FUNC init_hirsch(void) 110 | { 111 | moduleinit(); 112 | } 113 | 114 | #else 115 | // This is the python dll external entry point 116 | PyMODINIT_FUNC 117 | PyInit__hirsch(void) 118 | { 119 | return moduleinit(); 120 | } 121 | #endif 122 | -------------------------------------------------------------------------------- /src/pyhirsch.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * Project: python * 3 | * Module: hirsch * 4 | * Module Description: * 5 | * * 6 | * Compilation: * 7 | * * 8 | * Author: Dov Grobgeld * 9 | ********************************************************************/ 10 | 11 | #ifndef _HALCON_H_ 12 | #define _HALCON_H_ 13 | 14 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) 15 | #pragma warning( push ) 16 | #pragma warning( disable :4244) 17 | 18 | #include "HalconCpp.h" 19 | 20 | #pragma warning( pop ) 21 | #endif 22 | 23 | #include "pyhpoint2d.h" 24 | #include "pyhdpoint2d.h" 25 | #include "pyhrectangle1.h" 26 | #include "pyhrectangle2.h" 27 | #include "pyhimage.h" 28 | #include "pyhimagearray.h" 29 | #include "pyhregion.h" 30 | #include "pyhregionarray.h" 31 | #include "pyhxldcont.h" 32 | #include "pyhxldcontarray.h" 33 | #include "pyhtuple.h" 34 | #include "pyhdatacode2d.h" 35 | #include "pyhbarcode.h" 36 | #include "pyhpixval.h" 37 | #include "pyhimagearray.h" 38 | #include "pyhtemplate.h" 39 | #include "pyhline2d.h" 40 | #include "pyhxld.h" 41 | #include "pyhxldarray.h" 42 | #include "pyhcircle.h" 43 | #include "pyhellipse.h" 44 | #include "pyhaffinetrans2d.h" 45 | 46 | // This may be called when initializing the module statically 47 | PyMODINIT_FUNC 48 | pyhirsch_init_extension(void); 49 | 50 | #endif /* HALCON */ 51 | -------------------------------------------------------------------------------- /src/pyhline2d.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HLine2D 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschLine2D_dealloc(PyHirschLine2D* self) 7 | { 8 | // Explicit call to destructor. 9 | self->Line2D.~HLine2D(); 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschLine2D_init(PyHirschLine2D *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | double left, top, right, bottom; 17 | PyHirschLine2D *line; 18 | 19 | if (PyArg_ParseTuple(args,"(dd)(dd)",&left,&top,&right,&bottom)) 20 | self->Line2D = Halcon::HLine2D(Halcon::HPoint2D(left,top), 21 | Halcon::HPoint2D(right,bottom)); 22 | 23 | else if (PyArg_ParseTuple(args,"O",&line) 24 | && PyHirschRectangle1_Check(line) 25 | ) { 26 | self->Line2D = Halcon::HLine2D(line->Line2D); 27 | } 28 | else 29 | // empty line 30 | self->Line2D = Halcon::HLine2D(Halcon::HPoint2D(0,0),Halcon::HPoint2D(0,0)); 31 | PyErr_Clear(); 32 | 33 | return 0; 34 | } 35 | 36 | #include "hline2d_autogen_methods_declarations.i" 37 | 38 | static PyMethodDef PyHirschLine2D_methods[] = { 39 | #include "hline2d_autogen_methods_list.i" 40 | {NULL} /* Sentinel */ 41 | }; 42 | 43 | static PyObject * 44 | PyHirschLine2D_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 45 | { 46 | PyHirschLine2D *self; 47 | 48 | self = (PyHirschLine2D *)type->tp_alloc(type, 0); 49 | // Explicit call to constructor placement new 50 | new(&self->Line2D) Halcon::HLine2D(Halcon::HPoint2D(0,0),Halcon::HPoint2D(0,0)); 51 | 52 | return (PyObject *)self; 53 | } 54 | 55 | PyObject *PyHirschLine2D_FromHLine2D(Halcon::HLine2D Line2D) 56 | { 57 | PyHirschLine2D *self = (PyHirschLine2D*)PyHirschLine2D_new(&PyHirschLine2DType, NULL, NULL); 58 | self->Line2D = Line2D; 59 | return (PyObject*)self; 60 | } 61 | 62 | static PyObject * 63 | PyHirschLine2D_str(PyObject *ob) 64 | { 65 | PyHirschLine2D *self = (PyHirschLine2D *)ob; 66 | Halcon::HPoint2D start = self->Line2D.Start(); 67 | Halcon::HPoint2D end = self->Line2D.End(); 68 | PyObject *Tuple = Py_BuildValue("(OO)", 69 | PyHirschPoint2D_FromHPoint2D(start), 70 | PyHirschPoint2D_FromHPoint2D(end)); 71 | PyObject *Ret = PyObject_Str(Tuple); 72 | Py_DECREF(Tuple); 73 | 74 | return Ret; 75 | } 76 | 77 | PyTypeObject PyHirschLine2DType = { 78 | PyVarObject_HEAD_INIT(NULL, 0) 79 | "Hirsch.Line2D", /*tp_name*/ 80 | sizeof(PyHirschLine2D), /*tp_basicsize*/ 81 | 0, /*tp_itemsize*/ 82 | (destructor)PyHirschLine2D_dealloc, /*tp_dealloc*/ 83 | 0, /*tp_print*/ 84 | 0, /*tp_getattr*/ 85 | 0, /*tp_setattr*/ 86 | 0, /*tp_compare*/ 87 | PyHirschLine2D_str, /*tp_repr*/ 88 | 0, /*tp_as_number*/ 89 | 0, /*tp_as_sequence*/ 90 | 0, /*tp_as_mapping*/ 91 | 0, /*tp_hash */ 92 | 0, /*tp_call*/ 93 | PyHirschLine2D_str, /*tp_str*/ 94 | 0, /*tp_getattro*/ 95 | 0, /*tp_setattro*/ 96 | 0, /*tp_as_buffer*/ 97 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 98 | "PyHirschLine2D", /* tp_doc */ 99 | 0, /* tp_traverse */ 100 | 0, /* tp_clear */ 101 | 0, /* tp_richcompare */ 102 | 0, /* tp_weaklistoffset */ 103 | 0, /* tp_iter */ 104 | 0, /* tp_iternext */ 105 | PyHirschLine2D_methods, /* tp_methods */ 106 | 0, /* tp_members */ 107 | 0, /* tp_getset */ 108 | 0, /* tp_base */ 109 | 0, /* tp_dict */ 110 | 0, /* tp_descr_get */ 111 | 0, /* tp_descr_set */ 112 | 0, /* tp_dictoffset */ 113 | (initproc)PyHirschLine2D_init, /* tp_init */ 114 | 0, /* tp_alloc */ 115 | PyHirschLine2D_new, /* tp_new */ 116 | }; 117 | 118 | 119 | void PyHirschLine2DAddToModule(PyObject *m) 120 | { 121 | Py_INCREF(&PyHirschLine2DType); 122 | if (PyType_Ready(&PyHirschLine2DType) < 0) 123 | return; 124 | PyModule_AddObject(m, "HLine2D", (PyObject *)&PyHirschLine2DType); 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/pyhline2d.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HLine2D 2 | #ifndef PYHLINE2D_H 3 | #define HLINE2D_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschLine2D_FromHLine2D(Halcon::HLine2D Line2D); 9 | 10 | // Rewrite for static types without default constructor. 11 | struct PyHirschLine2D { 12 | PyHirschLine2D(void) 13 | : Line2D(Halcon::HPoint2D(0,0),Halcon::HPoint2D(0,0)) {} 14 | PyObject_HEAD; 15 | Halcon::HLine2D Line2D; 16 | }; 17 | 18 | #define PyHirschLine2D_Check(op) \ 19 | PyObject_TypeCheck(op, &PyHirschLine2DType) 20 | 21 | void PyHirschLine2DAddToModule(PyObject *m); 22 | 23 | extern PyTypeObject PyHirschLine2DType; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/pyhpixval.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HPixVal 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschPixVal_dealloc(PyHirschPixVal* self) 7 | { 8 | if(self->PixVal) 9 | delete self->PixVal; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschPixVal_init(PyHirschPixVal *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | // TBD - Use PyArg_ParseTupleAndKeywords() to do special initialziation 17 | self->PixVal=new Halcon::HPixVal; 18 | return 0; 19 | } 20 | 21 | #include "hpixval_autogen_methods_declarations.i" 22 | 23 | static PyMethodDef PyHirschPixVal_methods[] = { 24 | #include "hpixval_autogen_methods_list.i" 25 | {NULL} /* Sentinel */ 26 | }; 27 | 28 | PyObject *PyHirschPixVal_FromHPixVal(Halcon::HPixVal PixVal) 29 | { 30 | PyHirschPixVal *v = (PyHirschPixVal*)PyObject_New(PyHirschPixVal, &PyHirschPixValType); 31 | v->PixVal = new Halcon::HPixVal(PixVal); 32 | return (PyObject*)v; 33 | } 34 | 35 | PyTypeObject PyHirschPixValType = { 36 | PyVarObject_HEAD_INIT(NULL, 0) 37 | "Hirsch.PyHirschPixVal", /*tp_name*/ 38 | sizeof(PyHirschPixVal), /*tp_basicsize*/ 39 | 0, /*tp_itemsize*/ 40 | (destructor)PyHirschPixVal_dealloc, /*tp_dealloc*/ 41 | 0, /*tp_print*/ 42 | 0, /*tp_getattr*/ 43 | 0, /*tp_setattr*/ 44 | 0, /*tp_compare*/ 45 | 0, /*tp_repr*/ 46 | 0, /*tp_as_number*/ 47 | 0, /*tp_as_sequence*/ 48 | 0, /*tp_as_mapping*/ 49 | 0, /*tp_hash */ 50 | 0, /*tp_call*/ 51 | 0, /*tp_str*/ 52 | 0, /*tp_getattro*/ 53 | 0, /*tp_setattro*/ 54 | 0, /*tp_as_buffer*/ 55 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 | "PyHirschPixVal", /* tp_doc */ 57 | 0, /* tp_traverse */ 58 | 0, /* tp_clear */ 59 | 0, /* tp_richcompare */ 60 | 0, /* tp_weaklistoffset */ 61 | 0, /* tp_iter */ 62 | 0, /* tp_iternext */ 63 | PyHirschPixVal_methods, /* tp_methods */ 64 | 0, /* tp_members */ 65 | 0, /* tp_getset */ 66 | 0, /* tp_base */ 67 | 0, /* tp_dict */ 68 | 0, /* tp_descr_get */ 69 | 0, /* tp_descr_set */ 70 | 0, /* tp_dictoffset */ 71 | (initproc)PyHirschPixVal_init, /* tp_init */ 72 | 0, /* tp_alloc */ 73 | PyType_GenericNew, /* tp_new */ 74 | }; 75 | 76 | 77 | void PyHirschPixValAddToModule(PyObject *m) 78 | { 79 | Py_INCREF(&PyHirschPixValType); 80 | if (PyType_Ready(&PyHirschPixValType) < 0) 81 | return; 82 | PyModule_AddObject(m, "HPixVal", (PyObject *)&PyHirschPixValType); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/pyhpixval.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for Halcon type HPixVal 2 | #ifndef PYHPIXVAL_H 3 | #define HPIXVAL_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschPixVal_FromHPixVal(Halcon::HPixVal PixVal); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HPixVal *PixVal; 13 | } PyHirschPixVal; 14 | 15 | #define PyHirschPixVal_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschPixValType) 17 | 18 | void PyHirschPixValAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschPixValType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhpoint2d.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HPoint2D 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschPoint2D_dealloc(PyHirschPoint2D* self) 7 | { 8 | // Explicit call to destructor. 9 | self->Point2D.~HPoint2D(); 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschPoint2D_init(PyHirschPoint2D *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | double x,y; 17 | 18 | if (PyArg_ParseTuple(args,"(dd)",&x,&y)) 19 | self->Point2D = Halcon::HPoint2D(x,y); 20 | else if (PyArg_ParseTuple(args,"dd",&x,&y)) 21 | self->Point2D = Halcon::HPoint2D(x,y); 22 | else 23 | self->Point2D = Halcon::HPoint2D(0,0); 24 | 25 | PyErr_Clear(); 26 | 27 | return 0; 28 | } 29 | 30 | static PyObject * 31 | PyHirschPoint2D_str(PyObject *ob) 32 | { 33 | PyHirschPoint2D *self = (PyHirschPoint2D *)ob; 34 | PyObject *Tuple = Py_BuildValue("(dd)",self->Point2D.X(),self->Point2D.Y()); 35 | PyObject *Ret = PyObject_Str(Tuple); 36 | Py_DECREF(Tuple); 37 | 38 | return Ret; 39 | } 40 | 41 | #include "hpoint2d_autogen_methods_declarations.i" 42 | 43 | static PyMethodDef PyHirschPoint2D_methods[] = { 44 | #include "hpoint2d_autogen_methods_list.i" 45 | {NULL} /* Sentinel */ 46 | }; 47 | 48 | Py_ssize_t PyHirschPoint2D_Length(PyObject */*o*/) 49 | { 50 | return 2; // Return the length of the sequence 51 | } 52 | 53 | PyObject * 54 | PyHirschPoint2D_GetItem(PyHirschPoint2D *self, Py_ssize_t i) 55 | { 56 | Halcon::HPoint2D& Point2D(((PyHirschPoint2D*)self)->Point2D); 57 | 58 | if (i==0) 59 | return PyFloat_FromDouble(Point2D.X()); 60 | else if (i==1) 61 | return PyFloat_FromDouble(Point2D.Y()); 62 | return NULL; 63 | } 64 | 65 | static PySequenceMethods PyHirschPoint2D_sequence_methods = { 66 | PyHirschPoint2D_Length, /* sq_length */ 67 | 0, /* sq_concat */ 68 | 0, /* sq_repeat */ 69 | (ssizeargfunc)PyHirschPoint2D_GetItem, /* sq_item */ 70 | }; 71 | 72 | 73 | PyObject* PyHirschPoint2D_iter(PyObject *self) 74 | { 75 | Py_INCREF(self); 76 | ((PyHirschPoint2D*)self)->iter_pos = 0; 77 | return self; 78 | } 79 | 80 | PyObject* PyHirschPoint2D_iternext(PyObject *self) 81 | { 82 | PyHirschPoint2D *p = (PyHirschPoint2D *)self; 83 | Halcon::HPoint2D& Point2D(p->Point2D); 84 | 85 | if (p->iter_pos < 2) { 86 | int i=p->iter_pos; // shortcut 87 | double ret; 88 | if (i==0) 89 | ret = Point2D.X(); 90 | else 91 | ret = Point2D.Y(); 92 | 93 | p->iter_pos+=1; 94 | 95 | return PyFloat_FromDouble(ret); 96 | } 97 | else { 98 | /* Raising of standard StopIteration exception with empty value. */ 99 | PyErr_SetNone(PyExc_StopIteration); 100 | return NULL; 101 | } 102 | } 103 | 104 | static PyObject * 105 | PyHirschPoint2D_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 106 | { 107 | PyHirschPoint2D *self; 108 | 109 | self = (PyHirschPoint2D *)type->tp_alloc(type, 0); 110 | // Explicit call to constructor placement new 111 | new(&self->Point2D) Halcon::HPoint2D(); 112 | 113 | return (PyObject *)self; 114 | } 115 | 116 | PyObject *PyHirschPoint2D_FromHPoint2D(Halcon::HPoint2D Point2D) 117 | { 118 | PyHirschPoint2D *self = (PyHirschPoint2D*)PyHirschPoint2D_new(&PyHirschPoint2DType, NULL, NULL); 119 | self->Point2D = Point2D; 120 | return (PyObject*)self; 121 | } 122 | 123 | #if PY_MAJOR_VERSION >= 3 124 | #define Py_TPFLAGS_HAVE_ITER 0 125 | #endif 126 | 127 | PyTypeObject PyHirschPoint2DType = { 128 | PyVarObject_HEAD_INIT(NULL, 0) 129 | "Hirsch.Point2D", /*tp_name*/ 130 | sizeof(PyHirschPoint2D), /*tp_basicsize*/ 131 | 0, /*tp_itemsize*/ 132 | (destructor)PyHirschPoint2D_dealloc, /*tp_dealloc*/ 133 | 0, /*tp_print*/ 134 | 0, /*tp_getattr*/ 135 | 0, /*tp_setattr*/ 136 | 0, /*tp_compare*/ 137 | PyHirschPoint2D_str, /*tp_repr*/ 138 | 0, /*tp_as_number*/ 139 | &PyHirschPoint2D_sequence_methods, /*tp_as_sequence*/ 140 | 0, /*tp_as_mapping*/ 141 | 0, /*tp_hash */ 142 | 0, /*tp_call*/ 143 | PyHirschPoint2D_str, /*tp_str*/ 144 | 0, /*tp_getattro*/ 145 | 0, /*tp_setattro*/ 146 | 0, /*tp_as_buffer*/ 147 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER, /*tp_flags*/ 148 | "PyHirschPoint2D", /* tp_doc */ 149 | 0, /* tp_traverse */ 150 | 0, /* tp_clear */ 151 | 0, /* tp_richcompare */ 152 | 0, /* tp_weaklistoffset */ 153 | &PyHirschPoint2D_iter, /* tp_iter */ 154 | &PyHirschPoint2D_iternext, /* tp_iternext */ 155 | PyHirschPoint2D_methods, /* tp_methods */ 156 | 0, /* tp_members */ 157 | 0, /* tp_getset */ 158 | 0, /* tp_base */ 159 | 0, /* tp_dict */ 160 | 0, /* tp_descr_get */ 161 | 0, /* tp_descr_set */ 162 | 0, /* tp_dictoffset */ 163 | (initproc)PyHirschPoint2D_init, /* tp_init */ 164 | 0, /* tp_alloc */ 165 | PyHirschPoint2D_new, /* tp_new */ 166 | }; 167 | 168 | 169 | void PyHirschPoint2DAddToModule(PyObject *m) 170 | { 171 | Py_INCREF(&PyHirschPoint2DType); 172 | if (PyType_Ready(&PyHirschPoint2DType) < 0) 173 | return; 174 | PyModule_AddObject(m, "HPoint2D", (PyObject *)&PyHirschPoint2DType); 175 | } 176 | -------------------------------------------------------------------------------- /src/pyhpoint2d.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HPoint2D 2 | #ifndef HPOINT2D_H 3 | #define HPOINT2D_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschPoint2D_FromHPoint2D(Halcon::HPoint2D Point2D); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HPoint2D Point2D; 13 | int iter_pos; 14 | } PyHirschPoint2D; 15 | 16 | #define PyHirschPoint2D_Check(op) \ 17 | PyObject_TypeCheck(op, &PyHirschPoint2DType) 18 | 19 | void PyHirschPoint2DAddToModule(PyObject *m); 20 | 21 | extern PyTypeObject PyHirschPoint2DType; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/pyhrectangle1.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRectangle1 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschRectangle1_dealloc(PyHirschRectangle1* self) 7 | { 8 | self->Rectangle1.~HRectangle1(); 9 | Py_TYPE(self)->tp_free((PyObject*)self); 10 | } 11 | 12 | static int 13 | PyHirschRectangle1_init(PyHirschRectangle1 *self, PyObject *args, PyObject */*kwds*/) 14 | { 15 | double left, top, right, bottom; 16 | PyHirschRectangle1 *rect; 17 | 18 | try { 19 | if (PyArg_ParseTuple(args,"(dd)(dd)",&left,&top,&right,&bottom)) 20 | self->Rectangle1 = Halcon::HRectangle1(Halcon::HPoint2D(left,top), 21 | Halcon::HPoint2D(right,bottom)); 22 | 23 | else if (PyArg_ParseTuple(args,"O",&rect) 24 | && PyHirschRectangle1_Check(rect) 25 | ) { 26 | self->Rectangle1 = Halcon::HRectangle1(rect->Rectangle1); 27 | } 28 | else 29 | // empty rectangle 30 | self->Rectangle1 = Halcon::HRectangle1(); 31 | } 32 | catch (Halcon::HException &except) { 33 | PyErr_SetString(PyExc_RuntimeError, except.message); 34 | return 0; 35 | } 36 | 37 | PyErr_Clear(); 38 | 39 | return 0; 40 | } 41 | 42 | #include "hrectangle1_autogen_methods_declarations.i" 43 | 44 | static PyMethodDef PyHirschRectangle1_methods[] = { 45 | #include "hrectangle1_autogen_methods_list.i" 46 | {NULL} /* Sentinel */ 47 | }; 48 | 49 | Py_ssize_t PyHirschRectangle1_Length(PyObject */*o*/) 50 | { 51 | return 2; 52 | } 53 | 54 | PyObject * 55 | PyHirschRectangle1_GetItem(PyObject *self, Py_ssize_t i) 56 | { 57 | Halcon::HRectangle1 *Rectangle1 = &(((PyHirschRectangle1*)self)->Rectangle1); 58 | 59 | if (i==0) { 60 | return PyHirschPoint2D_FromHPoint2D(Rectangle1->UpperLeft()); 61 | } 62 | else if (i==1) { 63 | return PyHirschPoint2D_FromHPoint2D(Rectangle1->LowerRight()); 64 | } 65 | return NULL; 66 | } 67 | 68 | static PySequenceMethods PyHirschRectangle1_sequence_methods = { 69 | PyHirschRectangle1_Length, /* sq_length */ 70 | 0, /* sq_concat */ 71 | 0, /* sq_repeat */ 72 | PyHirschRectangle1_GetItem, /* sq_item */ 73 | }; 74 | 75 | 76 | PyObject* PyHirschRectangle1_iter(PyObject *self) 77 | { 78 | Py_INCREF(self); 79 | ((PyHirschRectangle1*)self)->iter_pos = 0; 80 | return self; 81 | } 82 | 83 | PyObject* PyHirschRectangle1_iternext(PyObject *self) 84 | { 85 | PyHirschRectangle1 *p = (PyHirschRectangle1 *)self; 86 | Halcon::HRectangle1 *Rectangle1 = &(p->Rectangle1); 87 | 88 | if (p->iter_pos < 2) { 89 | PyObject *ret = NULL; 90 | int i=p->iter_pos; // shortcut 91 | 92 | // Strangely this crashe unless I create the temporary valiable pt. 93 | if (i==0) { 94 | Halcon::HPoint2D pt = Rectangle1->UpperLeft(); 95 | ret = PyHirschPoint2D_FromHPoint2D(pt); 96 | } 97 | else if (i==1) { 98 | Halcon::HPoint2D pt = Rectangle1->LowerRight(); 99 | ret = PyHirschPoint2D_FromHPoint2D(pt); 100 | } 101 | 102 | p->iter_pos+=1; 103 | 104 | return ret; 105 | } else { 106 | /* Raising of standard StopIteration exception with empty value. */ 107 | PyErr_SetNone(PyExc_StopIteration); 108 | return NULL; 109 | } 110 | } 111 | 112 | static PyObject * 113 | PyHirschRectangle1_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 114 | { 115 | PyHirschRectangle1 *self; 116 | 117 | self = (PyHirschRectangle1 *)type->tp_alloc(type, 0); 118 | // Explicit call to constructor placement new 119 | new(&self->Rectangle1) Halcon::HPoint2D(); 120 | 121 | return (PyObject *)self; 122 | } 123 | 124 | PyObject *PyHirschRectangle1_FromHRectangle1(Halcon::HRectangle1 Rectangle1) 125 | { 126 | PyHirschRectangle1 *self = (PyHirschRectangle1*)PyHirschRectangle1_new(&PyHirschRectangle1Type, NULL, NULL); 127 | self->Rectangle1 = Rectangle1; 128 | return (PyObject*)self; 129 | } 130 | 131 | static PyObject * 132 | PyHirschRectangle1_str(PyObject *ob) 133 | { 134 | PyHirschRectangle1 *self = (PyHirschRectangle1 *)ob; 135 | Halcon::HPoint2D ul = self->Rectangle1.UpperLeft(); 136 | Halcon::HPoint2D lr = self->Rectangle1.LowerRight(); 137 | PyObject *Tuple = Py_BuildValue("(OO)", 138 | PyHirschPoint2D_FromHPoint2D(ul), 139 | PyHirschPoint2D_FromHPoint2D(lr)); 140 | PyObject *Ret = PyObject_Str(Tuple); 141 | Py_DECREF(Tuple); 142 | 143 | return Ret; 144 | } 145 | 146 | #if PY_MAJOR_VERSION >= 3 147 | #define Py_TPFLAGS_HAVE_ITER 0 148 | #endif 149 | 150 | PyTypeObject PyHirschRectangle1Type = { 151 | PyVarObject_HEAD_INIT(NULL, 0) 152 | "Hirsch.Rectangle1", /*tp_name*/ 153 | sizeof(PyHirschRectangle1), /*tp_basicsize*/ 154 | 0, /*tp_itemsize*/ 155 | (destructor)PyHirschRectangle1_dealloc, /*tp_dealloc*/ 156 | 0, /*tp_print*/ 157 | 0, /*tp_getattr*/ 158 | 0, /*tp_setattr*/ 159 | 0, /*tp_compare*/ 160 | PyHirschRectangle1_str, /*tp_repr*/ 161 | 0, /*tp_as_number*/ 162 | &PyHirschRectangle1_sequence_methods, /*tp_as_sequence*/ 163 | 0, /*tp_as_mapping*/ 164 | 0, /*tp_hash */ 165 | 0, /*tp_call*/ 166 | PyHirschRectangle1_str, /*tp_str*/ 167 | 0, /*tp_getattro*/ 168 | 0, /*tp_setattro*/ 169 | 0, /*tp_as_buffer*/ 170 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER, /*tp_flags*/ 171 | "PyHirschRectangle1", /* tp_doc */ 172 | 0, /* tp_traverse */ 173 | 0, /* tp_clear */ 174 | 0, /* tp_richcompare */ 175 | 0, /* tp_weaklistoffset */ 176 | &PyHirschRectangle1_iter, /* tp_iter */ 177 | &PyHirschRectangle1_iternext, /* tp_iternext */ 178 | PyHirschRectangle1_methods, /* tp_methods */ 179 | 0, /* tp_members */ 180 | 0, /* tp_getset */ 181 | 0, /* tp_base */ 182 | 0, /* tp_dict */ 183 | 0, /* tp_descr_get */ 184 | 0, /* tp_descr_set */ 185 | 0, /* tp_dictoffset */ 186 | (initproc)PyHirschRectangle1_init, /* tp_init */ 187 | 0, /* tp_alloc */ 188 | PyHirschRectangle1_new, /* tp_new */ 189 | }; 190 | 191 | 192 | void PyHirschRectangle1AddToModule(PyObject *m) 193 | { 194 | Py_INCREF(&PyHirschRectangle1Type); 195 | if (PyType_Ready(&PyHirschRectangle1Type) < 0) 196 | return; 197 | PyModule_AddObject(m, "HRectangle1", (PyObject *)&PyHirschRectangle1Type); 198 | } 199 | 200 | -------------------------------------------------------------------------------- /src/pyhrectangle1.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRectangle1 2 | #ifndef HRECTANGLE1_H 3 | #define HRECTANGLE1_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschRectangle1_FromHRectangle1(Halcon::HRectangle1 Rectangle1); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HRectangle1 Rectangle1; 13 | int iter_pos; 14 | } PyHirschRectangle1; 15 | 16 | #define PyHirschRectangle1_Check(op) \ 17 | PyObject_TypeCheck(op, &PyHirschRectangle1Type) 18 | 19 | void PyHirschRectangle1AddToModule(PyObject *m); 20 | 21 | extern PyTypeObject PyHirschRectangle1Type; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/pyhrectangle2.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRectangle2 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschRectangle2_dealloc(PyHirschRectangle2* self) 7 | { 8 | self->Rectangle2.~HRectangle2(); 9 | Py_TYPE(self)->tp_free((PyObject*)self); 10 | } 11 | 12 | static int 13 | PyHirschRectangle2_init(PyHirschRectangle2 *self, PyObject *args, PyObject */*kwds*/) 14 | { 15 | double centerX,centerY,ra,rb,phi=0; 16 | PyHirschRectangle2 *rect; 17 | 18 | if (PyArg_ParseTuple(args,"(dd)dd|d",¢erX,¢erY,&ra,&rb,&phi)) 19 | self->Rectangle2 = Halcon::HRectangle2(Halcon::HPoint2D(centerX,centerY), 20 | ra,rb,phi); 21 | 22 | else if (PyArg_ParseTuple(args,"O",&rect) 23 | && PyHirschRectangle2_Check(rect) 24 | ) { 25 | self->Rectangle2 = Halcon::HRectangle2(rect->Rectangle2); 26 | } 27 | else 28 | // Empty rectangle 29 | self->Rectangle2 = Halcon::HRectangle2(); 30 | 31 | PyErr_Clear(); 32 | 33 | return 0; 34 | } 35 | 36 | #include "hrectangle2_autogen_methods_declarations.i" 37 | 38 | static PyMethodDef PyHirschRectangle2_methods[] = { 39 | #include "hrectangle2_autogen_methods_list.i" 40 | {NULL} /* Sentinel */ 41 | }; 42 | 43 | static PyObject * 44 | PyHirschRectangle2_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) 45 | { 46 | PyHirschRectangle2 *self; 47 | 48 | self = (PyHirschRectangle2 *)type->tp_alloc(type, 0); 49 | // Explicit call to constructor placement new 50 | new(&self->Rectangle2) Halcon::HPoint2D(); 51 | 52 | return (PyObject *)self; 53 | } 54 | 55 | PyObject *PyHirschRectangle2_FromHRectangle2(Halcon::HRectangle2 Rectangle2) 56 | { 57 | PyHirschRectangle2 *self = (PyHirschRectangle2*)PyHirschRectangle2_new(&PyHirschRectangle2Type, NULL, NULL); 58 | self->Rectangle2 = Rectangle2; 59 | return (PyObject*)self; 60 | } 61 | 62 | static PyObject * 63 | PyHirschRectangle2_str(PyObject *ob) 64 | { 65 | PyHirschRectangle2 *self = (PyHirschRectangle2 *)ob; 66 | Halcon::HPoint2D Center = self->Rectangle2.Center(); 67 | double ra = self->Rectangle2.Ra(); 68 | double rb = self->Rectangle2.Rb(); 69 | double phi = self->Rectangle2.Phi(); 70 | PyObject *Tuple = Py_BuildValue("Oddd", 71 | PyHirschPoint2D_FromHPoint2D(Center), 72 | ra,rb,phi); 73 | PyObject *Ret = PyObject_Str(Tuple); 74 | Py_DECREF(Tuple); 75 | 76 | return Ret; 77 | } 78 | 79 | 80 | PyTypeObject PyHirschRectangle2Type = { 81 | PyVarObject_HEAD_INIT(NULL, 0) 82 | "Hirsch.Rectangle2", /*tp_name*/ 83 | sizeof(PyHirschRectangle2), /*tp_basicsize*/ 84 | 0, /*tp_itemsize*/ 85 | (destructor)PyHirschRectangle2_dealloc, /*tp_dealloc*/ 86 | 0, /*tp_print*/ 87 | 0, /*tp_getattr*/ 88 | 0, /*tp_setattr*/ 89 | 0, /*tp_compare*/ 90 | PyHirschRectangle2_str, /*tp_str*/ 91 | 0, /*tp_as_number*/ 92 | 0, /*tp_as_sequence*/ 93 | 0, /*tp_as_mapping*/ 94 | 0, /*tp_hash */ 95 | 0, /*tp_call*/ 96 | PyHirschRectangle2_str, /*tp_str*/ 97 | 0, /*tp_getattro*/ 98 | 0, /*tp_setattro*/ 99 | 0, /*tp_as_buffer*/ 100 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 101 | "PyHirschRectangle2", /* tp_doc */ 102 | 0, /* tp_traverse */ 103 | 0, /* tp_clear */ 104 | 0, /* tp_richcompare */ 105 | 0, /* tp_weaklistoffset */ 106 | 0, /* tp_iter */ 107 | 0, /* tp_iternext */ 108 | PyHirschRectangle2_methods, /* tp_methods */ 109 | 0, /* tp_members */ 110 | 0, /* tp_getset */ 111 | 0, /* tp_base */ 112 | 0, /* tp_dict */ 113 | 0, /* tp_descr_get */ 114 | 0, /* tp_descr_set */ 115 | 0, /* tp_dictoffset */ 116 | (initproc)PyHirschRectangle2_init, /* tp_init */ 117 | 0, /* tp_alloc */ 118 | PyHirschRectangle2_new, /* tp_new */ 119 | }; 120 | 121 | 122 | void PyHirschRectangle2AddToModule(PyObject *m) 123 | { 124 | Py_INCREF(&PyHirschRectangle2Type); 125 | if (PyType_Ready(&PyHirschRectangle2Type) < 0) 126 | return; 127 | PyModule_AddObject(m, "HRectangle2", (PyObject *)&PyHirschRectangle2Type); 128 | } 129 | 130 | -------------------------------------------------------------------------------- /src/pyhrectangle2.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRectangle2 2 | #ifndef PYHRECTANGLE2_H 3 | #define HRECTANGLE2_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschRectangle2_FromHRectangle2(Halcon::HRectangle2 Rectangle2); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HRectangle2 Rectangle2; 13 | } PyHirschRectangle2; 14 | 15 | #define PyHirschRectangle2_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschRectangle2Type) 17 | 18 | void PyHirschRectangle2AddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschRectangle2Type; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhregion.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRegion 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschRegion_dealloc(PyHirschRegion* self) 7 | { 8 | if(self->Region) 9 | delete self->Region; 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschRegion_init(PyHirschRegion *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | PyObject *ob; 17 | 18 | if (PyArg_ParseTuple(args,"O",&ob)) { 19 | if (PyHirschRegion_Check(ob)) 20 | self->Region = new Halcon::HRegion(*(((PyHirschRegion*)ob)->Region)); 21 | else if (PyHirschRectangle1_Check(ob)) { 22 | // The following convoluted code is needed to avoid crashes. 23 | Halcon::HRectangle1* rect = &(((PyHirschRectangle1*)ob)->Rectangle1); 24 | Halcon::HPoint2D ul(rect->UpperLeft()); 25 | Halcon::HPoint2D lr(rect->LowerRight()); 26 | Halcon::HRectangle1 r1(ul,lr); 27 | 28 | // Halcon::HRectangle1 r1(rect->UpperLeft(),rect->LowerRight()); // This crashes! 29 | 30 | self->Region = new Halcon::HRegion(Halcon::HRectangle1(ul,lr)); 31 | } 32 | // Py_DECREF(ob); 33 | } 34 | else 35 | self->Region = new Halcon::HRegion(); 36 | 37 | PyErr_Clear(); 38 | 39 | return 0; 40 | } 41 | 42 | #include "hregion_autogen_methods_declarations.i" 43 | 44 | static PyMethodDef PyHirschRegion_methods[] = { 45 | #include "hregion_autogen_methods_list.i" 46 | {NULL} /* Sentinel */ 47 | }; 48 | 49 | PyObject *PyHirschRegion_FromHRegion(Halcon::HRegion Region) 50 | { 51 | PyHirschRegion *v = (PyHirschRegion*)PyObject_New(PyHirschRegion, &PyHirschRegionType); 52 | v->Region = new Halcon::HRegion(Region); 53 | return (PyObject*)v; 54 | } 55 | 56 | PyTypeObject PyHirschRegionType = { 57 | PyVarObject_HEAD_INIT(NULL, 0) 58 | "Hirsch.HRegion", /*tp_name*/ 59 | sizeof(PyHirschRegion), /*tp_basicsize*/ 60 | 0, /*tp_itemsize*/ 61 | (destructor)PyHirschRegion_dealloc, /*tp_dealloc*/ 62 | 0, /*tp_print*/ 63 | 0, /*tp_getattr*/ 64 | 0, /*tp_setattr*/ 65 | 0, /*tp_compare*/ 66 | 0, /*tp_repr*/ 67 | 0, /*tp_as_number*/ 68 | 0, /*tp_as_sequence*/ 69 | 0, /*tp_as_mapping*/ 70 | 0, /*tp_hash */ 71 | 0, /*tp_call*/ 72 | 0, /*tp_str*/ 73 | 0, /*tp_getattro*/ 74 | 0, /*tp_setattro*/ 75 | 0, /*tp_as_buffer*/ 76 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 77 | "PyHirschRegion", /* tp_doc */ 78 | 0, /* tp_traverse */ 79 | 0, /* tp_clear */ 80 | 0, /* tp_richcompare */ 81 | 0, /* tp_weaklistoffset */ 82 | 0, /* tp_iter */ 83 | 0, /* tp_iternext */ 84 | PyHirschRegion_methods, /* tp_methods */ 85 | 0, /* tp_members */ 86 | 0, /* tp_getset */ 87 | 0, /* tp_base */ 88 | 0, /* tp_dict */ 89 | 0, /* tp_descr_get */ 90 | 0, /* tp_descr_set */ 91 | 0, /* tp_dictoffset */ 92 | (initproc)PyHirschRegion_init, /* tp_init */ 93 | 0, /* tp_alloc */ 94 | PyType_GenericNew, /* tp_new */ 95 | }; 96 | 97 | 98 | void PyHirschRegionAddToModule(PyObject *m) 99 | { 100 | Py_INCREF(&PyHirschRegionType); 101 | if (PyType_Ready(&PyHirschRegionType) < 0) 102 | return; 103 | PyModule_AddObject(m, "HRegion", (PyObject *)&PyHirschRegionType); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/pyhregion.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRegion 2 | #ifndef HREGION_H 3 | #define HREGION_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschRegion_FromHRegion(Halcon::HRegion Region); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HRegion *Region; 13 | } PyHirschRegion; 14 | 15 | #define PyHirschRegion_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschRegionType) 17 | 18 | void PyHirschRegionAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschRegionType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhregionarray.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRegionArray 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschRegionArray_dealloc(PyHirschRegionArray* self) 7 | { 8 | if(self->RegionArray) 9 | delete self->RegionArray; 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschRegionArray_init(PyHirschRegionArray *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | // TBD - Use PyArg_ParseTupleAndKeywords() to do special initilaziation 17 | self->RegionArray = new Halcon::HRegionArray(); 18 | 19 | return 0; 20 | } 21 | 22 | #include "hregionarray_autogen_methods_declarations.i" 23 | 24 | static PyMethodDef PyHirschRegionArray_methods[] = { 25 | #include "hregionarray_autogen_methods_list.i" 26 | {NULL} /* Sentinel */ 27 | }; 28 | 29 | Py_ssize_t PyHirschRegionArray_Length(PyObject *o) 30 | { 31 | return ((PyHirschRegionArray*)o)->RegionArray->Num(); 32 | } 33 | 34 | PyObject * 35 | PyHirschRegionArray_GetItem(PyObject *self, Py_ssize_t i) 36 | { 37 | Halcon::HRegionArray *RegionArray = (((PyHirschRegionArray*)self)->RegionArray); 38 | return PyHirschRegion_FromHRegion((*RegionArray)[i]); 39 | } 40 | 41 | static PySequenceMethods PyHirschRegionArray_sequence_methods = { 42 | PyHirschRegionArray_Length, /* sq_length */ 43 | 0, /* sq_concat */ 44 | 0, /* sq_repeat */ 45 | PyHirschRegionArray_GetItem, /* sq_item */ 46 | }; 47 | 48 | 49 | PyObject* PyHirschRegionArray_iter(PyObject *self) 50 | { 51 | Py_INCREF(self); 52 | ((PyHirschRegionArray*)self)->iter_pos = 0; 53 | return self; 54 | } 55 | 56 | PyObject* PyHirschRegionArray_iternext(PyObject *self) 57 | { 58 | PyHirschRegionArray *p = (PyHirschRegionArray *)self; 59 | Halcon::HRegionArray *RegionArray = (p->RegionArray); 60 | 61 | if (p->iter_pos < RegionArray->Num()) { 62 | PyObject *ret = PyHirschRegion_FromHRegion((*RegionArray)[p->iter_pos]); 63 | p->iter_pos+=1; 64 | 65 | return ret; 66 | } 67 | else { 68 | /* Raising of standard StopIteration exception with empty value. */ 69 | PyErr_SetNone(PyExc_StopIteration); 70 | return NULL; 71 | } 72 | } 73 | 74 | PyObject *PyHirschRegionArray_FromHRegionArray(Halcon::HRegionArray RegionArray) 75 | { 76 | PyHirschRegionArray *v = (PyHirschRegionArray*)PyObject_New(PyHirschRegionArray, &PyHirschRegionArrayType); 77 | v->RegionArray = new Halcon::HRegionArray(RegionArray); 78 | return (PyObject*)v; 79 | } 80 | 81 | #if PY_MAJOR_VERSION >= 3 82 | #define Py_TPFLAGS_HAVE_ITER 0 83 | #endif 84 | 85 | PyTypeObject PyHirschRegionArrayType = { 86 | PyVarObject_HEAD_INIT(NULL, 0) 87 | "Hirsch.HRegionArray", /*tp_name*/ 88 | sizeof(PyHirschRegionArray), /*tp_basicsize*/ 89 | 0, /*tp_itemsize*/ 90 | (destructor)PyHirschRegionArray_dealloc, /*tp_dealloc*/ 91 | 0, /*tp_print*/ 92 | 0, /*tp_getattr*/ 93 | 0, /*tp_setattr*/ 94 | 0, /*tp_compare*/ 95 | 0, /*tp_repr*/ 96 | 0, /*tp_as_number*/ 97 | &PyHirschRegionArray_sequence_methods, /*tp_as_sequence*/ 98 | 0, /*tp_as_mapping*/ 99 | 0, /*tp_hash */ 100 | 0, /*tp_call*/ 101 | 0, /*tp_str*/ 102 | 0, /*tp_getattro*/ 103 | 0, /*tp_setattro*/ 104 | 0, /*tp_as_buffer*/ 105 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER, /*tp_flags*/ 106 | "PyHirschRegionArray", /* tp_doc */ 107 | 0, /* tp_traverse */ 108 | 0, /* tp_clear */ 109 | 0, /* tp_richcompare */ 110 | 0, /* tp_weaklistoffset */ 111 | &PyHirschRegionArray_iter, /* tp_iter */ 112 | &PyHirschRegionArray_iternext, /* tp_iternext */ 113 | PyHirschRegionArray_methods, /* tp_methods */ 114 | 0, /* tp_members */ 115 | 0, /* tp_getset */ 116 | 0, /* tp_base */ 117 | 0, /* tp_dict */ 118 | 0, /* tp_descr_get */ 119 | 0, /* tp_descr_set */ 120 | 0, /* tp_dictoffset */ 121 | (initproc)PyHirschRegionArray_init, /* tp_init */ 122 | 0, /* tp_alloc */ 123 | PyType_GenericNew, /* tp_new */ 124 | }; 125 | 126 | 127 | void PyHirschRegionArrayAddToModule(PyObject *m) 128 | { 129 | Py_INCREF(&PyHirschRegionArrayType); 130 | if (PyType_Ready(&PyHirschRegionArrayType) < 0) 131 | return; 132 | PyModule_AddObject(m, "HRegionArray", (PyObject *)&PyHirschRegionArrayType); 133 | } 134 | 135 | -------------------------------------------------------------------------------- /src/pyhregionarray.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HRegionArray 2 | #ifndef HREGIONARRAY_H 3 | #define HREGIONARRAY_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschRegionArray_FromHRegionArray(Halcon::HRegionArray RegionArray); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HRegionArray *RegionArray; 13 | int iter_pos; 14 | } PyHirschRegionArray; 15 | 16 | #define PyHirschRegionArray_Check(op) \ 17 | PyObject_TypeCheck(op, &PyHirschRegionArrayType) 18 | 19 | void PyHirschRegionArrayAddToModule(PyObject *m); 20 | 21 | extern PyTypeObject PyHirschRegionArrayType; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/pyhtemplate.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HTemplate 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschTemplate_dealloc(PyHirschTemplate* self) 7 | { 8 | if(self->Template) 9 | delete self->Template; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschTemplate_init(PyHirschTemplate *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | // TBD - Use PyArg_ParseTupleAndKeywords() to do special initilaziation 17 | self->Template=new Halcon::HTemplate; 18 | return 0; 19 | } 20 | 21 | #include "htemplate_autogen_methods_declarations.i" 22 | 23 | static PyMethodDef PyHirschTemplate_methods[] = { 24 | #include "htemplate_autogen_methods_list.i" 25 | {NULL} /* Sentinel */ 26 | }; 27 | 28 | PyObject *PyHirschTemplate_FromHTemplate(Halcon::HTemplate Template) 29 | { 30 | PyHirschTemplate *v = (PyHirschTemplate*)PyObject_New(PyHirschTemplate, &PyHirschTemplateType); 31 | v->Template = new Halcon::HTemplate(Template); 32 | return (PyObject*)v; 33 | } 34 | 35 | PyTypeObject PyHirschTemplateType = { 36 | PyVarObject_HEAD_INIT(NULL, 0) 37 | "Hirsch.HTemplate", /*tp_name*/ 38 | sizeof(PyHirschTemplate), /*tp_basicsize*/ 39 | 0, /*tp_itemsize*/ 40 | (destructor)PyHirschTemplate_dealloc, /*tp_dealloc*/ 41 | 0, /*tp_print*/ 42 | 0, /*tp_getattr*/ 43 | 0, /*tp_setattr*/ 44 | 0, /*tp_compare*/ 45 | 0, /*tp_repr*/ 46 | 0, /*tp_as_number*/ 47 | 0, /*tp_as_sequence*/ 48 | 0, /*tp_as_mapping*/ 49 | 0, /*tp_hash */ 50 | 0, /*tp_call*/ 51 | 0, /*tp_str*/ 52 | 0, /*tp_getattro*/ 53 | 0, /*tp_setattro*/ 54 | 0, /*tp_as_buffer*/ 55 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 | "PyHirschTemplate", /* tp_doc */ 57 | 0, /* tp_traverse */ 58 | 0, /* tp_clear */ 59 | 0, /* tp_richcompare */ 60 | 0, /* tp_weaklistoffset */ 61 | 0, /* tp_iter */ 62 | 0, /* tp_iternext */ 63 | PyHirschTemplate_methods, /* tp_methods */ 64 | 0, /* tp_members */ 65 | 0, /* tp_getset */ 66 | 0, /* tp_base */ 67 | 0, /* tp_dict */ 68 | 0, /* tp_descr_get */ 69 | 0, /* tp_descr_set */ 70 | 0, /* tp_dictoffset */ 71 | (initproc)PyHirschTemplate_init, /* tp_init */ 72 | 0, /* tp_alloc */ 73 | PyType_GenericNew, /* tp_new */ 74 | }; 75 | 76 | 77 | void PyHirschTemplateAddToModule(PyObject *m) 78 | { 79 | Py_INCREF(&PyHirschTemplateType); 80 | if (PyType_Ready(&PyHirschTemplateType) < 0) 81 | return; 82 | PyModule_AddObject(m, "HTemplate", (PyObject *)&PyHirschTemplateType); 83 | } 84 | -------------------------------------------------------------------------------- /src/pyhtemplate.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HTemplate 2 | #ifndef PYHTEMPLATE_H 3 | #define HTEMPLATE_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschTemplate_FromHTemplate(Halcon::HTemplate Template); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HTemplate *Template; 13 | } PyHirschTemplate; 14 | 15 | #define PyHirschTemplate_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschTemplateType) 17 | 18 | void PyHirschTemplateAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschTemplateType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhtuple.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HTuple 2 | 3 | #include "pyhirsch.h" 4 | 5 | PyObject * 6 | PyHirschTuple_GetItem(PyObject *o, Py_ssize_t i); 7 | 8 | static void 9 | PyHirschTuple_dealloc(PyHirschTuple* self) 10 | { 11 | if(self->Tuple) 12 | delete self->Tuple; 13 | PyObject_Del(self); 14 | } 15 | 16 | #if PY_MAJOR_VERSION >= 3 17 | #define PyInt_Check PyLong_Check 18 | #define PyInt_AsLong PyLong_AsLong 19 | #define PyInt_FromLong PyLong_FromLong 20 | #define PyString_Check PyUnicode_Check 21 | #define PyString_AsString PyUnicode_AsUTF8 22 | #define PyString_FromFormat PyUnicode_FromFormat 23 | #define PyString_FromString PyUnicode_FromString 24 | #define Py_TPFLAGS_HAVE_ITER 0 25 | #endif 26 | 27 | static int 28 | PyHirschTuple_init(PyHirschTuple *self, PyObject *args, PyObject */*kwds*/) 29 | { 30 | PyObject *v; 31 | bool error = false; 32 | self->Tuple = new Halcon::HTuple(); 33 | 34 | // Support for tuple scalars 35 | if (PyArg_ParseTuple(args,"O",&v)) { 36 | if (PyInt_Check(v)) 37 | self->Tuple->Append(PyInt_AsLong(v)); 38 | #if PY_MAJOR_VERSION == 2 39 | if (PyLong_Check(v)) 40 | self->Tuple->Append(PyLong_AsLong(v)); 41 | #endif 42 | else if (PyFloat_Check(v)) 43 | self->Tuple->Append(PyFloat_AsDouble(v)); 44 | else if (PyString_Check(v)) 45 | self->Tuple->Append(PyString_AsString(v)); 46 | else if (PySequence_Check(v)) { 47 | for (int i=0; iTuple->Append(PyInt_AsLong(el)); 52 | #if PY_MAJOR_VERSION == 2 53 | else if (PyLong_Check(el)) 54 | self->Tuple->Append(PyLong_AsLong(el)); 55 | #endif 56 | else if (PyFloat_Check(el)) 57 | self->Tuple->Append(PyFloat_AsDouble(el)); 58 | else if (PyString_Check(el)) 59 | self->Tuple->Append(PyString_AsString(el)); 60 | else { 61 | error = true; 62 | } 63 | 64 | Py_DECREF(el); 65 | if (error) { 66 | PyObject *ErrorMessage = PyString_FromFormat("Unsupported type of element %d in sequence when initializing PyHTuple!", i+1); 67 | PyErr_SetString(PyExc_RuntimeError, PyString_AsString(ErrorMessage)); 68 | Py_DECREF(ErrorMessage); 69 | break; 70 | } 71 | 72 | if (error) 73 | break; 74 | } 75 | } 76 | else 77 | error = true; 78 | 79 | // Check if there is an error and we have not yet set the error 80 | if (error && !PyErr_Occurred()) { 81 | PyObject *ErrorMessage = PyString_FromFormat("Unsupported type of element when initializing PyHTuple!"); 82 | PyErr_SetString(PyExc_RuntimeError, PyString_AsString(ErrorMessage)); 83 | Py_DECREF(ErrorMessage); 84 | } 85 | } 86 | 87 | if (error) 88 | return -1; 89 | 90 | PyErr_Clear(); 91 | 92 | return 0; 93 | } 94 | 95 | static PyObject * 96 | PyHirschTuple_str(PyObject *ob) 97 | { 98 | PyHirschTuple *self = (PyHirschTuple *)ob; 99 | PyObject *Tuple = PyTuple_New(self->Tuple->Num()); 100 | for (int i=0; iTuple->Num(); i++) 101 | PyTuple_SET_ITEM(Tuple, i, PyHirschTuple_GetItem(ob,i)); 102 | 103 | PyObject *Ret = PyObject_Str(Tuple); 104 | Py_DECREF(Tuple); 105 | 106 | return Ret; 107 | } 108 | 109 | 110 | #include "htuple_autogen_methods_declarations.i" 111 | 112 | static PyMethodDef PyHirschTuple_methods[] = { 113 | #include "htuple_autogen_methods_list.i" 114 | {NULL} /* Sentinel */ 115 | }; 116 | 117 | Py_ssize_t PyHirschTuple_Length(PyObject *o) 118 | { 119 | Halcon::HTuple *Tuple = (((PyHirschTuple*)o)->Tuple); 120 | return Tuple->Num(); // Return the length of the sequence 121 | } 122 | 123 | PyObject * 124 | PyObjectFromHCtrlVar(Halcon::HCtrlVal& Val) 125 | { 126 | PyObject *ret = NULL; 127 | 128 | switch (Val.ValType()) { 129 | case LONG_PAR: 130 | ret = PyInt_FromLong(long(Val.L())); 131 | break; 132 | case DOUBLE_PAR: 133 | ret = PyFloat_FromDouble(Val.D()); 134 | break; 135 | case STRING_PAR: 136 | ret = PyString_FromString(Val.S()); 137 | break; 138 | default: 139 | PyErr_SetString(PyExc_RuntimeError, "Unknown Halcon type!"); 140 | return NULL; 141 | } 142 | 143 | return ret; 144 | } 145 | 146 | PyObject * 147 | PyHirschTuple_GetItem(PyObject *o, Py_ssize_t i) 148 | { 149 | Halcon::HTuple *Tuple = (((PyHirschTuple*)o)->Tuple); 150 | Halcon::HCtrlVal& Val((*Tuple)[i]); 151 | return PyObjectFromHCtrlVar(Val); 152 | } 153 | 154 | static PySequenceMethods PyHirschTuple_sequence_methods = { 155 | PyHirschTuple_Length, /* sq_length */ 156 | 0, /* sq_concat */ 157 | 0, /* sq_repeat */ 158 | PyHirschTuple_GetItem, /* sq_item */ 159 | 0 160 | }; 161 | 162 | 163 | PyObject* PyHirschTuple_iter(PyObject *self) 164 | { 165 | Py_INCREF(self); 166 | ((PyHirschTuple*)self)->iter_pos = 0; 167 | return self; 168 | } 169 | 170 | PyObject* PyHirschTuple_iternext(PyObject *self) 171 | { 172 | PyHirschTuple *p = (PyHirschTuple *)self; 173 | Halcon::HTuple *Tuple = (p->Tuple); 174 | 175 | if (p->iter_pos < Tuple->Num()) { 176 | PyObject *ret = PyHirschTuple_GetItem(self,p->iter_pos); 177 | p->iter_pos+=1; 178 | return ret; 179 | } 180 | else { 181 | /* Raising of standard StopIteration exception with empty value. */ 182 | PyErr_SetNone(PyExc_StopIteration); 183 | return NULL; 184 | } 185 | } 186 | 187 | PyObject *PyHirschTuple_FromHTuple(Halcon::HTuple Tuple) 188 | { 189 | PyHirschTuple *v = (PyHirschTuple*)PyObject_New(PyHirschTuple, &PyHirschTupleType); 190 | v->Tuple = new Halcon::HTuple(Tuple); 191 | return (PyObject*)v; 192 | } 193 | 194 | PyTypeObject PyHirschTupleType = { 195 | PyVarObject_HEAD_INIT(NULL, 0) 196 | "Hirsch.Tuple", /*tp_name*/ 197 | sizeof(PyHirschTuple), /*tp_basicsize*/ 198 | 0, /*tp_itemsize*/ 199 | (destructor)PyHirschTuple_dealloc, /*tp_dealloc*/ 200 | 0, /*tp_print*/ 201 | 0, /*tp_getattr*/ 202 | 0, /*tp_setattr*/ 203 | 0, /*tp_compare*/ 204 | PyHirschTuple_str, /*tp_repr*/ 205 | 0, /*tp_as_number*/ 206 | &PyHirschTuple_sequence_methods, /*tp_as_sequence*/ 207 | 0, /*tp_as_mapping*/ 208 | 0, /*tp_hash */ 209 | 0, /*tp_call*/ 210 | PyHirschTuple_str, /*tp_str*/ 211 | 0, /*tp_getattro*/ 212 | 0, /*tp_setattro*/ 213 | 0, /*tp_as_buffer*/ 214 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER, /*tp_flags*/ 215 | "PyHirschTuple", /* tp_doc */ 216 | 0, /* tp_traverse */ 217 | 0, /* tp_clear */ 218 | 0, /* tp_richcompare */ 219 | 0, /* tp_weaklistoffset */ 220 | &PyHirschTuple_iter, /* tp_iter */ 221 | &PyHirschTuple_iternext, /* tp_iternext */ 222 | PyHirschTuple_methods, /* tp_methods */ 223 | 0, /* tp_members */ 224 | 0, /* tp_getset */ 225 | 0, /* tp_base */ 226 | 0, /* tp_dict */ 227 | 0, /* tp_descr_get */ 228 | 0, /* tp_descr_set */ 229 | 0, /* tp_dictoffset */ 230 | (initproc)PyHirschTuple_init, /* tp_init */ 231 | 0, /* tp_alloc */ 232 | PyType_GenericNew, /* tp_new */ 233 | }; 234 | 235 | 236 | void PyHirschTupleAddToModule(PyObject *m) 237 | { 238 | Py_INCREF(&PyHirschTupleType); 239 | if (PyType_Ready(&PyHirschTupleType) < 0) 240 | return; 241 | PyModule_AddObject(m, "HTuple", (PyObject *)&PyHirschTupleType); 242 | } 243 | -------------------------------------------------------------------------------- /src/pyhtuple.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HTuple 2 | #ifndef PYHTUPLE_H 3 | #define HTUPLE_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschTuple_FromHTuple(Halcon::HTuple Tuple); 9 | PyObject *PyObjectFromHCtrlVar(Halcon::HCtrlVal& Val); 10 | 11 | typedef struct { 12 | PyObject_HEAD; 13 | Halcon::HTuple *Tuple; 14 | int iter_pos; 15 | } PyHirschTuple; 16 | 17 | #define PyHirschTuple_Check(op) \ 18 | PyObject_TypeCheck(op, &PyHirschTupleType) 19 | 20 | void PyHirschTupleAddToModule(PyObject *m); 21 | 22 | extern PyTypeObject PyHirschTupleType; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/pyhtuple_util.cc: -------------------------------------------------------------------------------- 1 | #include "htuple_util.h" 2 | 3 | PyObject *HTupleToPyTuple(Halcon::HTuple Tuple, 4 | int /*TypeHint*/) 5 | { 6 | PyObject *ret = NULL; 7 | 8 | int Len = Tuple.Num(); 9 | ret = PyTuple_New(Len); 10 | 11 | // TBD - Optimize by only asking for element types if 12 | // the tuple type is mixed. 13 | #if 0 14 | int tupleType = TypeHint; 15 | if (TupleType == HTUPLE_TYPE_UNKNOWN) 16 | TupleType = Tuple.TupleType().L(); 17 | #endif 18 | 19 | PyObject *el; 20 | for (int i=0; i 6 | #include 7 | 8 | #define HTUPLE_TYPE_UNKNOWN = -1; 9 | 10 | PyObject *HTupleToPyTuple(Halcon::HTuple Tuple, 11 | int TypeHint = -1); 12 | 13 | #endif /* HTUPLE_UTIL */ 14 | -------------------------------------------------------------------------------- /src/pyhxld.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLD 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschXLD_dealloc(PyHirschXLD* self) 7 | { 8 | if(self->XLD) 9 | delete self->XLD; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschXLD_init(PyHirschXLD *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | // TBD - Use PyArg_ParseTupleAndKeywords() to do special initilaziation 17 | self->XLD=new Halcon::HXLD; 18 | return 0; 19 | } 20 | 21 | #include "hxld_autogen_methods_declarations.i" 22 | 23 | static PyMethodDef PyHirschXLD_methods[] = { 24 | #include "hxld_autogen_methods_list.i" 25 | {NULL} /* Sentinel */ 26 | }; 27 | 28 | PyObject *PyHirschXLD_FromHXLD(Halcon::HXLD XLD) 29 | { 30 | PyHirschXLD *v = (PyHirschXLD*)PyObject_New(PyHirschXLD, &PyHirschXLDType); 31 | v->XLD = new Halcon::HXLD(XLD); 32 | return (PyObject*)v; 33 | } 34 | 35 | PyTypeObject PyHirschXLDType = { 36 | PyVarObject_HEAD_INIT(NULL, 0) 37 | "Hirsch.HXLD", /*tp_name*/ 38 | sizeof(PyHirschXLD), /*tp_basicsize*/ 39 | 0, /*tp_itemsize*/ 40 | (destructor)PyHirschXLD_dealloc, /*tp_dealloc*/ 41 | 0, /*tp_print*/ 42 | 0, /*tp_getattr*/ 43 | 0, /*tp_setattr*/ 44 | 0, /*tp_compare*/ 45 | 0, /*tp_repr*/ 46 | 0, /*tp_as_number*/ 47 | 0, /*tp_as_sequence*/ 48 | 0, /*tp_as_mapping*/ 49 | 0, /*tp_hash */ 50 | 0, /*tp_call*/ 51 | 0, /*tp_str*/ 52 | 0, /*tp_getattro*/ 53 | 0, /*tp_setattro*/ 54 | 0, /*tp_as_buffer*/ 55 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 | "PyHirschXLD", /* tp_doc */ 57 | 0, /* tp_traverse */ 58 | 0, /* tp_clear */ 59 | 0, /* tp_richcompare */ 60 | 0, /* tp_weaklistoffset */ 61 | 0, /* tp_iter */ 62 | 0, /* tp_iternext */ 63 | PyHirschXLD_methods, /* tp_methods */ 64 | 0, /* tp_members */ 65 | 0, /* tp_getset */ 66 | 0, /* tp_base */ 67 | 0, /* tp_dict */ 68 | 0, /* tp_descr_get */ 69 | 0, /* tp_descr_set */ 70 | 0, /* tp_dictoffset */ 71 | (initproc)PyHirschXLD_init, /* tp_init */ 72 | 0, /* tp_alloc */ 73 | PyType_GenericNew, /* tp_new */ 74 | }; 75 | 76 | 77 | void PyHirschXLDAddToModule(PyObject *m) 78 | { 79 | Py_INCREF(&PyHirschXLDType); 80 | if (PyType_Ready(&PyHirschXLDType) < 0) 81 | return; 82 | PyModule_AddObject(m, "HXLD", (PyObject *)&PyHirschXLDType); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/pyhxld.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLD 2 | #ifndef PYHXLD_H 3 | #define HXLD_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschXLD_FromHXLD(Halcon::HXLD XLD); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HXLD *XLD; 13 | } PyHirschXLD; 14 | 15 | #define PyHirschXLD_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschXLDType) 17 | 18 | void PyHirschXLDAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschXLDType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhxldarray.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLDArray 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschXLDArray_dealloc(PyHirschXLDArray* self) 7 | { 8 | if(self->XLDArray) 9 | delete self->XLDArray; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschXLDArray_init(PyHirschXLDArray *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | // TBD - Use PyArg_ParseTupleAndKeywords() to do special initilaziation 17 | self->XLDArray=new Halcon::HXLDArray; 18 | return 0; 19 | } 20 | 21 | #include "hxldarray_autogen_methods_declarations.i" 22 | 23 | static PyMethodDef PyHirschXLDArray_methods[] = { 24 | #include "hxldarray_autogen_methods_list.i" 25 | {NULL} /* Sentinel */ 26 | }; 27 | 28 | PyObject *PyHirschXLDArray_FromHXLDArray(Halcon::HXLDArray XLDArray) 29 | { 30 | PyHirschXLDArray *v = (PyHirschXLDArray*)PyObject_New(PyHirschXLDArray, &PyHirschXLDArrayType); 31 | v->XLDArray = new Halcon::HXLDArray(XLDArray); 32 | return (PyObject*)v; 33 | } 34 | 35 | PyTypeObject PyHirschXLDArrayType = { 36 | PyVarObject_HEAD_INIT(NULL, 0) 37 | "Hirsch.HXLDArray", /*tp_name*/ 38 | sizeof(PyHirschXLDArray), /*tp_basicsize*/ 39 | 0, /*tp_itemsize*/ 40 | (destructor)PyHirschXLDArray_dealloc, /*tp_dealloc*/ 41 | 0, /*tp_print*/ 42 | 0, /*tp_getattr*/ 43 | 0, /*tp_setattr*/ 44 | 0, /*tp_compare*/ 45 | 0, /*tp_repr*/ 46 | 0, /*tp_as_number*/ 47 | 0, /*tp_as_sequence*/ 48 | 0, /*tp_as_mapping*/ 49 | 0, /*tp_hash */ 50 | 0, /*tp_call*/ 51 | 0, /*tp_str*/ 52 | 0, /*tp_getattro*/ 53 | 0, /*tp_setattro*/ 54 | 0, /*tp_as_buffer*/ 55 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 | "PyHirschXLDArray", /* tp_doc */ 57 | 0, /* tp_traverse */ 58 | 0, /* tp_clear */ 59 | 0, /* tp_richcompare */ 60 | 0, /* tp_weaklistoffset */ 61 | 0, /* tp_iter */ 62 | 0, /* tp_iternext */ 63 | PyHirschXLDArray_methods, /* tp_methods */ 64 | 0, /* tp_members */ 65 | 0, /* tp_getset */ 66 | 0, /* tp_base */ 67 | 0, /* tp_dict */ 68 | 0, /* tp_descr_get */ 69 | 0, /* tp_descr_set */ 70 | 0, /* tp_dictoffset */ 71 | (initproc)PyHirschXLDArray_init, /* tp_init */ 72 | 0, /* tp_alloc */ 73 | PyType_GenericNew, /* tp_new */ 74 | }; 75 | 76 | 77 | void PyHirschXLDArrayAddToModule(PyObject *m) 78 | { 79 | Py_INCREF(&PyHirschXLDArrayType); 80 | if (PyType_Ready(&PyHirschXLDArrayType) < 0) 81 | return; 82 | PyModule_AddObject(m, "HXLDArray", (PyObject *)&PyHirschXLDArrayType); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/pyhxldarray.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLDArray 2 | #ifndef PYHXLDARRAY_H 3 | #define HXLDARRAY_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschXLDArray_FromHXLDArray(Halcon::HXLDArray XLDArray); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HXLDArray *XLDArray; 13 | } PyHirschXLDArray; 14 | 15 | #define PyHirschXLDArray_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschXLDArrayType) 17 | 18 | void PyHirschXLDArrayAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschXLDArrayType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhxldcont.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLDCont 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschXLDCont_dealloc(PyHirschXLDCont* self) 7 | { 8 | if(self->XLDCont) 9 | delete self->XLDCont; 10 | Py_TYPE(self)->tp_free((PyObject*)self); 11 | } 12 | 13 | static int 14 | PyHirschXLDCont_init(PyHirschXLDCont *self, PyObject */*args*/, PyObject */*kwds*/) 15 | { 16 | self->XLDCont = new Halcon::HXLDCont(); 17 | 18 | return 0; 19 | } 20 | 21 | #include "hxldcont_autogen_methods_declarations.i" 22 | 23 | static PyMethodDef PyHirschXLDCont_methods[] = { 24 | #include "hxldcont_autogen_methods_list.i" 25 | {NULL} /* Sentinel */ 26 | }; 27 | 28 | PyObject *PyHirschXLDCont_FromHXLDCont(Halcon::HXLDCont XLDCont) 29 | { 30 | PyHirschXLDCont *v = (PyHirschXLDCont*)PyObject_New(PyHirschXLDCont, &PyHirschXLDContType); 31 | v->XLDCont = new Halcon::HXLDCont(XLDCont); 32 | return (PyObject*)v; 33 | } 34 | 35 | PyTypeObject PyHirschXLDContType = { 36 | PyVarObject_HEAD_INIT(NULL, 0) 37 | "Halcon.hxldcont", /*tp_name*/ 38 | sizeof(PyHirschXLDCont), /*tp_basicsize*/ 39 | 0, /*tp_itemsize*/ 40 | (destructor)PyHirschXLDCont_dealloc, /*tp_dealloc*/ 41 | 0, /*tp_print*/ 42 | 0, /*tp_getattr*/ 43 | 0, /*tp_setattr*/ 44 | 0, /*tp_compare*/ 45 | 0, /*tp_repr*/ 46 | 0, /*tp_as_number*/ 47 | 0, /*tp_as_sequence*/ 48 | 0, /*tp_as_mapping*/ 49 | 0, /*tp_hash */ 50 | 0, /*tp_call*/ 51 | 0, /*tp_str*/ 52 | 0, /*tp_getattro*/ 53 | 0, /*tp_setattro*/ 54 | 0, /*tp_as_buffer*/ 55 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 | "PyHirschXLDCont", /* tp_doc */ 57 | 0, /* tp_traverse */ 58 | 0, /* tp_clear */ 59 | 0, /* tp_richcompare */ 60 | 0, /* tp_weaklistoffset */ 61 | 0, /* tp_iter */ 62 | 0, /* tp_iternext */ 63 | PyHirschXLDCont_methods, /* tp_methods */ 64 | 0, /* tp_members */ 65 | 0, /* tp_getset */ 66 | 0, /* tp_base */ 67 | 0, /* tp_dict */ 68 | 0, /* tp_descr_get */ 69 | 0, /* tp_descr_set */ 70 | 0, /* tp_dictoffset */ 71 | (initproc)PyHirschXLDCont_init, /* tp_init */ 72 | 0, /* tp_alloc */ 73 | PyType_GenericNew, /* tp_new */ 74 | }; 75 | 76 | 77 | void PyHirschXLDContAddToModule(PyObject *m) 78 | { 79 | Py_INCREF(&PyHirschXLDContType); 80 | if (PyType_Ready(&PyHirschXLDContType) < 0) 81 | return; 82 | PyModule_AddObject(m, "HXLDCont", (PyObject *)&PyHirschXLDContType); 83 | } 84 | -------------------------------------------------------------------------------- /src/pyhxldcont.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLDCont 2 | #ifndef HXLDCONT_H 3 | #define HXLDCONT_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschXLDCont_FromHXLDCont(Halcon::HXLDCont XLDCont); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HXLDCont *XLDCont; 13 | } PyHirschXLDCont; 14 | 15 | #define PyHirschXLDCont_Check(op) \ 16 | PyObject_TypeCheck(op, &PyHirschXLDContType) 17 | 18 | void PyHirschXLDContAddToModule(PyObject *m); 19 | 20 | extern PyTypeObject PyHirschXLDContType; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/pyhxldcontarray.cc: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLDContArray 2 | 3 | #include "pyhirsch.h" 4 | 5 | static void 6 | PyHirschXLDContArray_dealloc(PyHirschXLDContArray* self) 7 | { 8 | if(self->XLDContArray) 9 | delete self->XLDContArray; 10 | PyObject_Del(self); 11 | } 12 | 13 | static int 14 | PyHirschXLDContArray_init(PyHirschXLDContArray *self, PyObject *args, PyObject */*kwds*/) 15 | { 16 | PyObject *obj; 17 | 18 | if (PyArg_ParseTuple(args,"O",&obj)) { 19 | if (PyHirschXLDArray_Check(obj)) 20 | self->XLDContArray = new Halcon::HXLDContArray(*(((PyHirschXLDArray*)obj)->XLDArray)); 21 | else if (PyHirschXLDContArray_Check(obj)) 22 | self->XLDContArray = new Halcon::HXLDContArray(*(((PyHirschXLDContArray*)obj)->XLDContArray)); 23 | } 24 | else 25 | // Create an empty cont array by default. 26 | self->XLDContArray = new Halcon::HXLDContArray(); 27 | 28 | return 0; 29 | } 30 | 31 | #include "hxldcontarray_autogen_methods_declarations.i" 32 | 33 | static PyMethodDef PyHirschXLDContArray_methods[] = { 34 | #include "hxldcontarray_autogen_methods_list.i" 35 | {NULL} /* Sentinel */ 36 | }; 37 | 38 | Py_ssize_t PyHirschXLDContArray_Length(PyObject *o) 39 | { 40 | return ((PyHirschXLDContArray*)o)->XLDContArray->Num(); 41 | } 42 | 43 | PyObject * 44 | PyHirschXLDContArray_GetItem(PyObject *self, Py_ssize_t i) 45 | { 46 | Halcon::HXLDContArray *XLDContArray = (((PyHirschXLDContArray*)self)->XLDContArray); 47 | Halcon::HXLDCont XLDCont((*XLDContArray)[i]); 48 | 49 | return PyHirschXLDCont_FromHXLDCont(XLDCont); 50 | } 51 | 52 | static PySequenceMethods PyHirschXLDContArray_sequence_methods = { 53 | PyHirschXLDContArray_Length, /* sq_length */ 54 | 0, /* sq_concat */ 55 | 0, /* sq_repeat */ 56 | PyHirschXLDContArray_GetItem, /* sq_item */ 57 | }; 58 | 59 | 60 | PyObject* PyHirschXLDContArray_iter(PyObject *self) 61 | { 62 | Py_INCREF(self); 63 | ((PyHirschXLDContArray*)self)->iter_pos = 0; 64 | return self; 65 | } 66 | 67 | PyObject* PyHirschXLDContArray_iternext(PyObject *self) 68 | { 69 | PyHirschXLDContArray *p = (PyHirschXLDContArray *)self; 70 | Halcon::HXLDContArray *XLDContArray = (p->XLDContArray); 71 | 72 | if (p->iter_pos < XLDContArray->Num()) { 73 | PyObject *ret = PyHirschXLDCont_FromHXLDCont((*XLDContArray)[p->iter_pos]); 74 | p->iter_pos+=1; 75 | 76 | return ret; 77 | } 78 | else { 79 | /* Raising of standard StopIteration exception with empty value. */ 80 | PyErr_SetNone(PyExc_StopIteration); 81 | return NULL; 82 | } 83 | } 84 | 85 | PyObject *PyHirschXLDContArray_FromHXLDContArray(Halcon::HXLDContArray XLDContArray) 86 | { 87 | PyHirschXLDContArray *v = (PyHirschXLDContArray*)PyObject_New(PyHirschXLDContArray, &PyHirschXLDContArrayType); 88 | v->XLDContArray = new Halcon::HXLDContArray(XLDContArray); 89 | 90 | return (PyObject*)v; 91 | } 92 | 93 | #if PY_MAJOR_VERSION >= 3 94 | #define Py_TPFLAGS_HAVE_ITER 0 95 | #endif 96 | 97 | PyTypeObject PyHirschXLDContArrayType = { 98 | PyVarObject_HEAD_INIT(NULL, 0) 99 | "Hirsch.HXLDContArray", /*tp_name*/ 100 | sizeof(PyHirschXLDContArray), /*tp_basicsize*/ 101 | 0, /*tp_itemsize*/ 102 | (destructor)PyHirschXLDContArray_dealloc, /*tp_dealloc*/ 103 | 0, /*tp_print*/ 104 | 0, /*tp_getattr*/ 105 | 0, /*tp_setattr*/ 106 | 0, /*tp_compare*/ 107 | 0, /*tp_repr*/ 108 | 0, /*tp_as_number*/ 109 | &PyHirschXLDContArray_sequence_methods, /*tp_as_sequence*/ 110 | 0, /*tp_as_mapping*/ 111 | 0, /*tp_hash */ 112 | 0, /*tp_call*/ 113 | 0, /*tp_str*/ 114 | 0, /*tp_getattro*/ 115 | 0, /*tp_setattro*/ 116 | 0, /*tp_as_buffer*/ 117 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER, /*tp_flags*/ 118 | "PyHirschXLDContArray", /* tp_doc */ 119 | 0, /* tp_traverse */ 120 | 0, /* tp_clear */ 121 | 0, /* tp_richcompare */ 122 | 0, /* tp_weaklistoffset */ 123 | &PyHirschXLDContArray_iter, /* tp_iter */ 124 | &PyHirschXLDContArray_iternext, /* tp_iternext */ 125 | PyHirschXLDContArray_methods, /* tp_methods */ 126 | 0, /* tp_members */ 127 | 0, /* tp_getset */ 128 | 0, /* tp_base */ 129 | 0, /* tp_dict */ 130 | 0, /* tp_descr_get */ 131 | 0, /* tp_descr_set */ 132 | 0, /* tp_dictoffset */ 133 | (initproc)PyHirschXLDContArray_init, /* tp_init */ 134 | 0, /* tp_alloc */ 135 | PyType_GenericNew, /* tp_new */ 136 | }; 137 | 138 | 139 | void PyHirschXLDContArrayAddToModule(PyObject *m) 140 | { 141 | Py_INCREF(&PyHirschXLDContArrayType); 142 | if (PyType_Ready(&PyHirschXLDContArrayType) < 0) 143 | return; 144 | PyModule_AddObject(m, "HXLDContArray", (PyObject *)&PyHirschXLDContArrayType); 145 | } 146 | -------------------------------------------------------------------------------- /src/pyhxldcontarray.h: -------------------------------------------------------------------------------- 1 | // Autogenerated file for halcon type HXLDContArray 2 | #ifndef HXLDCONTARRAY_H 3 | #define HXLDCONTARRAY_H 4 | 5 | #include 6 | #include 7 | 8 | PyObject *PyHirschXLDContArray_FromHXLDContArray(Halcon::HXLDContArray XLDContArray); 9 | 10 | typedef struct { 11 | PyObject_HEAD; 12 | Halcon::HXLDContArray *XLDContArray; 13 | int iter_pos; 14 | } PyHirschXLDContArray; 15 | 16 | #define PyHirschXLDContArray_Check(op) \ 17 | PyObject_TypeCheck(op, &PyHirschXLDContArrayType) 18 | 19 | void PyHirschXLDContArrayAddToModule(PyObject *m); 20 | 21 | extern PyTypeObject PyHirschXLDContArrayType; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /test_data/maja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/test_data/maja.png -------------------------------------------------------------------------------- /test_data/qrfoo.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/test_data/qrfoo.tif -------------------------------------------------------------------------------- /tests/code39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dov/hirsch/e9f8867866fb964f8158a6e7d4b3c95a7dd04280/tests/code39.png -------------------------------------------------------------------------------- /tests/test-barcode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Test code39 detection 4 | 5 | import sys 6 | 7 | sys.path = ['./build/lib.linux-x86_64-2.7/'] + sys.path 8 | import hirsch as halcon 9 | 10 | BarCode = halcon.HBarCode() 11 | empty = halcon.HTuple() 12 | BarCode.CreateBarCodeModel(empty, empty); 13 | BarCode.SetBarCodeParam(halcon.HTuple("check_char"), halcon.HTuple("absent")) 14 | BarCode.SetBarCodeParam("element_size_max", 1000); 15 | 16 | Image = halcon.HImage.ReadImage('code39.png') 17 | 18 | Regions,DecodedStrings = BarCode.FindBarCode(Image,"Code 39"); 19 | print DecodedStrings 20 | 21 | -------------------------------------------------------------------------------- /tests/test-with-numpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # An example of how to turn a numpy image into Halcon and vice versa. 4 | 5 | import numpy as np 6 | import hirsch as H 7 | 8 | def himg_to_string(im): 9 | """Turn a (small) binary image into a string representation""" 10 | chars = '.1' 11 | width, height = im.Width(), im.Height() 12 | return '\n'.join( 13 | [''.join([chars[im.GetGrayval(r,c)[0]>0] for c in range(width)]) 14 | for r in range(height)]) 15 | 16 | def slow_himg_to_array(im): 17 | """A pixel by pixel translation of an himage to a numpy array""" 18 | width, height = im.Width(), im.Height() 19 | htype = im.PixType() 20 | typeconv = {'byte': np.uint8 } 21 | if not htype in typeconv: 22 | raise Exception('Unsupported halcon type!') 23 | a = np.zeros((height, width), dtype=typeconv[htype]) 24 | for r in range(height): 25 | for c in range(width): 26 | a[(r,c)] = im.GetGrayval(r,c)[0] 27 | return a 28 | 29 | def slow_array_to_himg(a): 30 | """A pixel by pixel translation of an np array to an himage""" 31 | height, width = a.shape 32 | nptype = a.dtype 33 | typeconv = {np.dtype('uint8') : 'byte'} 34 | if not nptype in typeconv: 35 | raise Exception('Unsupported np type for halcon conversion!') 36 | img = H.HImage.GenImageConst('byte',width,height) 37 | for r in range(height): 38 | for c in range(width): 39 | img.SetGrayval(r,c,a[(r,c)]) 40 | return img 41 | 42 | def medium_speed_himg_to_array(img): 43 | a = np.fromiter(img, 44 | dtype=np.uint8, 45 | count=img.Width()*img.Height()) 46 | a.resize( img.Height(), img.Width()) 47 | return a 48 | 49 | # Create a small h-image 50 | w,h = 7,5 51 | img = H.HImage.GenImageConst('byte',w,h) 52 | for j in range(1,h-1): 53 | for i in range(1,w-1): 54 | img.SetGrayval(j,i,1) 55 | 56 | # Slow conversion as reference 57 | a = slow_himg_to_array(img) 58 | 59 | # Convert to np array using the __array_interface__ 60 | a1 = np.array(img) 61 | assert((a==a1).all()) 62 | 63 | # Convert back to an image using the support of the __array_interface__ 64 | # in the HImage construction. 65 | img1 = H.HImage(a) 66 | assert(himg_to_string(img)==himg_to_string(img1)) 67 | 68 | print "ok" 69 | --------------------------------------------------------------------------------