Running Hamamatsu Orca Flash 4 code

Hello, I came across the Orca Flash 4 example code while trying to find a way to process images taken from that camera using Opencv. Hamamatsu has an SDK but modifying the source to process images with Opencv (take stdev/mean of 5 pixel kernel in real time) is a bit more than I can muster. As for running the Hamamatsu python source on this site, what modules need to be installed for that to work? Do you ever program using python in Visual Studio? I really like the intellisense but there might be other issues with getting everything to work in Visual Studio that makes it less than ideal.

Hello Jeremy!

Since the code was written, a lot of time passed, and Hamamatsu released a lot of documentation on their DCAM-API (which was not available when I worked with the code.) If I’m not mistaken, you can make OpenCV work on any array, therefore, you can grab the image from the camera and pass it to the std/mean functions you want to you.

What code did you find that brought you here? I will base myself on this example. The important class in that file is HamamatsuCamera, especially you can see that the method getFrames reads the camera and returns a list of all the frames available.

Each frame is a numpy array and thus you can work on it as you prefer, also with OpenCV. In order for the program to run, you will need to have installed DCAM-API. The importing of the library happens on this line, so if you have problems after installing (perhaps newer versions of the library work differently), that is the line you have to check.

Regarding Visual Studio (or any other IDE), they are great tools for developing code and testing it. However, if you want to run your programs, it is normally wise to do it from the command line. IDE’s consume a lot of resources and may add a bit of overhead that may ruin your program (especially if it is time sensitive as acquiring from a camera). I normally use Pycharm, which is free for educational purposes, or provides a community edition. My experience with VS was also positive, but it didn’t make any sense changing from one IDE to another just because.

Hope I’ve managed to point you into the right direction! Let me know if there is anything else!

Hello Aqui,

Yes, your reply is very helpful, thank you.

I’m sure you have seen the DCAM SDK for that camera and I can run it without issues. The problem starts when I try to figure out where in the Excap4 sample code to transfer frames to an array with OpenCV to then process and then how to change the GUI to make it easy to display and save processed images. C++ code is a bear for me to follow, even debugging line by line. So it seems that starting with your python sample code (the Hamamatsu code you linked is what brought me here) might be easier for me to use as long as I can keep the overhead low.

I will make sure the DCAM-API is installed and see if I can get it running.

Great work on the articles/tutorials! I’m very interested in the GUI and driver development.

1 Like

It’s been a while since last time I checked the Hamamatsu code, and I don’t have access to a camera now to test. I’ve seen the Excap4 and it seems a fairly complex program, which I’m not sure is going to help you more than confuse you.

Are you developing anything which is very time-critical? I’ve managed to deal with >500fps with the class in the link. And I believe OpenCV is highly optimized for the kind of operations in which you are interested, so I think it is a good match.

What you have to understand is that once the data was transferred from the camera to the computer, you will have very little (negligible) if you call an OpenCV function on a numpy array (the frame of your camera). You won’t be transferring data to other memory space nor anything. If you have some code to share, it would be great.

In the file that you found, pay attention that at the end you have some examples on how to run it. Especially, if you change the 0 for a one in this line you will acquire data from the camera. You can then change this other line in order to process the frames with OpenCV and then you will have a very quick working test.

When you are ready to build a GUI, you can check this article that deals with a camera, so I think it can be a good match. Cameras generate a LOT of information very quickly. If on top you need to analyze or transform the data, you will run into performance issues. I’ve written a tutorial, which is fairly advanced, but it is the foundation of how Pynta works.

Would you mind explaining what your experiment is?

Yeah, the Excap4 definitely does more to confuse me, you are right about that.

I’m trying to do laser speckle contrast imaging to record surface blood flow (for example see this article ) where I process a 5x5 pixel sliding window of standard deviation/mean in real time (say 10fps) and save them. I’ve done this using OpenCV with a Dalsa 1M60 camera and EPIX framegrabber/programming library with an SDK that is much easier for me to follow. Now I want to get up and running with the Hamamatsu camera which seems very doable with the python code you posted.

1 Like

I’ve run into a snag getting this example code to run. Installing pyQt4 has been really troublesome but I can install pyQt5 no problem. I updated the code for pyQt5 except I’m having a bit of trouble with SIGNAL in the file in the Model/Cameras folder (I updated to pyqtSignal but apparently ‘Updated’ nor ‘New’ are supported as pyqtSignal argument types). Can you comment on how to deal with something like this where you might have to migrate code from an older version of pyQt or do you not recommend doing that because of all the problems that will potentially cause?

Did you manage to acquire some data with your Hamamatsu camera (regardless of the user interface)?

Regarding Pyqt4/5, I have to be honest and tell you that I made the mistake of sticking to PyQt4 for too long. I was reusing code, etc. and in retrospective, that was a huge mistake.

Some of the differences between PyQt4 and PyQt5 are just cosmetic, such as some imports are now from different modules (from PyQt5.QtWidgets import QApplication used to be from PyQt4.QtGui import QApplication). That is easy to fix. However, PyQt5 has dropped support for old-fashioned signals and slots. You can read a brief summary here. So, I would keep working in porting the program to PyQt5 if possible.

