Esempio n. 1
0
def grabanimage():
    camera_port = 0
    ramp_frames = 40
    camera = cv2.VideoCapture(camera_port)

    ################## original (access camera thru cv2) ##########################

    #    def get_image():
    #        retval, im = camera.read()
    #        return im
    #
    #    for i in xrange(ramp_frames):
    #        temp = get_image()
    #    print("Taking image...")
    ## Take the actual image we want to keep
    #    camera_capture = get_image()
    #    file = "USBtemp.png"
    ## A nice feature of the imwrite method is that it will automatically choose the
    ## correct format based on the file extension you provide. Convenient!
    #    cv2.imwrite(file, camera_capture)

    ############# reading from IDS camera (added 6/1/19 by Abner) #################

    def get_image(w, h):
        im = ueye.get_data(mem_ptr, w, h, bitspixel, lineinc, copy=True)
        return im

    # init camera
    hcam = ueye.HIDS(0)
    initTrigger = ueye.is_InitCamera(hcam, None)

    # load camera parameters
    memory = ueye.int(128)
    #    cameraSettingFile = ueye.wchar_p('/media/pi/USB30FD/Frostad Research Group/Biofilm Project/Code/FINAL_Biofilm Project.ini')
    ret = ueye.is_ParameterSet(hcam, ueye.IS_PARAMETERSET_CMD_LOAD_FILE,
                               cameraSettingFile, memory)
    # set color mode
    ret = ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED)
    # set width and height -- FIND FUNCTION TO OUTPUT IMAGE RESOLUTION
    width = 2560
    height = 1920
    # allocate memory
    mem_ptr = ueye.c_mem_p()
    mem_id = ueye.int()
    bitspixel = 24  # for colormode = IS_CM_BGR8_PACKED
    ret = ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr,
                                mem_id)
    # set active memory region
    ret = ueye.is_SetImageMem(hcam, mem_ptr, mem_id)
    # continuous capture to memory
    ret = ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT)
    # get data from camera and display
    lineinc = width * int((bitspixel + 7) / 8)

    for i in xrange(ramp_frames):
        temp = get_image(width, height)
    print("Taking image...")
    # Take the actual image we want to keep
    camera_capture = get_image(width, height)
    file = "USBtemp.png"
Esempio n. 2
0
def param_from_json(cam):
    """
    Set parameters from config.json file
    Parameter
    =========
    cam: Cam
        IDS camera
    """
    with open(
            '/home/pi/swim4all/Tirocinio/Tirocinio/config.json') as json_file:
        data = json.load(json_file)
        for j in data['config']:
            cam.rectAOI.s32Width = ueye.int(j['width'])
            cam.rectAOI.s32Height = ueye.int(j['height'])
            cam.rectAOI.s32X = ueye.int(j['x'])
            cam.rectAOI.s32Y = ueye.int(j['y'])
            cam.exposure = j['exp']
            cam.pixelclock = j['pixclock']
            cam.current_fps = j['fps']
            cam.gain = j['gain']
            cam.rGain = j['rGain']
            cam.bGain = j['bGain']
            cam.gGain = j['gGain']
            cam.mode_filename = j['directory_structure']
            cam.m_nColorMode = j['color_mode']
Esempio n. 3
0
def init_cam(hcam):

    # get fps
    #  hcam_fps = is_GetFramesPerSecond(hcam, None)

    # set color mode
    ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED)

    # set region of interest
    rect_aoi = ueye.IS_RECT()
    rect_aoi.s32X = ueye.int(0)
    rect_aoi.s32Y = ueye.int(0)
    rect_aoi.s32Width = ueye.int(width)
    rect_aoi.s32Height = ueye.int(height)
    ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi,
                ueye.sizeof(rect_aoi))

    # allocate memory
    mem_ptr = ueye.c_mem_p()
    mem_id = ueye.int()

    ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id)
    ueye.is_SetImageMem(hcam, mem_ptr, mem_id)

    # continuous capture to memory
    ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT)

    return mem_ptr
