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()
class MyCamera(object): def __init__(self): pass 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 fix_orientation(self): _, sensor_id = self.arducam_utils.read_dev( ArducamUtils.FIRMWARE_SENSOR_ID_REG) print("0x{:X}".format(sensor_id)) if sensor_id == 0x5647: self.arducam_utils.cvt_code = cv2.COLOR_BAYER_GB2BGR self.cap.grab() self.arducam_utils.write_sensor(0x3820, 0x42) self.arducam_utils.write_sensor(0x3821, 0x00) elif sensor_id == 0x0219: self.arducam_utils.cvt_code = cv2.COLOR_BAYER_RG2BGR self.cap.grab() self.arducam_utils.write_sensor(0x0172, 0x03) def get_framesize(self): width = self.cap.get(cv2.CAP_PROP_FRAME_WIDTH) height = self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT) return (width, height) def close_camera(self): self.cap.release() self.cap = None def get_frame(self): ret, frame = self.cap.read() if not ret: return None return self.arducam_utils.convert(frame)
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()
parser.add_argument("--verbose", "-v", action="count") args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) if args.cert_file: ssl_context = ssl.SSLContext() ssl_context.load_cert_chain(args.cert_file, args.key_file) else: ssl_context = None #Init camera cmd1 = 'v4l2-ctl -d 0 -c exposure=160' 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 dimentions de l'image en provenance du capteur w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) # needed to purge the frame with default exposure for i in range(6): subprocess.call(cmd1, shell=True) ret, frame = cap.read() app = web.Application() app.on_shutdown.append(on_shutdown) app.router.add_get("/", index)
help= "When using Camarray's single channel, use this parameter to switch channels. \ (E.g. ov9781/ov9281 Quadrascopic Camera Bundle Kit)" ) args = parser.parse_args() # open camera cap = cv2.VideoCapture(args.device, cv2.CAP_V4L2) # set pixel format 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) show_info(arducam_utils) # 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) if args.channel in range(0, 4): arducam_utils.write_dev(ArducamUtils.CHANNEL_SWITCH_REG, args.channel)