How to debug opencv on Pi 4B?

The opencv sample crashes after capturing video for a few seconds. Is it a way to dig out what happens when using camera?

ubuntu@ubuntu:~/opencv_contrib-master/samples/python2$ python video.py 

Video capture sample.

Sample shows how VideoCapture class can be used to acquire video
frames from a camera of a movie file. Also the sample provides
an example of procedural video generation by an object, mimicking
the VideoCapture interface (see Chess class).

'create_capture' is a convinience function for capture creation,
falling back to procedural video in case of error.

Usage:
    video.py [--shotdir <shot path>] [source0] [source1] ...'

    sourceN is an
     - integer number for camera capture
     - name of video file
     - synth:<params> for procedural video

Synth examples:
    synth:bg=../cpp/lena.jpg:noise=0.1
    synth:class=chess:bg=../cpp/lena.jpg:noise=0.1:size=640x480

Keys:
    ESC    - exit
    SPACE  - save current frame to <shot path> directory



(python:2948): Gtk-WARNING **: 03:41:28.134: Unable to locate theme engine in module_path: "pixmap",

(python:2948): Gtk-WARNING **: 03:41:28.137: Unable to locate theme engine in module_path: "pixmap",

(python:2948): Gtk-WARNING **: 03:41:28.138: Unable to locate theme engine in module_path: "pixmap",

(python:2948): Gtk-WARNING **: 03:41:28.145: Unable to locate theme engine in module_path: "pixmap",

(python:2948): Gtk-WARNING **: 03:41:28.146: Unable to locate theme engine in module_path: "pixmap",
[ WARN:0] global /home/ubuntu/opencv-master/modules/videoio/src/cap_v4l.cpp (1001) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
Traceback (most recent call last):
  File "video.py", line 189, in <module>
    cv.imshow('capture %d' % i, img)
cv2.error: OpenCV(4.5.4-dev) /home/ubuntu/opencv-master/modules/core/src/array.cpp:2494: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

Another test from opencv sample:

ubuntu@ubuntu:~/opencv-master/samples/cpp$ ./example_cpp_videocapture_camera
Opening camera...
Frame width: 640
     height: 480
Capturing FPS: 30

Press 'ESC' to quit, 'space' to toggle frame processing

Start grabbing...

(example_cpp_videocapture_camera:14266): Gtk-WARNING **: 06:56:11.814: Unable to locate theme engine in module_path: "pixmap",

(example_cpp_videocapture_camera:14266): Gtk-WARNING **: 06:56:11.817: Unable to locate theme engine in module_path: "pixmap",

(example_cpp_videocapture_camera:14266): Gtk-WARNING **: 06:56:11.818: Unable to locate theme engine in module_path: "pixmap",

(example_cpp_videocapture_camera:14266): Gtk-WARNING **: 06:56:11.822: Unable to locate theme engine in module_path: "pixmap",

(example_cpp_videocapture_camera:14266): Gtk-WARNING **: 06:56:11.823: Unable to locate theme engine in module_path: "pixmap",
Frames captured:    10    Average FPS:       8.3    Average time per frame:    120.77 ms    Average processing time:      0.00 ms
Frames captured:    20    Average FPS:      19.1    Average time per frame:     52.26 ms    Average processing time:      0.00 ms
Frames captured:    30    Average FPS:      19.8    Average time per frame:     50.56 ms    Average processing time:      0.00 ms
ERROR: Can't grab camera frame.
Number of captured frames: 37
[ WARN:0] global /home/ubuntu/opencv-master/modules/videoio/src/cap_v4l.cpp (802) requestBuffers VIDEOIO(V4L2:/dev/video0): failed VIDIOC_REQBUFS: errno=19 (No such device)