Welcome to DOFBOT Pro repository
1. Camera display
Camera Display
For Orin motherboard users, simply open a web browser and enter the IP address:8888 to access jupyter-lab and run directly. For Jetson-Nano motherboard users, you need to first enter the docker container, then enter the following command in docker:
cdjupyter-lab --allow-root
Then open a web browser and enter IP address:9999 to access jupyter-lab and run the following program.
1. Camera Reading
capture=cv.VideoCapture(0)
Parameter meaning:
The parameter 0 in VideoCapture() indicates opening the USB camera.
If you need to check the camera device number, please enter the following command:
xxxxxxxxxxls /dev/video*
2. Display Camera Video
ret,img = frame.read()
Return value meaning:
ret: ret is a boolean value that determines whether a correct frame was read back
img: The image data of each frame
3. Code and Actual Effect Display
Program path:
xxxxxxxxxx#Jetson-Nano users need to enter the docker container to view~/dofbot_pro/dofbot_basic_visual/scripts/01.Camera_Demo.ipynb
Main code:
xxxxxxxxxximport cv2import ipywidgets.widgets as widgetsimport timefrom dofbot_utils.fps import FPS #Camera display componentxxxxxxxxxx#bgr8 to jpeg formatdef bgr8_to_jpeg(value, quality=75): return bytes(cv2.imencode('.jpg', value)[1])x#Set up camera display componentsimage_widget = widgets.Image(format='jpeg', width=600, height=500) fps = FPS()cap = cv2.VideoCapture(0) width=640height=480cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)print("Camera state:", cap.isOpened())xxxxxxxxxx# Display camera assemblydisplay(image_widget)try:while cap.isOpened():ret, frame = cap.read()fps.update_fps()fps.show_fps(frame)image_widget.value = bgr8_to_jpeg(frame)time.sleep(0.01)except KeyboardInterrupt:print(" Program closed! ")pass
xxxxxxxxxx#release#Releasecap.release()
Click "Run All Code Blocks" on the toolbar, scroll to the bottom, and you should be able to see the images captured by the USB camera.


If you need to stop the program, please click the stop button on the toolbar.
