Welcome to JetCobot repository
1. Camera driver
Camera driver
1 Experimental purpose
This course mainly uses the camera of the mainboard to obtain the camera image and display it on the jupyterlab control.
2 Experimental preparation
Check the device number of the USB camera, as shown in the figure below, and get the device number /dev/video0
xxxxxxxxxxls /dev/video*

3 Experimental process
Open the jupyterLab client and find the code path:
xxxxxxxxxxjetcobot_ws/src/jetcobot_ai_basic/scripts/1.Camera_Show.ipynb
Import the opencv library and jupyter lab display control.
xxxxxxxxxximport cv2import ipywidgets.widgets as widgets
Open the camera, the default configuration device is /dev/video0, the display resolution is 640*480, and the frame rate is 30 frames. If the device number of the camera in the system is not /dev/video0, please modify the configuration information according to the actual device number.
xxxxxxxxxximage_widget = widgets.Image(format='jpeg', width=640, height=480)image = cv2.VideoCapture(0)image.set(3, 640)image.set(4, 480)image.set(5, 30)
Read a frame of the camera image, ret=True if the read is successful, ret=False if the read fails, frame represents the current read image, and calculates the FPS, and displays the image on the control.
xwhile g_camera.isOpened():ret, frame = g_camera.read()if not ret:print("Camera Read Fail")breakm_fps = m_fps + 1fps = m_fps / (time.time() - t_start)if (time.time() - t_start) >= 2:m_fps = fpst_start = time.time() - 1text="FPS:" + str(int(fps))cv2.putText(frame, text, (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 1)image_widget.value = bgr8_to_jpeg(frame)

If you do not need to use it, please release the camera to avoid errors caused by other routines accessing the camera at the same time. Select the cell that displays the camera and click the stop button to automatically stop and call the camera release program.

xxxxxxxxxxg_camera.release()
4 Experimental summary
This time, JupyterLab controls are used to display the camera screen. If the default device /dev/video0 device number cannot be driven, please check the device number of the current system or re-plug the camera cable.