MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / Mat

Class Mat

resources/oidscripts/oidtypes/opencv.py:23–81  ·  view source on GitHub ↗

Implementation for inspecting OpenCV Mat classes

Source from the content-addressed store, hash-verified

21
22
23class Mat(interface.TypeInspectorInterface):
24 """
25 Implementation for inspecting OpenCV Mat classes
26 """
27 def get_buffer_metadata(self, obj_name, picked_obj, debugger_bridge):
28 buffer = debugger_bridge.get_casted_pointer('char', picked_obj['data'])
29
30 width = int(picked_obj['cols'])
31 height = int(picked_obj['rows'])
32 flags = int(picked_obj['flags'])
33
34 channels = ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
35 row_stride = int(int(picked_obj['step']['buf'][0])/channels)
36
37 if channels >= 3:
38 pixel_layout = 'bgra'
39 else:
40 pixel_layout = 'rgba'
41
42 cvtype = ((flags) & CV_MAT_TYPE_MASK)
43
44 type_value = (cvtype & 7)
45
46 if (type_value == symbols.OID_TYPES_UINT16 or
47 type_value == symbols.OID_TYPES_INT16):
48 row_stride = int(row_stride / 2)
49 elif (type_value == symbols.OID_TYPES_INT32 or
50 type_value == symbols.OID_TYPES_FLOAT32):
51 row_stride = int(row_stride / 4)
52 elif type_value == symbols.OID_TYPES_FLOAT64:
53 row_stride = int(row_stride / 8)
54
55 return {
56 'display_name': f'{obj_name} ({picked_obj.type})',
57 'pointer': buffer,
58 'width': width,
59 'height': height,
60 'channels': channels,
61 'type': type_value,
62 'row_stride': row_stride,
63 'pixel_layout': pixel_layout,
64 'transpose_buffer' : False
65 }
66
67 def is_symbol_observable(self, symbol, symbol_name):
68 """
69 Returns true if the given symbol is of observable type (the type of the
70 buffer you are working with). Make sure to check for pointers of your
71 type as well
72 """
73 # Check if symbol type is the expected buffer
74 symbol_type = str(symbol.type)
75 type_regex = (
76 r'^(?:const\s+)?cv::Mat_?'
77 r'(?:<[^>]{1,32}>)?'
78 r'(?:\s*[*&])?$'
79 )
80

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected