fix check video type cv2.VideoCapture and add unittest

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/11181951
This commit is contained in:
wenmeng.zwm
2022-12-26 09:59:59 +08:00
parent 086f629fbc
commit a01e29ceb0
2 changed files with 4 additions and 6 deletions

View File

@@ -38,10 +38,10 @@ INPUT_TYPE = {
def check_input_type(input_type, input):
expected_type = INPUT_TYPE[input_type]
if expected_type == 'cv2.VideoCapture':
if input_type == InputType.VIDEO:
# special type checking using class name, to avoid introduction of opencv dependency into fundamental framework.
assert type(input).__name__ == 'VideoCapture',\
f'invalid input type for {input_type}, expected cv2.VideoCapture but got {type(input)}\n {input}'
assert type(input).__name__ == 'VideoCapture' or isinstance(input, expected_type),\
f'invalid input type for {input_type}, expected {expected_type} but got {type(input)}\n {input}'
else:
assert isinstance(input, expected_type), \
f'invalid input type for {input_type}, expected {expected_type} but got {type(input)}\n {input}'

View File

@@ -39,9 +39,7 @@ class Body3DKeypointsTest(unittest.TestCase, DemoCompatibilityCheck):
if not cap.isOpened():
raise Exception('modelscope error: %s cannot be decoded by OpenCV.'
% (self.test_video))
pipeline_input = self.test_video
self.pipeline_inference(
body_3d_keypoints, pipeline_input=pipeline_input)
self.pipeline_inference(body_3d_keypoints, pipeline_input=cap)
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_demo_compatibility(self):