Welcome to JetCobot repository
1.Camera driver
Camera driver
1. Experimental purpose
This course mainly uses the camera on the motherboard 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
ls /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 the 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 image from the camera. If the reading is successful, ret=True; if the reading fails, ret=False. Frame represents the image currently read.
The FPS is calculated and the image is displayed 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 the camera, please release it 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, it will automatically stop and call the camera release procedure.

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