def __init__(self, exposure=500, gain=0): """ exposure (in us, default 500us) gain (image gain in dB, default 0) """ print("Creating camera object") Aravis.enable_interface("Fake") self.camera = Aravis.Camera.new(None) self.camera.set_region(0, 0, 2064, 1544) #2064x1544 print("Old packet size: %d" % self.camera.gv_get_packet_size()) self.camera.gv_set_packet_size(1024) print("New packet size: %d" % self.camera.gv_get_packet_size()) #camera.set_binning(1,1) #basically disable #camera.set_frame_rate (10.0) self.camera.set_exposure_time(exposure) #us self.camera.set_gain(gain) self.camera.set_pixel_format(Aravis.PIXEL_FORMAT_MONO_8) self.camera.set_trigger("Line1") print("Getting payload object") self.payload = self.camera.get_payload() [self.x, self.y, self.width, self.height] = self.camera.get_region() print("Creating stream") self.stream = self.camera.create_stream(None, None) if self.stream is None: print("Failed to construct stream") return print("Starting Acquisition") self.camera.start_acquisition() print("Creating stream buffer") for i in range(0, 50): self.stream.push_buffer(Aravis.Buffer.new_allocate(self.payload)) print("Done") self.prs = queue.Queue()
def Setup_Camera(verbose, fakeCam=False): ''' Instantiates a camera and returns it, along with the corresponding "dev". This gives access to "deeper" camera functions, such as the device temperature. If fakeCam = True, it returns the fake camera object, a software equivalent, with (presumably realistic) noise, etc. ''' Aravis.update_device_list() # Scan for live cameras if fakeCam: Aravis.enable_interface("Fake") # using arv-fake-gv-camera-0.8 cam = Aravis.Camera.new(None) # Instantiate cam if verbose: print("Instantiated FakeCam") else: # Note: We expect only one "real" camera !! try: cam = Aravis.Camera.new(Aravis.get_device_id(0)) # Instantiate cam if verbose: print("Instantiated real camera") except: print("ERROR - No camera found") # Ooops!! return None, None, None # Send back nothing dev = cam.get_device() # Allows access to "deeper" features return cam, dev # Send back camera, device
def getCameraStream(): Aravis.enable_interface("Fake") try: if len(sys.argv) > 1: camera = Aravis.Camera.new(sys.argv[1]) else: camera = Aravis.Camera.new(None) except: print("No camera found") exit() stream = camera.create_stream(None, None) #stream.push_buffer (Aravis.Buffer.new_allocate(payload)) return stream, camera
def __init__(self): # Open camera, and get image dimensions Aravis.enable_interface('Fake') self.camera = Aravis.Camera.new(None) self.stream = self.camera.create_stream(None, None) payload = self.camera.get_payload() self.stream.push_buffer(Aravis.Buffer.new_allocate(payload)) x, y, w, h = self.camera.get_region() self.width = w self.height = h self.camera.start_acquisition() # Set up scanner self.scanner = zbar.ImageScanner() self.scanner.parse_config('enable') # Set up code cache self.cache = {}
def GigeStreamer(cam_id): camera_id = cam_id pyyolo.init(darknet_path, datacfg, cfgfile, weightfile) Aravis.enable_interface(camera_id) # using arv-fake-gv-camera-0.6 camera = Aravis.Camera.new(None) stream = camera.create_stream(None, None) payload = camera.get_payload() for i in range(0, 50): stream.push_buffer(Aravis.Buffer.new_allocate(payload)) print("Starting acquisition") camera.start_acquisition() while True: buffer = stream.try_pop_buffer() print(buffer) if buffer: frame = convert(buffer) stream.push_buffer(buffer) #push buffer back into stream cv2.imshow("frame", frame) # img = cv2.imread(filename) img = frame.transpose(2, 0, 1) # img = img.transpose(2,0,1) c, h, w = img.shape[0], img.shape[1], img.shape[2] data = img.ravel() / 255.0 data = np.ascontiguousarray(data, dtype=np.float32) # perform_recognition() outputs = pyyolo.detect(w, h, c, data, thresh, hier_thresh) for output in outputs: print(output) ch = cv2.waitKey(1) & 0xFF if ch == 27 or ch == ord('q'): break elif ch == ord('s'): cv2.imwrite("imagename.png", frame) camera.stop_acquisition() pyyolo.cleanup()
# If you have installed aravis in a non standard location, you may need # to make GI_TYPELIB_PATH point to the correct location. For example: # # export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:/opt/bin/lib/girepositry-1.0/ # # You may also have to give the path to libaravis.so, using LD_PRELOAD or # LD_LIBRARY_PATH. import sys import time import gi gi.require_version('Aravis', '0.4') from gi.repository import Aravis Aravis.enable_interface("Fake") try: if len(sys.argv) > 1: camera = Aravis.Camera.new(sys.argv[1]) else: camera = Aravis.Camera.new(None) except: print("No camera found") exit() camera.set_region(0, 0, 128, 128) camera.set_frame_rate(10.0) camera.set_pixel_format(Aravis.PIXEL_FORMAT_MONO_8) payload = camera.get_payload()
# Author: Emmanuel Pacaud <*****@*****.**> # If you have installed aravis in a non standard location, you may need # to make GI_TYPELIB_PATH point to the correct location. For example: # # export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:/opt/bin/lib/girepositry-1.0/ # # You may also have to give the path to libaravis.so, using LD_PRELOAD or # LD_LIBRARY_PATH. import sys import time from gi.repository import Aravis Aravis.enable_interface ("Fake") try: if len(sys.argv) > 1: camera = Aravis.Camera.new (sys.argv[1]) else: camera = Aravis.Camera.new (None) except: print ("No camera found") exit () device = camera.get_device () genicam = device.get_genicam_xml (); print genicam;
import sys import time import gi gi.require_version('Aravis', '0.4') from gi.repository import Aravis import numpy as np from PIL import Image import cv2 Aravis.enable_interface("Fake") # using arv-fake-gv-camera-0.6 try: if len(sys.argv) > 1: camera = Aravis.Camera.new(sys.argv[1]) else: camera = Aravis.Camera.new(None) except: print("No camera found") exit() camera.set_region(0, 0, 128, 128) camera.set_frame_rate(10.0) camera.set_pixel_format(Aravis.PIXEL_FORMAT_MONO_8) camera.set_exposure_time(980) #camera = Aravis.Camera.new(None) device = camera.get_device() device.set_string_feature_value("AcquisitionMode", "SingleFrame") payload = camera.get_payload() [x, y, width, height] = camera.get_region() stream = camera.create_stream()
def worker(camId): pyyolo.init(darknet_path, datacfg, cfgfile, weightfile) Aravis.enable_interface("Fake") try: cam = Aravis.Camera.new(camId) print("Camera found") except: print("No camera found") exit() thresh = 0.45 hier_thresh = 0.5 #cam.set_region (0,0,2048,1536) #cam.set_region (0,0,512,512) #cam.set_frame_rate (10.0) #cam.set_exposure_time(500000) #cam.set_pixel_format (Aravis.PIXEL_FORMAT_MONO_8) #print(dir(cam)) stream = cam.create_stream(None, None) payload = cam.get_payload() [x, y, width, height] = cam.get_region() print("Camera vendor : %s" % (cam.get_vendor_name())) print("Camera model : %s" % (cam.get_model_name())) print("Camera id : %s" % (cam.get_device_id())) print("ROI : %dx%d at %d,%d" % (width, height, x, y)) print("Payload : %d" % (payload)) print("Pixel format : %s" % (cam.get_pixel_format_as_string())) #cv2.namedWindow('Live Stream', flags=0) cv2.namedWindow(camId, flags=0) #rint(dir(stream)) #for i in range(0,50): #stream.push_buffer (Aravis.Buffer.new_allocate (payload)) cam.start_acquisition() lastTime = time.time() transposeTime = 0 i = 0 while (True): stream.push_buffer(Aravis.Buffer.new_allocate(payload)) buffer = stream.pop_buffer() transposeTime = time.time() b = ctypes.cast(buffer.data, ctypes.POINTER(ctypes.c_uint8)) im = np.ctypeslib.as_array(b, (height, width)) #im = im.copy() #print("shape: ", im.shape) #cv2.imshow("Live Stream", im.copy()) gray = im.copy() cv2.imshow(camId, gray) #im = np.zeros((3,gray.shape[0],gray.shape[1])) #im[1,:,:] = gray #im = cv2.cvtColor(gray,cv2.COLOR_GRAY2RGB) im = np.stack((im, ) * 3, -1) im = im.transpose(2, 0, 1) c, h, w = im.shape[0], im.shape[1], im.shape[2] #print(im.shape) #cv2.imshow(camId, im.copy()) im = im.ravel() / 255.0 #print(im.shape) data = np.ascontiguousarray(im, dtype=np.float32) #print("TRANS-FPS: ", 1.0/(time.time()-transposeTime)) predictions = pyyolo.detect(w, h, c, data, thresh, hier_thresh) # { 'left':0, 'right': 767, 'top': 0, 'bottom': x, class': x, prob: x, } for output in predictions: left, right, top, bottom, what, prob = output['left'], output[ 'right'], output['top'], output['bottom'], output[ 'class'], output['prob'] print(output) if (what == 'car'): d_from_top = top d_from_bottom = bottom d_from_left = left d_from_right = right d_height = top d_width = left if (d_height > 0.5): print(output) #trigger other cameras cv2.waitKey(1) print("CAM: ", camId, " Frame: ", i, " FPS: ", 1.0 / (time.time() - lastTime), "RES: ", h, " x ", w) lastTime = time.time() i += 1 cam.stop_acquisition()
def setup_camera(self): print("PROCESS ID: ", os.getpid()) os.system("sudo chrt -f -p 1 %d" % os.getpid()) Aravis.enable_interface("Fake") self.aravis_camera = Aravis.Camera.new(self.cam_id) self.width = int(2048) self.height = int(1536) self.width = int(2048) self.height = int(1536) self.aravis_camera.set_binning(1, 1) self.aravis_camera.set_region(0, 0, self.width, self.height) #2064x1544 #self.width = int(2048/2) #self.height = int(1536/2) #self.aravis_camera.set_region(0,0,self.width,self.height) #2064x1544 #self.aravis_camera.set_binning(2,2) self.aravis_camera.gv_set_packet_size(8000) self.aravis_camera.gv_set_packet_delay( 40000) #np.random.randint(10000)) print("!!!!") print(self.aravis_camera.gv_get_packet_delay()) #self.aravis_camera.gv_set_stream_options(Aravis.GvStreamOption.NONE) aravis_device = self.aravis_camera.get_device() ####print(aravis_device.get_string_feature_value('MaxImageSize')) availpixelformats = self.aravis_camera.dup_available_pixel_formats_as_strings( ) if 'BayerRG8' in availpixelformats: aravis_device.set_string_feature_value("PixelFormat", "BayerRG8") #Mono8, RGB8Packed, BayerRG8 if self.aravis_camera.get_pixel_format_as_string() == 'RGB8Packed': print("Colour") self.colour_camera = True else: print("Monochrome") self.colour_camera = False #Trying to get it working... #aravis_device.set_string_feature_value("LineSelector", "Line0") #aravis_device.set_string_feature_value("LineMode", "Input") #Triggering the camera: # Software trigger... #aravis_device.set_string_feature_value("TriggerMode", "On") #aravis_device.set_string_feature_value("TriggerSource", "Software") # Hardware trigger... aravis_device.set_string_feature_value("TriggerMode", "On") aravis_device.set_string_feature_value("TriggerSource", "Line0") ##print(aravis_device.get_available_trigger_sources()) ##print(self.aravis_camera.get_available_pixel_formats_as_strings()) ##self.aravis_camera.set_trigger("Line0") ####### #self.aravis_camera.set_trigger_source("Line0") aravis_device.set_string_feature_value("TriggerActivation", "RisingEdge") aravis_device.set_string_feature_value("AcquisitionMode", "Continuous") #Triggering the flash... #if triggerflash: #this camera might not be the one doing the triggering aravis_device.set_string_feature_value("LineSelector", "Line2") aravis_device.set_boolean_feature_value("StrobeEnable", True) aravis_device.set_string_feature_value("LineMode", "Strobe") aravis_device.set_integer_feature_value("StrobeLineDelay", 100) aravis_device.set_integer_feature_value("StrobeLinePreDelay", 165) #200 aravis_device.set_string_feature_value("LineSource", "ExposureStartActive") aravis_device.set_boolean_feature_value("LineInverter", True) #aravis_device.set_string_feature_value("ExposureTimeMode","UltraShort") self.aravis_camera.set_exposure_time(90) #140 self.aravis_camera.set_gain(0) ##########NEW CODE FOR SHORT EXPOSURE########## #aravis_device = self.aravis_camera.get_device(); #aravis_device.set_string_feature_value("ExposureTimeMode","UltraShort") #self.aravis_camera.set_exposure_time(7) #15 us #self.aravis_camera.set_gain(0) #self.aravis_camera.set_pixel_format (Aravis.PIXEL_FORMAT_MONO_8) #self.aravis_camera.set_trigger("Line1") #aravis_device.set_float_feature_value("LineDebouncerTime",5.0) ##########ORIGINAL CODE######################## #self.aravis_camera.set_exposure_time(15) #1000000)#15 us #self.aravis_camera.set_gain(0) #self.aravis_camera.set_pixel_format (Aravis.PIXEL_FORMAT_MONO_8) #self.aravis_camera.set_trigger("Line1") self.payload = self.aravis_camera.get_payload() self.stream = self.aravis_camera.create_stream(None, None) ### #self.stream.set_property('packet-timeout',5000) #self.stream.set_property('frame-retention',250000) #self.stream.set_property('packet-request-ratio',0.1) #self.stream.set_property('socket-buffer',Aravis.GvStreamSocketBuffer.FIXED) #self.stream.set_property('socket-buffer-size',5000000) #self.stream.set_property('packet-resend',Aravis.GvStreamPacketResend.ALWAYS) ### if self.stream is None: print("Failed to construct stream") return self.aravis_camera.start_acquisition() for i in range(0, 16): self.stream.push_buffer(Aravis.Buffer.new_allocate(self.payload)) #Print info about camera... print("Camera vendor : %s" % (self.aravis_camera.get_vendor_name())) print("Camera model : %s" % (self.aravis_camera.get_model_name())) print("Camera id : %s" % (self.aravis_camera.get_device_id())) print("Pixel format : %s" % (self.aravis_camera.get_pixel_format_as_string())) print("Ready")