def open_camera(self, device=0, width=-1, height=-1): self.cap = cv2.VideoCapture(device, cv2.CAP_V4L2) self.arducam_utils = ArducamUtils(device) # turn off RGB conversion if self.arducam_utils.convert2rgb == 0: self.cap.set(cv2.CAP_PROP_CONVERT_RGB, self.arducam_utils.convert2rgb) # set width if width != -1: self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width) # set height if height != -1: self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height) self.fix_orientation()
def __init__(self): super().__init__() # don't forget this! self.counter = 0 height, width = 480, 640 cmd1 = 'v4l2-ctl -d 0 -c exposure=200' cmd2 = 'v4l2-ctl -d 0 -C exposure' cap = cv2.VideoCapture(0, cv2.CAP_V4L2) arducam_utils = ArducamUtils(0) cap.set(cv2.CAP_PROP_CONVERT_RGB, arducam_utils.convert2rgb) show_info(arducam_utils) # Aquisition des dimensions de l'image en provenance du capteur w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) for i in range(6): subprocess.call(cmd1, shell=True) ret, frame = cap.read()
from utils import ArducamUtils import array import fcntl import os from matplotlib import pyplot as plt def resize(frame, dst_width): width = frame.shape[1] height = frame.shape[0] scale = dst_width * 1.0 / width return cv2.resize(frame, (int(scale * width), int(scale * height))) cap = cv2.VideoCapture(0, cv2.CAP_V4L2) arducam_utils = ArducamUtils(0) cap.set(cv2.CAP_PROP_CONVERT_RGB, arducam_utils.convert2rgb) cv2.namedWindow("window") while cap.isOpened(): ret, frame = cap.read() frame = arducam_utils.convert(frame) resizedImg = resize(frame, 1280.0) #dimensions = resizedImg.shape image_height = resizedImg.shape[0] image_width = resizedImg.shape[1] left_img = frame[0:image_height, 0:(image_width // 2)] right_img = frame[0:image_height, (image_width // 2):image_width] stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)
parser.add_argument('--height', type=lambda x: int(x, 0), help="set height of image") args = parser.parse_args() # open camera cap = cv2.VideoCapture(args.device, cv2.CAP_V4L2) # set pixel format # cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('Y', '1', '6', ' ')) if args.pixelformat != None: if not cap.set(cv2.CAP_PROP_FOURCC, args.pixelformat): print("Failed to set pixel format.") arducam_utils = ArducamUtils(args.device) # turn off RGB conversion if arducam_utils.convert2rgb == 0: cap.set(cv2.CAP_PROP_CONVERT_RGB, arducam_utils.convert2rgb) # set width if args.width != None: cap.set(cv2.CAP_PROP_FRAME_WIDTH, args.width) # set height if args.height != None: cap.set(cv2.CAP_PROP_FRAME_HEIGHT, args.height) # begin display display(cap, arducam_utils, args.device) # release camera cap.release()