Esempio n. 4
0
    def set_aoi(self, x, y, width, height):
        rect_aoi = ueye.IS_RECT()
        rect_aoi.s32X = ueye.int(x)
        rect_aoi.s32Y = ueye.int(y)
        rect_aoi.s32Width = ueye.int(width)
        rect_aoi.s32Height = ueye.int(height)

        return ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi))
 def set_aoi(self, x, y, width, height):
     rect_aoi = ueye.IS_RECT()
     rect_aoi.s32X = ueye.int(x)
     rect_aoi.s32Y = ueye.int(y)
     rect_aoi.s32Width = ueye.int(width)
     rect_aoi.s32Height = ueye.int(height)
     # ---  --- #
     hasWorked = ueye.is_AOI(
         self.cam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi,
         ueye.sizeof(rect_aoi))  # set and return the success of AOI change
     #print('SET AOI: ', hasWorked )
     return hasWorked
Esempio n. 6
0
    def Camera_Initialization(self):
        self.hcam = ueye.HIDS(0)
        self.ret = ueye.is_InitCamera(self.hcam, None)
        self.ret = ueye.is_SetColorMode(self.hcam, ueye.IS_CM_MONO12)
        self.IDS_FPS = float(50)
        self.newrate = ueye.DOUBLE(self.IDS_FPS)
        self.rate = ueye.DOUBLE(self.IDS_FPS)
        self.IDS_exposure = float(20)

        self.width = 2056
        self.height = 1542
        self.rect_aoi = ueye.IS_RECT()
        self.rect_aoi.s32X = ueye.int(0)
        self.rect_aoi.s32Y = ueye.int(0)
        self.rect_aoi.s32Width = ueye.int(self.width)
        self.rect_aoi.s32Height = ueye.int(self.height)
        ueye.is_AOI(self.hcam, ueye.IS_AOI_IMAGE_SET_AOI, self.rect_aoi,
                    ueye.sizeof(self.rect_aoi))

        self.mem_ptr = ueye.c_mem_p()
        self.mem_id = ueye.int()
        self.bitspixel = 16
        self.ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height,
                                         self.bitspixel, self.mem_ptr,
                                         self.mem_id)

        self.ret = ueye.is_SetImageMem(self.hcam, self.mem_ptr, self.mem_id)
        self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT)
        #self.lineinc = self.width * int((self.bitspixel + 7) / 8)
        self.lineinc = self.width * int(self.bitspixel / 8)

        self.nRet = ueye.is_SetFrameRate(self.hcam, self.rate, self.newrate)
        self.expms = ueye.DOUBLE(self.IDS_exposure)
        self.nRet = ueye.is_Exposure(self.hcam,
                                     ueye.IS_EXPOSURE_CMD_SET_EXPOSURE,
                                     self.expms, ueye.sizeof(self.expms))

        self.pixelclock = ueye.c_uint(197)
        self.nRet = ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_SET,
                                       self.pixelclock, 4)
        #pixelclock = ueye.c_uint()
        #ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pixelclock, 4)

        self.nRet = ueye.is_SetHardwareGain(self.hcam, 100,
                                            ueye.IS_IGNORE_PARAMETER,
                                            ueye.IS_IGNORE_PARAMETER,
                                            ueye.IS_IGNORE_PARAMETER)
        #gg = ueye.c_uint()
        #ueye.is_SetHWGainFactor(hcam, ueye.IS_GET_MASTER_GAIN_FACTOR, gg)
        self.nRet = ueye.is_SetHardwareGamma(self.hcam,
                                             ueye.IS_SET_HW_GAMMA_ON)
Esempio n. 7
0
def init_cam(hcam):

    # get fps
  #  hcam_fps = is_GetFramesPerSecond(hcam, None)
    
    # set color mode
    ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) 
    
    # set region of interest
    rect_aoi = ueye.IS_RECT()
    rect_aoi.s32X = ueye.int(0)
    rect_aoi.s32Y = ueye.int(0)
    rect_aoi.s32Width = ueye.int(width)
    rect_aoi.s32Height = ueye.int(height)
    ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi))
#    
#    # set parameters, see ids doc for parameter setting flow chart
#    ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, exp, ueye.sizeof(pclock))
#    pclock = ueye.int(220)
#    ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pclock, ueye.sizeof(pclock))
#    
#    expo_rng = ueye.is_Exposure(hcam, IS_EXPOSURE_CMD_GET_CAPS, ncap, size(ncap))
#    ftime_rng = ueye.is_GetFrameTimeRange()
#    expo_rng = (expo_rng[0], max(expo_rng[1], ftime_rng[1]))
#    
#    fps_actual = ueye.cdouble() 
#    ueye.is_SetFrameRate(hcam, ueye.cdouble(fps_set), byref(fps_actual))
#    
#    exp_cap = ueye.uint32()
#    ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_GET_EXPOSURE_RANGE, ueye.byref(exp_cap), ueye.sizeof(exp_cap))
#    exp_cur = ueye.cdouble() # in s
#    ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_SET_EXPOSURE, ueye.byref(exp_cur), ueye.sizeof(exp_cur))

#    ueye.is_SetGainBoost()
#    ueye.is_Gamma()
#    ueye.is_SetHWGainFactor()
#    
    
    # allocate memory
    mem_ptr = ueye.c_mem_p()
    mem_id = ueye.int()
    
    ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id)
    ueye.is_SetImageMem(hcam, mem_ptr, mem_id)
     
    # continuous capture to memory
    ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT)
    
    return mem_ptr
    def __init__(self, h_cam, img_buff):
        self.x = ueye.int()
        self.y = ueye.int()
        self.bits = ueye.int()
        self.pitch = ueye.int()
        self.img_buff = img_buff

        rect_aoi = ueye.IS_RECT()
        check(ueye.is_AOI(h_cam,
                          ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)))
        self.width = rect_aoi.s32Width.value
        self.height = rect_aoi.s32Height.value
        check(ueye.is_InquireImageMem(h_cam,
                                      self.img_buff.mem_ptr,
                                      self.img_buff.mem_id, self.x, self.y, self.bits, self.pitch))
def Set_Values(cam, exposure, gain, blacklevel, automode):
    """sets the exposure time and gain of the camera"""
    exposure = ueye.double(exposure)
    expo = ueye.double()
    gain = ueye.int(gain)
    # sets the exposure time and gain with the values
    # or sets them automatically
    if automode is False:
        ueye.is_SetHardwareGain(cam, gain, ueye.IS_IGNORE_PARAMETER,
                                ueye.IS_IGNORE_PARAMETER,
                                ueye.IS_IGNORE_PARAMETER)
        ueye.is_Exposure(cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, exposure,
                         ueye.ueye.sizeof(exposure))
        expo = exposure
        ueye.is_Blacklevel(cam, ueye.IS_BLACKLEVEL_CMD_SET_OFFSET, blacklevel)
    elif automode is True:
        pval1 = ueye.double(1)
        pval2 = ueye.double(0)
        ueye.is_SetAutoParameter(cam, ueye.IS_SET_ENABLE_AUTO_GAIN, pval1,
                                 pval2)
        pval1 = ueye.double(1)
        pval2 = ueye.double(0)
        ueye.is_SetAutoParameter(cam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, pval1,
                                 pval2)
    return Get_Values(cam.value, expo.value)
Esempio n. 10
0
    def __init__(self, camID, buffer_count=3):
        # Variables
        self.cam = ueye.HIDS(camID)
        self.sInfo = ueye.SENSORINFO()
        self.cInfo = ueye.CAMINFO()
        self.pcImageMemory = ueye.c_mem_p()
        self.MemID = ueye.int()
        self.rectAOI = ueye.IS_RECT()
        self.pitch = ueye.INT()
        self.nBitsPerPixel = ueye.INT(8)
        self.channels = 3
        self.m_nColorMode = ueye.IS_CM_SENSOR_RAW8
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
        self.buffer_count = buffer_count
        self.img_buffer = []
        self.mode_filename = 0

        self.pixelclock = 0
        self.exposure = 0
        self.width = 0
        self.height = 0
        self.nRet = 0
        self.camID = camID
        self.current_fps = 0
        self.FPS = 0
        self.gain = 0
        self.rGain = 0
        self.bGain = 0
        self.gGain = 0
Esempio n. 11
0
    def __init__(self):
        # Variabeln für Kameraverarbeitung
        self.h_cam = ueye.HIDS(0)
        self.pitch = ueye.INT()
        self.ColorMode = ueye.IS_CM_BGRA8_PACKED
        self.nBitsPerPixel = ueye.INT(32)
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
        self.pitch = ueye.INT()
        self.pcImageMemory = ueye.c_mem_p()
        self.rectAOI = ueye.IS_RECT()
        self.MemID = ueye.int()
        self.width = None
        self.height = None

        self.size_of_square = 3.6  # Zentimeter
        self.nx = 8
        self.ny = 6
        self.n_im = 0
        self.gray = None
        self.objectpoints = None
        self.imagepoints = None
        self.camera_matrix = None
        self.dist_coeff = None
        self.mean_error = 0

        # Pfad zum Speichern der Bilder angeben
        self.path = os.path.dirname(os.path.abspath(sys.argv[0])) + "/images/"
