Skip to content

Unable to interface Genie Nano M2020 camera with DeepLabCut-Live #32

@jadrew43

Description

@jadrew43

Hi, I am using DLC-Live's base Camera class to write a class for Teledyne's Genie Nano M2020 camera. I've initiated the camera, started acquisition, and enabled a raw readout. According to get_frame_status(), the number of acquired frames increases by 1 per _capture_loop(), while unread_images==1 and buffer_size==100. I can print out the frame values (2D array of pixel values), and convert that array into a .jpeg matching the image seen in the camera feed provided by National Instruments, but the frame is not getting pushed to the DLC-Live GUI (use_tk_display==True). I've also confirmed that the frame being copied within _capture_loop() is the correct frame, but I cannot discern why that frame is not being pushed to the display. Can anyone assist this issue?

import time
from dlclivegui.camera import Camera
import pylablib as pll
from pylablib.devices import IMAQdx
import numpy as np

class m2020Cam(Camera):
    # Base camera class. Controls image capture, writing images to video, pose estimation and image display. 
    
    Parameters
    ----------
    id : [type]
        camera id
    exposure : int, optional
        exposure time in microseconds, by default None
    gain : int, optional
        gain value, by default None
    rotate : [type], optional
        [description], by default None
    crop : list, optional
        camera cropping parameters: [left, right, top, bottom], by default None
    fps : float, optional
        frame rate in frames per second, by default None
    use_tk_display : bool, optional
        flag to use tk image display (if using GUI), by default False
    display_resize : float, optional
        factor to resize images if using opencv display (display is very slow for large images), by default None
   

   def __init__(
        self,
        id="m2020",
        resolution=[600,600],#[2048, 1536],
        exposure=25.65, #microseconds
        gain=1, #1x to 251x
        rotate=None,
        crop=None,
        fps=15,
        use_tk_display=True, #true if no display module
        display_resize=1.0
    ):
       # Constructor method
        
        self.id = id
        self.exposure = exposure
        self.gain = gain
        self.rotate = rotate
        self.crop = [int(c) for c in crop] if crop else None
        self.set_im_size(resolution)
        self.fps = fps
        self.use_tk_display = use_tk_display
        self.display_resize = display_resize if display_resize else 1.0
        self.next_frame = 0

    def set_im_size(self, res):
        if not res:
            raise CameraError("Resolution is not set!")

        self.im_size = (
            (int(res[0]), int(res[1]))
            if self.crop is None
            else (self.crop[3] - self.crop[2], self.crop[1] - self.crop[0])
        )

    def set_capture_device(self):
        # Sets frame capture device with desired properties
        
        self.cam = IMAQdx.IMAQdxCamera('Cam_3')
        self.cam.start_acquisition(mode='sequence', nframes=100) #called once but read_frames continually called
        self.cam.enable_raw_readout(enable='frame') #makes it so start_acq does not run
        
        return True

    def get_image_on_time(self):
       # Gets an image from frame capture device at the appropriate time (according to fps).
        
        Returns
        -------
        `np.ndarray`
            image as a numpy array
        float
            timestamp at which frame was taken, obtained from :func:`time.time`
       
        frame = None
        while frame is None:
            cur_time = time.time()
            if cur_time > self.next_frame:
                frame = self.get_image()
                timestamp = cur_time
                self.next_frame = max(
                    self.next_frame + 1.0 / self.fps, cur_time + 0.5 / self.fps
                )
        
        return frame, timestamp

    def get_image(self):
        # Gets image from frame capture device
        
        self.cam.wait_for_frame()
        frame = read_oldest_image(return_info=True)
        return frame
        

    def close_capture_device(self):
        # Closes frame capture device
        self.cam.stop_acquisition()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions