python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
67 stars 39 forks source link

support PiCam (Raspberry Pi Camera) #167

Closed carandraug closed 1 year ago

carandraug commented 3 years ago

Support the Raspberry Pi Camera (PiCam). Requested by @iandobbie . Initial work on iandobbie's "picam" and "picam-devel" branches.

carandraug commented 3 years ago

@beniroquai : adding you to this issue, since you're planning on implementing support for the picamera first. As we spoke, Ian's most advanced branch to support the picamera was the picam-devel. I just merged master into it and made some adjustments to fit with the current microscope. I suggest you start with the picam-devel branch that it's currently on my fork.

iandobbie commented 3 years ago

Hi everyone.

I am away with no computer this weekend. My memory is the software triggering worked fine but I planned to implement a hardware trigger via an interrupt on a gpio pin. In Theory this is easy but I got distracted by other stuff before I actually implemented it.

Also this is all likely 2-3 years ago so the OS may have moved a little underneath it. Also might be wor to thinking about the new hq camera but we don’t yet have one of these.

Ian

Sent from my iPhone

On 11 Dec 2020, at 16:57, Carnë Draug notifications@github.com wrote:



@beniroquaihttps://github.com/beniroquai : adding you to this issue, since you're planning on implementing support for the picamera first. As we spoke, Ian's most advanced branch to support the picamera was the picam-devel. I just merged master into it and made some adjustments to fit with the current microscope. I suggest you start with the picam-devel branch that it's currently on my fork.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/python-microscope/microscope/issues/167#issuecomment-743308485, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABJTBBLK3VSWMYDDOWVPMJDSUJFNHANCNFSM4RQIFPQQ.

carandraug commented 3 years ago

@beniroquai : just checking, are you still planning on implementing the PiCAM in Microscope?

iandobbie commented 3 years ago

I have done some work on this and got the basic framework in place but I now need some help. The current code is in my repository in wip-picam

I have a trigger which is setup to generate an interrupt from one of the GPIO pins. This currently calls:

def HW_trigger(self,channel):
    '''Function called by GPIO interupt, needs to trigger image capture'''
    print ('PiCam HW trigger')

I want this function to capture an image, with some thing like the software trigger code

        with picamera.array.PiYUVArray(self.camera) as output:
            self.camera.capture(output, format='yuv', use_video_port = False)
            #just return intensity values                                   
            return(output.array[:,:,0])

But not return the array but I guess put it on a queue which _fetch_data then empties, but I know nothing about how best to do queues in python.

beniroquai commented 3 years ago

Hey, sorry for late reply. I was trying to play with microscope, but had troubles to get the GUI up and running on my machine. I'll definitely come back to it later again. For now I was able to hack a GBRL stage (CNC machine/3D printer), Lasers and Lenses as well as the picamerax from Bowman et al. into the openflexure-server system. The device adapters should be fairly simple to port again. The GBRL protocol caused me some problems. I'll try to merge the branch and see what I can do on my end here. Compared to the ordinary picamera package, the picamerax has more degrees of freedoms in terms of RAW acquisitions, selecting the gain and flat fielding.

iandobbie commented 2 years ago

I have now implemented a bare bones driver that does software and hardware triggering. With a test setup I can do software triggering and hardware trigger from a red pitaya. Deals with exposure times, and all standard camera settings (rotation, roi etc...). I will add it to the main branch but it still needs support for

a) the various camera settings b) different camera modes, image sizes etc.... c) generally tidied up to read GPIO pin from config, etc....

carandraug commented 2 years ago

Are you sure the code works? I see it uses self._logger which has been removed from the base class almost two years ago (with 8f2d2fdb1ac1bc6cae2dd). It is also missing a series a few of abstract methods and implements some that are no longer used.

iandobbie commented 2 years ago

Hi am trying to get back to this again. I have merged my latest version with the current microscope main branch and have the software triggering working. I need to test the hardware trigger. As to the previous comment it now uses _logger which the other camera drivers also seem to use so I assume this is ok, also runs fine with main branch, just replacing the picam.py file.

iandobbie commented 2 years ago

I have now tested with HW trigger and it still works with that. My branch is at https://github.com/iandobbie/microscope/tree/picam-update

I will keep working on this to add some of the picam config options.

carandraug commented 1 year ago

@iandobbie already pushed this a few months ago. Closing as fixed.