Esempio n. 12
0
    def __init__(self):
        self.hCam = ueye.HIDS(
            1
        )  # 0: first available camera;  1-254: The camera with the specified camera ID
        self.sInfo = ueye.SENSORINFO()
        self.cInfo = ueye.CAMINFO()
        self.pcImageMemory = ueye.c_mem_p()
        self.MemID = ueye.int()
        self.rectAOI = ueye.IS_RECT()
        self.pitch = ueye.INT()
        self.nBitsPerPixel = ueye.INT(
            24
        )  # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome
        self.channels = 3  # 3: channels for color mode(RGB); take 1 channel for monochrome
        self.m_nColorMode = ueye.INT()  # Y8/RGB16/RGB24/REG32
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)

        self.f_length = (652.7396, 653.3803)  # FocalLength
        self.p_center = (321.8104, 259.7124)  # PrincipalPoint
        self.intrinsic = np.array(
            [[self.f_length[0], 0, self.p_center[0]],
             [0, self.f_length[1], self.p_center[1]], [0, 0, 1]],
            dtype=np.float)
        self.offset = [0, 0, 50]  #milimeter
        # ---------------------------------------------------------------------------------------------------------------------------------------
        print("In hand camera initilized")
    def __init__(self):
        self.cam = ueye.HIDS(0)
        self.cam_info = ueye.CAMINFO()
        self.sensor_info = ueye.SENSORINFO()
        self.image_memory = ueye.c_mem_p()
        self.memory_id = ueye.int()
        self.rect_aoi = ueye.IS_RECT()
        self.bits_per_pixel = ueye.INT(24)
        self.bytes_per_pixel = int(self.bits_per_pixel / 8)
        self.pitch = ueye.INT()
        self.color_mode = ueye.INT()
        self.width = 0
        self.height = 0
        self.status = 'IDLE'
        self.data = []
        self.lock = Lock()
        self.pipe = 0
        self.offset_x = 2
        self.offset_y = 2

        self.__init_camera()
        self.__get_camera_info()
        self.__get_sensor_info()
        #self.__default()
        self.__display_mode()
        self.__get_color_mode()
        self.__get_dimensions()
        self.__memory_allocation()
        self.__set_color_mode()
        self.__set_events()
        self.__mandatory_shit()

        print("Color mode {}".format(self.color_mode))
        print("Bits per pixel {}".format(self.bits_per_pixel))
        print("Bytes per pixel {}".format(self.bytes_per_pixel))
Esempio n. 14
0
 def __init__(self, parent=None):
     self.converted_memory_pointer = ueye.c_mem_p()
     self.converted_memory_id = ueye.int()
     self.img_data = ImageData()
     self.capturing = False
     self.hCam = 0
     self.init()
     ueye.is_SetColorMode(self.hCam, ueye.IS_CM_RGB8_PACKED)
     self.alloc(self.hCam)
     self.qt_image = None
     ueye.is_CaptureVideo(self.hCam, Wait=True)
     QWidget.__init__(self, parent, flags=Qt.Widget)
     self.graphics_scene = QGraphicsScene()
     self.graphics_view = QGraphicsView(self.graphics_scene)
     self.graphics_view.setViewportUpdateMode(
         QGraphicsView.FullViewportUpdate)
     self.start_stop_button = QPushButton("start/stop")
     self.event = ueye.HANDLE(int())
     self.frame_event_id = ueye.IS_SET_EVENT_FRAME
     self.image_data_copy = None
     self.pil_image = None
     self.pix_map = None
     self.width = 0
     self.height = 0
     self.threads = []
     layout = QVBoxLayout()
     layout.addWidget(self.start_stop_button, alignment=Qt.AlignTop)
     layout.addWidget(self.graphics_view)
     self.setLayout(layout)
     self.start_stop_button.clicked.connect(self.switch_capturing)
Esempio n. 15
0
    def set_aoi(self, x, y, width, height):
        """
        Set the area of interest.

        Parameters
        ==========
        x, y, width, height: integers
            Position and size of the area of interest.
        """
        rect_aoi = ueye.IS_RECT()
        rect_aoi.s32X = ueye.int(x)
        rect_aoi.s32Y = ueye.int(y)
        rect_aoi.s32Width = ueye.int(width)
        rect_aoi.s32Height = ueye.int(height)
        return ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi,
                           ueye.sizeof(rect_aoi))
def Init_Cam(width=640, heigth=480, gain_boost=1):
    """inits the uEye camera"""
    # inits next available cam
    cam = ueye.HIDS(0)
    ueye.is_InitCamera(cam, None)

    ueye.is_EnableAutoExit(cam, ueye.IS_ENABLE_AUTO_EXIT)

    # sets the Colourmode of the camera
    ueye.is_SetColorMode(cam, ueye.IS_CM_SENSOR_RAW8)

    # sets the trigger
    ret = ueye.is_SetExternalTrigger(cam, ueye.IS_SET_TRIGGER_SOFTWARE)
    mode = ueye.int(0)

    # sets the blacklevel
    ueye.is_Blacklevel(cam, ueye.IS_BLACKLEVEL_CMD_SET_MODE, mode,
                       ueye.sizeof(mode))

    # sets the size of the image
    rectAOI = ueye.IS_RECT()
    rectAOI.s32X = 44
    rectAOI.s32Y = 0
    rectAOI.s32Width = 480
    rectAOI.s32Height = 480
    ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_SET_AOI, rectAOI, ueye.sizeof(rectAOI))

    # allocates memory with given size
    width = ueye.int(width)
    heigth = ueye.int(heigth)
    bitspixel = ueye.int(8)
    pcImgMem = ueye.c_mem_p()
    pid = ueye.int()
    ueye.is_AllocImageMem(cam, 480, heigth, bitspixel, pcImgMem, pid)

    # sets the image memory as active
    ueye.is_SetImageMem(cam, pcImgMem, pid)

    # activates video mode
    ueye.is_CaptureVideo(cam, ueye.IS_DONT_WAIT)

    # sets gain boost mode
    if gain_boost == 1:
        ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_ON)
    else:
        ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_OFF)
    return cam, ret, pcImgMem, pid
Esempio n. 17
0
    def __init__(self):
        # Variabeln für Kameraverarbeitung
        self.h_cam = ueye.HIDS(0)
        self.pitch = ueye.INT()
        self.ColorMode = ueye.IS_CM_BGRA8_PACKED
        self.nBitsPerPixel = ueye.INT(32)
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
        self.pitch = ueye.INT()
        self.pcImageMemory = ueye.c_mem_p()
        self.rectAOI = ueye.IS_RECT()
        self.MemID = ueye.int()
        self.width = None
        self.height = None
        self.dst = None
        self.path_images = os.path.dirname(os.path.abspath(
            sys.argv[0])) + "/images/"

        # laden der intrinsischen Kalibriermatrix
        self.load_calibration_config()

        # Variabeln zur Farberkennung
        self.found_container = False
        self.contours_rectangle = []
        blue_lower = [50, 0, 0]
        blue_upper = [255, 75, 75]
        self.boundaries = [(blue_lower, blue_upper)]
        self.cX = None
        self.cY = None
        self.cX_container = None
        self.cY_container = None

        # Variablen zur Positionsbestimmung
        self.container_world_position = []
        self.ball_position = []
        self.container_position = []
        self.qr_centres = []
        self.world_points = []
        self.qr_codes = None
        self.image_points_of_qr_codes = None
        self.localization_qr_codes = []
        self.world_localization_qr_codes = []
        self.increment = 0.25
        self.results = 0

        # Wahl des Ansatzes
        self.method = 0
        while self.method <= 0 or self.method >= 4:
            try:
                self.method = eval(
                    input(
                        "Mit welchem Ansatz sollen die Positionen ermittelt werden?\n (1) GPS-Ansatz\n "
                        "(2) Vergleichsansattz\n (3) Berechnen der Weltkoordinaten\n"
                    ))
            except NameError:
                self.method = 0
            except SyntaxError:
                self.method = 0
            except TypeError:
                self.method = 0
Esempio n. 18
0
def _throw_if_err(hcam, err):
    if err != ueye.IS_SUCCESS:
        ueye_err = ueye.int(err)
        txt = ueye.c_char_p()
        ret = ueye.is_GetError(hcam, ueye_err, txt)
        msg = str(
            txt.value) if ret == ueye.IS_SUCCESS else 'camera not availible'
        raise _IdsException(msg)
Esempio n. 19
0
 def __init__(self):
     self.hcam = ueye.HIDS(0)
     self.membuf = ueye.c_mem_p()
     self.memid = ueye.int()
     self.pitch = -1
     self.framerate = -1
     self.imgwidth = None
     self.imgheight = None
Esempio n. 20
0
 def getImageData(self):
     # --- set AOI --- #
     rect_aoi = ueye.IS_RECT()
     hasWorked = ueye.is_AOI(self.cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi,
                             ueye.sizeof(rect_aoi))
     self.check(hasWorked, 'getImageData')
     # ---  --- #
     x = ueye.int()
     y = ueye.int()
     bits = ueye.int()
     pitch = ueye.int()
     self.frame_width = rect_aoi.s32Width.value
     self.frame_height = rect_aoi.s32Height.value
     hasWorked = ueye.is_InquireImageMem(self.cam, self.img_buffer.mem_ptr,
                                         self.img_buffer.mem_id, x, y, bits,
                                         pitch)
     self.check(hasWorked, 'getImageData')
     self.imgdata = ueye.get_data(self.img_buffer.mem_ptr, self.frame_width,
                                  self.frame_height, bits, pitch, True)
    def __init__(self):
        super(CamDialog, self).__init__()
        loadUi('cam.ui', self)
        self.image=None
        self.roi_color=None
        self.startButton.clicked.connect(self.start_webcam)
        self.stopButton.clicked.connect(self.stop_webcam)
#        self.detectButton.setCheckable(True)
#        self.detectButton.toggled.connect(self.detect_webcam_face)
        self.face_Enabled=False
        self.faceCascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

        self.hCam = ueye.HIDS(0)  # 0: first available camera;  1-254: The camera with the specified camera ID
        self.sInfo = ueye.SENSORINFO()
        self.cInfo = ueye.CAMINFO()
        self.pcImageMemory = ueye.c_mem_p()
        self.MemID = ueye.int()
        self.rectAOI = ueye.IS_RECT()
        self.pitch = ueye.INT()
        self.nBitsPerPixel = ueye.INT(24)  # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome
        self.channels = 3  # 3: channels for color mode(RGB); take 1 channel for monochrome
        self.m_nColorMode = ueye.INT()  # Y8/RGB16/RGB24/REG32
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)

        self.nRet = ueye.is_InitCamera(self.hCam, None)
        self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo)
        self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo)
        self.nRet = ueye.is_ResetToDefault(self.hCam)
        self.nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB)
        ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode)
        self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI))
        self.width = self.rectAOI.s32Width
        self.height = self.rectAOI.s32Height
        self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID)
        self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID)
        self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode)
        self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT)
        self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch)
        self.xp=[]
        self.yp=[]
        self.lxp=[]
        self.lyp = []
        self.rxp = []
        self.ryp = []
        self.sx = 200
        self.sy = 150
        self.endx = 600
        self.endy = 450

   #     self.avgx = 0
    #    self.avgy = 0
        self.holeflag = 0
        self.lflag = 0
        self.rflag = 0
def Get_Values(cam, exposure):
    """gets the current exposure time and gain of the camera"""
    exposure = ueye.double(exposure)
    gain = ueye.int()
    ueye.is_Exposure(cam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, exposure,
                     ueye.sizeof(exposure))
    gain = ueye.is_SetHardwareGain(cam, ueye.IS_GET_MASTER_GAIN,
                                   ueye.IS_IGNORE_PARAMETER,
                                   ueye.IS_IGNORE_PARAMETER,
                                   ueye.IS_IGNORE_PARAMETER)
    return exposure.value, gain
Esempio n. 23
0
    def __init__(self, cam, img_buffer):
        self.x = ueye.int()
        self.y = ueye.int()
        self.bits = ueye.int()
        self.pitch = ueye.int()
        self.img_buff = img_buffer
        rect_aoi = ueye.IS_RECT()
        nRet = ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi,
                           ueye.sizeof(rect_aoi))

        if nRet != ueye.IS_SUCCESS:
            error_log(nRet, "is_Aoi")

        self.width = rect_aoi.s32Width.value
        self.height = rect_aoi.s32Height.value
        nRet = ueye.is_InquireImageMem(cam, self.img_buff.mem_ptr,
                                       self.img_buff.mem_id, self.x, self.y,
                                       self.bits, self.pitch)

        if nRet != ueye.IS_SUCCESS:
            error_log(nRet, "is_InquireImageMem")
Esempio n. 24
0
class cam:
    camID = 0
    vc = None
    mem_ptr = ueye.c_mem_p()
    mem_id = ueye.int()
    mem_size = (0,0)

    def __init__(self, _camID):
        self.camID=_camID
        self.vc = ueye.HIDS(_camID)
        if not (ueye.is_InitCamera(self.vc, None)==0):
            raise ValueError('Failed to open camera')


        #reserve memory
        self.mem_size = self.getMaxSize()
        ueye.is_AllocImageMem(self.vc, self.mem_size[0], self.mem_size[1],24,self.mem_ptr, self.mem_id)
        
        #set active memory region
        ueye.is_SetImageMem(self.vc, self.mem_ptr, self.mem_id)
 
        #continuous capture to memory
        ueye.is_CaptureVideo(self.vc, ueye.IS_DONT_WAIT)

        
    def setSize(self,_size):
        #TODO
        #test size:
        if self.getSize() != _size:
            raise ValueError('Failed to set camera size')
        
    def getSize(self):
        _h,_w = self.getFrame().shape[0:2]
        return (_w,_h)
        
    def getMaxSize(self):
        sensorinfo = ueye.SENSORINFO()
        ueye.is_GetSensorInfo(self.vc, sensorinfo)
        return (sensorinfo.nMaxWidth.value,sensorinfo.nMaxHeight.value)

    def getID(self):
        return self.camID
        
    def getFrame(self):
        lineinc = self.mem_size[0] * int((24 + 7) / 8)
        frame = ueye.get_data(self.mem_ptr, self.mem_size[0], self.mem_size[1], 24, lineinc, copy=True)
        frame = np.reshape(frame, (self.mem_size[1],self.mem_size[0], 3))
        return frame
                
    def close(self):
        ueye.is_StopLiveVideo(self.vc, ueye.IS_FORCE_VIDEO_STOP)
        ueye.is_ExitCamera(self.vc)
Esempio n. 25
0
 def __init__(self, cam_ID = 0):
     # Several parameters are unused, but may be needed in the future
     self.hCam = ueye.HIDS(cam_ID)
     self.sInfo = ueye.SENSORINFO()
     self.cInfo = ueye.CAMINFO()
     self.pcImageMemory = ueye.c_mem_p()
     self.MemID = ueye.int()
     self.rectAOI = ueye.IS_RECT()
     self.pitch = ueye.INT()
     self.nBitsPerPixel = ueye.INT(32)  # 32 bits for color camera
     self.channels = 3  # 3: channels for color mode(RGB); take 1 channel for monochrome
     self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED  # RGB32
     self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
Esempio n. 26
0
    def __init__(self):
        # Variabeln für Kameraverarbeitung
        self.h_cam = ueye.HIDS(0)
        self.pitch = ueye.INT()
        self.ColorMode = ueye.IS_CM_BGRA8_PACKED
        self.nBitsPerPixel = ueye.INT(32)
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
        self.pitch = ueye.INT()
        self.pcImageMemory = ueye.c_mem_p()
        self.rectAOI = ueye.IS_RECT()
        self.MemID = ueye.int()
        self.width = None
        self.height = None
        self.dst = None
        self.path_images = os.path.dirname(os.path.abspath(
            sys.argv[0])) + "/images/"

        # laden der intrinsischen Kalibriermatrix
        self.load_calibration_config()

        # Variabeln zur Farberkennung
        blue_lower = [50, 0, 0]
        blue_upper = [255, 75, 75]
        red_lower = [0, 0, 100]
        red_upper = [50, 50, 255]
        green_lower = [0, 75, 50]
        green_upper = [50, 255, 150]
        self.blue_boundaries = [(blue_lower, blue_upper)]
        self.red_boundaries = [(red_lower, red_upper)]
        self.green_boundaries = [(green_lower, green_upper)]

        # Variablen zur Positionsbestimmung
        self.found_blue_container = False
        self.found_red_container = False
        self.found_green_container = False
        self.qr_centres = []
        self.world_points = []
        self.localization_qr_codes = []
        self.world_localization_qr_codes = []
        self.results = 0

        # Farbbereiche
        self.blue = Color(self.blue_boundaries, "blue")
        self.red = Color(
            self.red_boundaries,
            "red",
        )
        self.green = Color(self.green_boundaries, "green")
    def __init__(self, camID):
        super().__init__()

        # Define the variables that will be used to retrieve the properties
        # of the camera (generic dictionnaries from ueye)
        # -----------------------------------------------

        self.hcam = ueye.HIDS(
            camID
        )  # 0 for the first available camera - 1-254 when we already have a specified ID
        self.sensor_info = ueye.SENSORINFO()
        self.cam_info = ueye.CAMINFO()
        self.rectAOI = ueye.IS_RECT()
        self.pcImageMemory = ueye.c_mem_p()
        self.MemID = ueye.int()
        self.pitch = ueye.INT()
