-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCamera.py
More file actions
58 lines (45 loc) · 1.35 KB
/
TestCamera.py
File metadata and controls
58 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import PIL.Image
import torch.nn.utils.prune as prune
from ultralytics import YOLO
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.transforms.functional as TF
import PIL
import os
from runpy import run_path
from skimage import img_as_ubyte
from collections import OrderedDict
from natsort import natsorted
from glob import glob
import cv2
import argparse
import time
from torchinfo import summary
SOURCE_TYPE = 'usb'
USB_IDX = 0
RES_W, RES_H = 640, 480
cap_arg = USB_IDX
# cap = cv2.VideoCapture(cap_arg)
# cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
# cap.set(cv2.CAP_PROP_FPS, 30)
# cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
# cap.set(3, RES_W)
# cap.set(4, RES_H)
cap = cv2.VideoCapture(USB_IDX, cv2.CAP_V4L2)
# cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
cap.set(cv2.CAP_PROP_FPS, 30)
for _ in range(15):
cap.read()
while True:
ret, frame = cap.read()
if (frame is None) or (not ret):
print('Unable to read frames from the camera. This indicates the camera is disconnected or not working. Exiting program.')
break
frame = cv2.resize(frame, (RES_W, RES_H))
cv2.imshow(winname= 'USB Camera 00', mat=frame)
key = cv2.waitKey(5)
if key ==('q') or key == ord('Q'):
break