Obtain IPC List
(alpha) D:\anaconda3\envs\alpha\main5>wmic path Win32_PnPEntity where "Service='usbvideo'" get Name /value | findstr "Name="
Name=Integrated Camera
Name=HD USB Camera
Obtain IPC Resolution
(alpha) D:\anaconda3\envs\alpha\main5>ffprobe -loglevel quiet -f dshow -show_streams -i video="Integrated Camera" | findstr "coded_width | coded_height"
coded_width=1280
coded_height=720
(alpha) D:\anaconda3\envs\alpha\main5>ffprobe -loglevel quiet -f dshow -show_streams -i video="HD USB Camera" | findstr "coded_width | coded_height"
coded_width=3840
coded_height=2880
Checking
(alpha) D:\anaconda3\envs\alpha\main5>check
Input="Integrated Camera" Resolution=1280x720 Framerate=30
(alpha) D:\anaconda3\envs\alpha\main5>check "Integrated Camera" 800x600 25
Input="Integrated Camera" Resolution=800x600 Framerate=25
(alpha) D:\anaconda3\envs\alpha\main5>check "HD USB Camera" 1280x720 20
Input="HD USB Camera" Resolution=1280x720 Framerate=20
letterbox & scale_coords
if True:
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # YOLO需要RGB输入
if True:
stride = int(model.stride.max().item())
img, ratio, pad = letterbox(rgb_frame, img_size, stride=stride)
img = img.transpose(2, 0, 1) # HWC to CHW
img = torch.from_numpy(img).to(device).float()
img /= 255.0 # 归一化
if img.ndimension() == 3: img = img.unsqueeze(0)
with torch.no_grad():
pred = model(img)[0]
# NMS
pred = non_max_suppression(pred, conf_thres, iou_thres)
if True:
for det in pred:
original_img = frame.copy()
if len(det):
det[:, :4] = scale_coords(img.shape[:2], det[:, :4], rgb_frame.shape[:2], ratio_pad=(ratio, pad)).round()
for *xyxy, conf, cls in det:
label = f'{model.names[int(cls)]} {conf:.2f}'
plot_one_box(xyxy, original_img, label = label, color = colors[int(cls)])
rgb_frame = original_img