Skip to content

Commit 757ea01

Browse files
Pull request #46: Bugfix/ensure pixel format is compatible for numpy access test
Merge in HSW_SDK/vmbpy from bugfix/ensure-pixel-format-is-compatible-for-numpy-access-test to dev * commit 'c0d50fd70f710493ec3b1840558ea33c0946f616': Reset pixelformat after test case execution Set pixel format to compatible value if possible
2 parents f54ae9d + c0d50fd commit 757ea01

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

Tests/real_cam_tests/frame_test.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,15 @@ def test_convert_to_all_given_formats(self):
181181
test_frames = []
182182

183183
with self.cam:
184+
initial_pixel_format = self.cam.get_pixel_format()
184185
for fmt in self.cam.get_pixel_formats():
185186
self.cam.set_pixel_format(fmt)
186187

187188
frame = self.cam.get_frame()
188189

189190
self.assertEqual(fmt, frame.get_pixel_format())
190191
test_frames.append(frame)
192+
self.cam.set_pixel_format(initial_pixel_format)
191193

192194
for frame in test_frames:
193195
original_fmt = frame.get_pixel_format()
@@ -223,8 +225,19 @@ def test_numpy_arrays_can_be_accessed_after_frame_is_garbage_collected(self):
223225
# PROCESS. THIS MEANS THAT THE TEST CASE WILL NOT REALLY REPORT A FAILURE, BUT SIMPLY EXIT
224226
# WITHOUT BEING MARKED AS PASSED. ALL SUBSEQUENT TEST CASES WILL ALSO NOT BE EXECUTED
225227
with self.cam:
228+
compatible_formats = intersect_pixel_formats(OPENCV_PIXEL_FORMATS,
229+
self.cam.get_pixel_formats())
230+
if not compatible_formats:
231+
self.skipTest(f'Camera does not support a compatible format. Available formats '
232+
f'from camera are: {self.cam.get_pixel_formats()}. Numpy compatible '
233+
f'formats are {OPENCV_PIXEL_FORMATS}')
234+
if self.cam.get_pixel_format() not in compatible_formats:
235+
self.cam.set_pixel_format(compatible_formats[0])
226236
frame = self.cam.get_frame()
227-
np_array = frame.as_numpy_ndarray()
237+
try:
238+
np_array = frame.as_numpy_ndarray()
239+
except ImportError:
240+
self.skipTest('Numpy is not imported')
228241
del frame
229242

230243
# Ensure that garbage collection has cleaned up the frame object

0 commit comments

Comments
 (0)