Esempio n. 28
0
    def __init__(self, graphic=None, mainf=None):
        """
        Constructor.
        
        """
        
        self.camera = False
        self.graphic = graphic
        self.mainf = mainf
        self.detected_devices = {}

        self.hid = ueye.HIDS()
        self.sinfo = ueye.SENSORINFO()
        self.hwnd = ueye.HWND()
        self.width = None
        self.height = None
        self.psize = None
        self.bitspixel = ueye.INT(24)
        self.bytesppixel = int(self.bitspixel/8)
        self.ppcImgMem = ueye.c_mem_p()
        self.MemID = ueye.int()
        self.colorm = ueye.INT()
        self.pitch = ueye.INT()
        self.rect = ueye.IS_RECT()
        self.maxExp = ueye.double()
        self.minExp = ueye.double()
        self.Exp = ueye.double()
        self.nRet = None

        try:
            self.hid = ueye.HIDS()
            self.sinfo = ueye.SENSORINFO()
            self.hwnd = ueye.HWND()
            self.width = ueye.INT()
            self.height = ueye.INT()
            self.psize = None
            self.bitspixel = ueye.INT(24)
            self.ppcImgMem = ueye.c_mem_p()
            self.pid = ueye.INT()
            self.MemID = ueye.INT()
            self.colorm = ueye.INT()
            self.pitch = ueye.INT()
            self.rect = ueye.IS_RECT()
        except:
            return
Esempio n. 29
0
 def alloc(self, h_cam):
     rect_aoi = ueye.IS_RECT()
     memory_id = ueye.int()
     memory_pointer = ueye.c_mem_p()
     bits_per_pixel = 8
     ueye.is_AOI(h_cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi,
                 ueye.sizeof(rect_aoi))
     ueye.is_AllocImageMem(h_cam, rect_aoi.s32Width, rect_aoi.s32Height,
                           bits_per_pixel, memory_pointer, memory_id)
     ueye.is_SetImageMem(h_cam, memory_pointer, memory_id)
     self.img_data.memory_pointer = memory_pointer
     self.img_data.memory_id = memory_id
     self.img_data.width = rect_aoi.s32Width
     self.img_data.height = rect_aoi.s32Height
     self.img_data.bits_per_pixel = bits_per_pixel
     ueye.is_AllocImageMem(h_cam, rect_aoi.s32Width, rect_aoi.s32Height, 24,
                           self.converted_memory_pointer,
                           self.converted_memory_id)
Esempio n. 30
0
    def __init__(self):
        rospy.init_node("coordinates_publisher")
        self.coordinates_pub = rospy.Publisher("/coordinates",
                                               Coordinates,
                                               queue_size=1)
        self.coordinates_msg = Coordinates()

        self.h_cam = ueye.HIDS(0)
        self.pitch = ueye.INT()
        self.ColorMode = ueye.IS_CM_BGRA8_PACKED
        self.nBitsPerPixel = ueye.INT(32)
        self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
        self.pitch = ueye.INT()
        self.pcImageMemory = ueye.c_mem_p()
        self.rectAOI = ueye.IS_RECT()
        self.MemID = ueye.int()
        self.width = None
        self.height = None
        self.dst = None

        self.load_calibration_config()

        self.found_container = False
        self.contours_rectangle = []
        blue_lower = [51, 0, 0]
        blue_upper = [255, 62, 62]
        self.boundaries = [(blue_lower, blue_upper)]
        self.cX = None
        self.cY = None
        self.cX_container = None
        self.cY_container = None

        self.container_world_position = []
        self.ball_position = []
        self.container_position = []
        self.qr_centres = []
        self.world_points = []
        self.qr_codes = None
        self.image_points_of_qr_codes = None
        self.localization_qr_codes = []
        self.world_localization_qr_codes = []
        self.increment = 0.25