python3 checkScaledTensor.py testcase3.direct.log 640 480 testcase3.scaled.log 1280 960 3
testResult $? 3 "Golden test comparison" 0 1
+# Passthrough with CV (multithreaded)
+python3 cv2_availability.py
+CV2=$?
+IGNORE=0
+if [ "$CV2" == "0" ]; then
+ IGNORE=0
+else
+ IGNORE=1
+fi
+PATH_TO_SCRIPT="../test_models/models/passThrough_CV.py"
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=280,height=40,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_filter framework=\"${FRAMEWORK}\" model=\"${PATH_TO_SCRIPT}\" input=\"3:280:40:1\" inputtype=\"uint8\" output=\"3:280:40:1\" outputtype=\"uint8\" ! filesink location=\"testcase4.passthrough.log\" sync=true t. ! queue ! filesink location=\"testcase4.direct.log\" sync=true" 4-1 $IGNORE 0 $PERFORMANCE
+callCompareTest testcase4.direct.log testcase4.passthrough.log 4-2 "Multithreaded python script as a filter (CV2)" 0 $IGNORE
+
rm *.log
report
--- /dev/null
+#!/bin/env python3
+##
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# @file passThrough_CV.py
+# @brief A trivial python custom filter to test the usage of CV2 in python script, which tests multithreading in a script as well.
+# @author beto-gulliver @ github
+
+import numpy as np
+import nnstreamer_python as nns
+
+D1 = 3
+D2 = 280
+D3 = 40
+D4 = 1
+
+USE_CV2 = True # [NG] XXX: 'cv2' halts!!! --> github issue (threads' race condition/deadlock? release GIL? ???)
+#USE_CV2 = False # [OK]
+if USE_CV2 : import cv2
+
+class CustomFilter(object):
+ def __init__(self, *args):
+ self.input_dims = [nns.TensorShape([D1, D2, D3, D4], np.uint8)]
+ self.output_dims = [nns.TensorShape([D1, D2, D3, D4], np.uint8)]
+
+ def getInputDim(self):
+ return self.input_dims
+
+ def getOutputDim(self):
+ return self.output_dims
+
+ def invoke(self, input_array):
+ # passthrough, just return.
+ print(f"--- USE_CV2:{USE_CV2}", __file__, input_array[0].shape)
+ if USE_CV2 : cv2.imwrite("/tmp/x.png", np.zeros((240, 320, 3), dtype=np.uint8)) # [NG] XXX: 'cv2' halts!!! --> github issue (threads' race condition/deadlock? release GIL? ???)
+ return input_array
+
+# ----------------------------------------------------------------------
+def main():
+ import sys
+ cf = CustomFilter()
+ print(cf)
+ shape, dtype = [D1, D2, D3, D4], "uint8"
+ if 1 :
+ input_dims = [nns.TensorShape(shape, dtype)]
+# cf.setInputDim(input_dims) # callback
+ for idx in range(10) :
+ in_ = np.ones(shape).astype(np.uint8)
+ in_ = (np.random.random(shape) * 255).astype(np.uint8)
+ in_ = [np.ravel(in_)] # as buffer (memory)
+ print(idx, f"USE_CV2:{USE_CV2} in_ {in_}", __file__)
+ out = cf.invoke(in_)
+ print(idx, f"USE_CV2:{USE_CV2} out {out}", __file__)
+
+# voila!
+if __name__ == '__main__':
+ main()
+# ----------------------------------------------------------------------