I couldn’t find the file you refer to in the Model/Cameras. Would you put a link to the file in the Github repository? Also, it would be very useful if you copy the error you get while running the program. If you make the changes to UUTrack publicly available on Github, it is also much quicker for me to check and point you in a specific direction.

Yes, I have been able to verify that the camera is set up and capturing images in several programs, including the DCAM SDK example programs using C# and C++ (Excap4) that I compiled using Visual Studio 2019.

It sounds like I am on the right track trying to update to pyQt5. Like you mentioned, there are mostly easy fixes. It seems that figuring out what to do with the signals is going to take some digging.

lines 65 and 68 are the SIGNAL calls. I tried to just make them pyqtSignal calls but, as you mentioned, they don’t work the same anymore so I need to figure out how change the code and keep the functionality.

I’ll try to make changes available publicly available on Github. Seems fairly intuitive with Visual Studio so we’ll see how it goes.

I was actually asking if you’ve managed to run the code using the Hamamatsu Python wrapper.

To update that part of the code, you will need to define the Signal explicitly, I would add it right before __init__, like this:

Updated = pyqtSignal()

And then line 65 becomes:


You will have to do that for every signal (not only on the file).

Then, you will need to update the other part of the code, which is where you connect signals to slots. For example in here there is a line:


Which should become:


It’s a bit of work, but once you get the gist of it, should work.

It was so long since I wrote UUTrack, I had even forgotten how convoluted the had become. Don’t take that approach anymore fortunately!

You can also check PyNTA, which is under development (and if you are newer to Python is not a good starting point), but there I use the new syntax for signals and slots.

I’m trying to take a step back and do what you suggested, which was to run the code as-is, but I’ve hit some snags. Since you said you use pycharm I installed the edu version but have trouble installing the requirements from the requirements.txt file, both when using pycharm as well as visual studio. PyQt4 has been especially challenging to install in either IDE. Any suggestions?

Hi jjsword,
I had the same problem with installing PyQt4. I solved it by using python 3.6.1 instead of the newest version of python 3.7. For python 3.6.1 it is possible to install PyQt4 without too much trouble (I am not completely sure about which method I used, either pip or a wheel). Using an older version of python has it’s own problems but I hope this can help you.

Thanks for the feedback!
To follow that approach, a great resource website is:

where you have plenty of precompiled wheels for Python.

If you manage to make the switch to PyQt5 (which I completely advise), it would be great to see the code!

I’ve made some progress installing the requirements, and even have PyQt4 installed (from the link mentioned-thanks to you both!) but have run into problems because I don’t think I’m using the correct version of python. What version python did you use the last time you ran the Orca Flash program?

I know it’s been a very long time! Sorry for that.
Most likely, I was using Python 3.5 when I’ve managed to run the code.

Is there any place where I can see what you are doing? If you don’t want to make it public, you can create a private Github repository. I am developing a set of tools for people to quickly build user interfaces, it is still incomplete, but would be great to learn about your use case!

Unfortunately I got to a point where just being able to run your source code was too challenging, whether I was using PyCharm, Visual Studio, or Anaconda. I finally installed PyQt 4 but then I still had troubles getting the source to run because of the python version I was using, presumably. So I went back to the ExCap4 source in C++ from the Hamamatsu SDK and after some lengthy digging into the flow of the program, I was finally able to transfer image data to OpenCV to process images in real time. 12 bit images were challenging because they are bit packed (2 pixels of data in 3 bytes) but there was an example of how to unpack them as well. Believe it or not, that ended up being the fastest way forward for me. I would be happy to share that source with you if you are interested but it is C++ and not python :slight_smile:

It’s a pity to hear you had to abandon Python! With what I’m building, you will be able to try out the acquisition from the Hamamatsu and doing real-time analysis in around 1 hour of coding (that’s my goal at least). OpenCV is a GREAT tool! Not sure what kind of data processing you need, but they guys behind it really know what they are doing, and probably you won’t find better implementations of complex algorithms.

It would be great to see your code, so I have an idea of what you need to do. I’m building the code in a distributed way, so that you can acquire and process data independently, where processing data means anything from saving it to disk, to analysis, to plotting, etc. And where the processed data can be an entry for a different task, for instance, instead of saving raw data, you save the processed data, which could be orders of magnitude smaller.

Here is a link to the source on GitHub
I used OpenCV 3.4.3 and Hamamatsu_DCAMSDK4_v18085609 which I downloaded from . The API would be required to run it, of course. I used Visual Studio 2019 since the intellisense training wheels help me a lot. I should say I added code to the imagedcam.cpp file for transferring image buffer data to a Mat object for processing and added code to unpack the 12 bit images.

Right now it is a little clunky since I have no idea yet how to change the GUI to incorporate the OpenCV window and I would like to add a real time histogram that I can turn on and off. It works so I’m happy for now. I think you can run it without a camera connected but obviously you won’t be able to capture any images.

Thank you for the description of what is going on!

I will take a look, and see if I can somehow port this to Python, don’t promise anything soon, but I’ll add it to the list of features :slight_smile: