建设单位适合去哪个网站看资料,工商网站如何做企业增资,做常州美食网站首页的背景图,网站 代备案事情是这样的#xff0c;在拼多多花了40买了一个4k高清的摄像偷#xff0c;确实清楚。但是我一直以为网络摄像头分辨率只有640*480,于是用python测试了一下#xff0c;上代码
import cv2def get_max_resolution(camera_index):获取摄像头的最大分辨率。在拼多多花了40买了一个4k高清的摄像偷确实清楚。但是我一直以为网络摄像头分辨率只有640*480,于是用python测试了一下上代码
import cv2def get_max_resolution(camera_index):获取摄像头的最大分辨率。cap cv2.VideoCapture(camera_index)if not cap.isOpened():return None, Nonemax_width, max_height 0, 0# 定义常见分辨率列表resolutions [(640, 480),(1280, 720),(1920, 1080),(2560, 1440),(3840, 2160)]for width, height in resolutions:cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)actual_width int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))actual_height int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))if actual_width width and actual_height height:max_width, max_height actual_width, actual_heightcap.release()return max_width, max_heightdef find_all_cameras(max_index10):遍历所有可用的摄像头并输出最大分辨率。cameras []for camera_index in range(max_index):cap cv2.VideoCapture(camera_index)if cap.isOpened():cameras.append(camera_index)cap.release()print(f发现 {len(cameras)} 个摄像头)for camera in cameras:max_width, max_height get_max_resolution(camera)if max_width and max_height:print(f摄像头 {camera} 的最大分辨率为{max_width}x{max_height})else:print(f摄像头 {camera} 无法获取分辨率)def capture_image_with_maximized_window(camera_index, width, height):采集摄像头图像并以最大化窗口显示。cap cv2.VideoCapture(camera_index)if not cap.isOpened():print(f无法打开摄像头 {camera_index})return# 设置摄像头分辨率cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)actual_width int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))actual_height int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))print(f实际采集的图像分辨率: 宽度{actual_width}, 高度{actual_height})ret, frame cap.read()if ret:# 创建窗口并最大化cv2.namedWindow(Captured Frame, cv2.WINDOW_NORMAL)cv2.resizeWindow(Captured Frame, 1920, 1080) # 设置默认分辨率窗口大小cv2.imshow(Captured Frame, frame)# 保存图像到本地cv2.imwrite(captured_image.jpg, frame)print(图像已保存为 captured_image.jpg)else:print(无法采集图像)# 等待按键退出cv2.waitKey(0)cap.release()cv2.destroyAllWindows()if __name__ __main__:# 遍历所有摄像头并输出最大分辨率find_all_cameras()# 示例采集第一个摄像头的图像camera_index 0capture_width 1920capture_height 1080capture_image_with_maximized_window(camera_index, capture_width, capture_height)输出为发现 2 个摄像头 摄像头 0 的最大分辨率为1920x1080 摄像头 2 的最大分辨率为1920x1080 实际采集的图像分辨率: 宽度1920, 高度1080
买了2个摄像头一个2K,一个4k实际都是2k吧请问另外的2k哪里去了