ubuntu外接摄像头,安装ros_noetic并用opencv打开摄像头,保存照片

  1. 安装环境

安装ros_noetic:http://wiki.ros.org/noetic/Installation/Ubuntu#Ubuntu_install_of_ROS_Noetic

安装usb接口环境:https://blog.csdn.net/Z_xiao_bai_/article/details/124064923?ops_request_mis

  1. python程序

参考:https://blog.csdn.net/qq_51967017/article/details/125038633?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167766866216800211517611%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=167766866216800211517611&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-4-125038633-null-null.142^v73^control_1,201^v4^add_ask,239^v2^insert_chatgpt&utm_term=opencv%E8%AF%86%E5%88%AB%E5%A4%96%E6%8E%A5%E6%91%84%E5%83%8F%E5%A4%B4&spm=1018.2226.3001.4187

配置环境:pip install opencv-python

# coding:utf-8
import cv2
cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
flag = cap.isOpened()
index = 1
cap.open(0)
while True:
    ret, frame = cap.read()
    cv2.imshow("Capture_Paizhao", frame)
    k = cv2.waitKey(1) & 0xFF
    if k == ord('s'):  # 按下s键,进入下面的保存图片操作
        cv2.imwrite("" + str(index) + ".jpg", frame)
        #cv2.imwrite("online_data" + str(index) + ".jpg", frame)
        print("save" + str(index) + ".jpg successfuly!")
        print("-------------------------")
        index += 1
    elif k == ord('q'):  # 按下q键,程序退出
        break
cap.release() # 释放摄像头
cv2.destroyAllWindows()# 释放并销毁窗口

你可能感兴趣的:(c++,python)