def vxReleaseContext_int(context): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateImage: cannot verify context') raise AttributeError for grph in context['VX_GRAPH']: graph.vxReleaseGraph(grph) for img in context['VX_IMAGE']: image.vxReleaseImage(img) for pyrd in context['VX_PYRAMID']: pyramid.vxReleasePyramid(pyrd) for thresh in context['VX_THRESHOLD']: threshold.vxReleaseThreshold_int(thresh) for distribution in context['VX_DISTRIBUTION']: histogram.vxReleaseDistribution_int(distribution) for sclr in context['VX_SCALAR']: scalar.vxReleaseScalar(sclr) for arr in context['VX_ARRAY']: array.vxReleaseArray(arr) context['VX_GRAPH'] = [] context['VX_IMAGE'] = [] context['VX_PYRAMID'] = [] context['VX_THRESHOLD'] = [] context['VX_DISTRIBUTION'] = [] context['VX_SCALAR'] = [] context['VX_ARRAY'] = [] context['VX_VIRT'] = [] context['VX_RECT'] = [] context['VX_DATA'] = None
def vxCreateThreshold_int(context, thresholdType, dataType): logger = logging.getLogger(__name__) ret0 = defn.verifyContext(context) ret1 = isinstance(thresholdType, numbers.Number) ret2 = isinstance(dataType, numbers.Number) if ((ret0 != True) or (ret1 != True) or (ret2 != True)): logger.error('vxCreateThreshold: one or all parameters are wrong') raise Exception thresh = defn.create_dict(defn.VX_THRESHOLD,context) thresh['VX_DATA'] = Threshold(thresholdType, dataType) context['VX_THRESHOLD'].append(thresh) return thresh
def vxCreateScalar_int(context, data_type, initial_value): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateScalar: context cannot be verified') raise AttributeError if (isinstance(initial_value,numbers.Number) == False): logger.error('vxCreateScalar: initial_value is not a number') raise TypeError sclr = defn.create_dict(defn.VX_SCALAR,context) sclr['VX_DATA'] = VXScalar(context['VX_DATA'],data_type,initial_value,len(context['VX_SCALAR'])) context['VX_SCALAR'].append(sclr) return sclr
def vxCreateGraph_int(context): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateGraph: verifyContext failed') return None grph = defn.create_dict(defn.VX_GRAPH, context) grph['VX_DATA'] = VXGraph() grph['VX_IMAGE'] = [] grph['VX_SCALAR'] = [] grph['VX_ARRAY'] = [] grph['VX_VIRT'] = [] context['VX_GRAPH'].append(grph) return grph
def vxCreateImage_int(context, width, height, type): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateImage: cannot verify context') raise AttributeError if ((isinstance(width, numbers.Number) == False) or (isinstance(height, numbers.Number) == False)): logger.error('vxCreateImage: width and height are not valid') raise TypeError img = defn.create_dict(defn.VX_IMAGE, context) img['VX_DATA'] = VXImage(context['VX_DATA'], width, height, type, None) context['VX_IMAGE'].append(img) return img
def vxCreateRectangle_int(context, start_x, start_y, end_x, end_y): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateRectangle: Context cannot be verified') raise AttributeError if ((isinstance(start_x, numbers.Number) == False) or (isinstance(start_y, numbers.Number) == False) or (isinstance(end_x, numbers.Number) == False) or (isinstance(end_y, numbers.Number) == False)): logger.error('vxCreateRectangle: rect values are not int') raise TypeError rect = defn.create_dict(defn.VX_RECT, context) rect['VX_DATA'] = VXRectangle(start_x, start_y, end_x, end_y) context['VX_RECT'].append(rect) return rect
def vxCreateDistribution_int(context, numBins, offset, range): logger = logging.getLogger('__name__') ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateDistribution: Cannot verify context') raise AttributeError if ((isinstance(numBins, numbers.Number) == False) or (isinstance(range, numbers.Number) == False) or (isinstance(offset, numbers.Number) == False)): logger.error('vxCreateDistribution: bins/offset/range not numbers') raise TypeError if numBins != 256: logger.error('vxCreateDistribution: numBins not in range') raise ValueError distribution = defn.create_dict(defn.VX_DISTRIBUTION, context) distribution['VX_DATA'] = VXDistribution(context, numBins, offset, range) context['VX_DISTRIBUTION'].append(distribution) return distribution
def vxCreateArray_int(context, item_type, capacity): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreateArray: Context cannot be verified') raise AttributeError if ((isinstance(item_type, numbers.Number) == False) or (isinstance(capacity, numbers.Number) == False)): logger.error('vxCreateArray: item type/capacity is not integer type') raise TypeError lArray = VXArray(context['VX_DATA'], item_type, capacity) if lArray.verify() is not True: logger.error('vxCreateArray: VXArray cannot be created') raise AttributeError arr = defn.create_dict(defn.VX_ARRAY, context) arr['VX_DATA'] = lArray context['VX_ARRAY'].append(arr) return arr
def vxCreatePyramid_int(context, levels, scale, width, height, type): logger = logging.getLogger(__name__) ret = defn.verifyContext(context) if ret is not True: logger.error('vxCreatePyramid: Context cannot be verified') raise AttributeError if ((isinstance(levels, numbers.Number) == False) or (isinstance(scale, numbers.Number) == False)): logger.error('vxCreatePyramid: levels/scale are not numbers') raise TypeError if ((isinstance(width, numbers.Number) == False) or (isinstance(height, numbers.Number) == False) or (isinstance(type, numbers.Number) == False)): logger.error('vxCreatePyramid: levels/scale are not numbers') raise TypeError pyrd = defn.create_dict(defn.VX_PYRAMID, context) pyrd['VX_DATA'] = VXPyramid(context['VX_DATA'], levels, scale, width, height, type) context['VX_PYRAMID'].append(pyrd) return pyrd
def vxGenerateConfig_int(context, directory, numcores, dump_header=False): logger = logging.getLogger(__name__) if (isinstance(numcores, numbers.Number) == False): logger.error('vxGenerateConfig: numcores is not an integer') raise TypeError if (isinstance(directory, basestring) == False): logger.error('vxGenerateConfig: directory is not a string') raise TypeError ret = defn.verifyContext(context) if ret is not True: logger.error('vxGenerateConfig: Contect cannot be verified') raise AttributeError if (numcores <= 0): logger.error('vxGenerateConfig: numcores is less than zero') raise ValueError if (numcores > 8): logger.error('vxGenerateConfig: numcores is greater than 8') raise ValueError prefix = context['VX_NAME'] #write binary file if not os.path.exists(directory): os.makedirs(directory) directory = directory + '/' print directory hash_md5 = hashlib.md5() for graph in context['VX_GRAPH']: for node in graph['VX_DATA'].node: msg = node['VX_DATA'].createMailBox(numcores) if msg is not None: for item in msg: hash_md5.update(item) uniqueID = int((hash_md5.hexdigest())[0:8], 16) + int( float(brcm_openvx.__version__) * 100) for graph in context['VX_GRAPH']: try: fp = open(directory + prefix + '_' + graph['VX_NAME'] + '.bin', 'wb') fp.write(struct.pack('>I', 0x56580006)) fp.write(struct.pack('I', uniqueID)) except: print 'vxGenerateConfig:Cannot open the bin file to write' raise EnvironmentError num_jobs = 0 for node in graph['VX_DATA'].node: num_jobs += node['VX_DATA'].getNumJobs() fp.write(struct.pack('I', num_jobs)) fp.write(struct.pack('I', numcores)) fp.write(struct.pack('I', graph['VX_DATA'].getTotalTempSize())) for node in graph['VX_DATA'].node: msg = node['VX_DATA'].createMailBox(numcores) if msg is not None: for item in msg: fp.write(item) for node in graph['VX_DATA'].node: tbl = node['VX_DATA'].getTableData() for item in tbl: fp.write(item) fp.close() if dump_header == True: try: ldr = open( directory + prefix + '_' + graph['VX_NAME'] + '.bin', 'rb') dump = open(directory + prefix + '_' + graph['VX_NAME'] + '.h', 'wb') dump.write(license_txt) dump.write( '\n/******************************************************************************\nFile Name : config.h\nDescription: This file contains config data\n ******************************************************************************/' ) dump.write('\n#ifndef GRAPH_' + graph['VX_NAME'] + '_H\n#define GRAPH_' + graph['VX_NAME'] + '_H\nstatic unsigned char graph_' + graph['VX_NAME'] + '[] = {\n') isContinue = True except: print 'vxGenerateConfig:Cannot open the bin file to write' raise EnvironmentError while isContinue == True: s = ldr.read(8) if len(s) == 0: isContinue = False for c in s: dump.write(" " + "0x{:02x}".format(ord(c)) + ",") dump.write('\n') dump.write('};\n') dump.write('#endif\n') dump.close() ldr.close() ## generate the config file try: fp = open(directory + prefix + '_' + 'internal.h', 'wb') #wrire header fp.write(license_txt) fp.write('\n#ifndef ' + prefix.upper() + '_INTERNAL_H\n#define ' + prefix.upper() + '_INTERNAL_H\n\n') fp.write('\n') fp.write('#include <openvx_lib.h>\n\n') fp.write('#define ' + prefix.upper() + '_UNIQUE_ID (' + str(uniqueID) + 'UL)\n\n') fp.write('#define ' + prefix.upper() + '_NUM_PP_CORES (' + str(numcores) + 'UL)\n\n') fp.write('#define ' + prefix.upper() + '_MAX_DATA_ENTRIES (' + str(context['VX_DATA'].getMaxDataEntries()) + 'UL)\n\n') except: print 'vxGenerateConfig:Cannot open the internal.h file to write' raise EnvironmentError tempSize = 0 for graph in context['VX_GRAPH']: graphTempSize = graph['VX_DATA'].getTotalTempSize() if tempSize < graphTempSize: tempSize = graphTempSize totalScalarsSize = len(context['VX_SCALAR']) * 8 fp.write('#define ' + prefix.upper() + '_TEMP_STORAGE_IDX' + ' (0UL)\n') fp.write('#define ' + prefix.upper() + '_TEMP_STORAGE_SIZE' + ' (' + str(tempSize + totalScalarsSize) + 'UL)\n') fp.write('\n') for image in context['VX_IMAGE']: (name, size, offset) = image['VX_DATA'].getStorageDetails() fp.write('#define ' + prefix.upper() + '_' + image['VX_NAME'].upper() + '_IMG_IDX' + ' (' + str(name) + 'UL)\n') fp.write('#define ' + prefix.upper() + '_' + image['VX_NAME'].upper() + '_IMG_SIZE' + ' (' + str(size) + 'UL)\n') fp.write('\n') fp.write('\n') for pyramid in context['VX_PYRAMID']: (name, size, offset) = pyramid['VX_DATA'].getStorageDetails() fp.write('#define ' + prefix.upper() + '_' + pyramid['VX_NAME'].upper() + '_PYRAMID_IDX' + ' (' + str(name) + 'UL)\n') fp.write('#define ' + prefix.upper() + '_' + pyramid['VX_NAME'].upper() + '_PYRAMID_SIZE' + ' (' + str(size) + 'UL)\n') fp.write('\n') fp.write('\n') for array in context['VX_ARRAY']: (name, size, offset) = array['VX_DATA'].getStorageDetails() fp.write('#define ' + prefix.upper() + '_' + array['VX_NAME'].upper() + '_ARRAY_IDX' + ' (' + str(name) + 'UL)\n') (type, maxCount) = array['VX_DATA'].getDataType() fp.write('typedef ' + type + ' ' + prefix.upper() + '_' + array['VX_NAME'].upper() + '_ARRAY_TYPE;\n') fp.write('#define ' + prefix.upper() + '_' + array['VX_NAME'].upper() + '_MAX_COUNT' + ' (' + str(maxCount) + 'UL)\n') fp.write('#define DEFINE_' + prefix.upper() + '_' + array['VX_NAME'].upper() + '(aName)\\\n') fp.write(' ' + type + ' aName[' + str(maxCount) + 'UL]') fp.write('\n\n') fp.write('\n') for scalar in context['VX_SCALAR']: (name, size, offset) = scalar['VX_DATA'].getStorageDetails() fp.write('#define ' + prefix.upper() + '_' + scalar['VX_NAME'].upper() + '_SCALAR_IDX' + ' (' + str(name) + 'UL)\n') #fp.write('#define '+prefix.upper()+'_'+scalar['VX_NAME'].upper()+'_SCALAR_SIZE'+' ('+str(size)+'UL)\n') type = scalar['VX_DATA'].getDataType() fp.write('typedef ' + type + ' ' + prefix.upper() + '_' + scalar['VX_NAME'].upper() + '_SCALAR_TYPE;') fp.write('\n') fp.write('\n') fp.write('#endif /* ' + prefix.upper() + '_INTERNAL_H */\n') fp.close()