Page 1 of 1

Real Time access to frame pixels with Python

Posted: Fri Feb 20, 2026 7:10 am
by Paulinho
Hi, all.
I'd like to access camera pixel data in real time but cannot find any mention of how to do it within SharpCap python.

My intent is to write a python script that tracks the drift over time of multiple SHG700 scans (for timelapse) so that I can provide a nudge to the mount to keep the scans centred. The idea is to look for the edge of the image (change in brighness) and track its movement over a series of scans, and thereby calculate the 'nudge' to recentre it. Since the image is a scan and not a disc, there is no centre of mass etc to track using SharpCap's extant methods.

Grateful for any suggestions.

And if there is already a way to keep successive SHG700 scans centred, please let me know.
Cheers.
Paul

Re: Real Time access to frame pixels with Python

Posted: Fri Feb 20, 2026 8:17 am
by Jean-Francois
Hello Paul,

you can have some answer from my little script from here viewtopic.php?t=9341

My script shows the red selection rectangle and does a quick analysis (average) of the pixel inside it.
When you set a time (test first with only few seconds), the script will perform the average of the "red" rectangle for each frame.
You can set a name for the log file. (You need to change the path for your system manually before using the script the first time).

In place of the average ... you can write something doing a column binning and then analyse the 1D data.

For you ... may be the first time, the red rectangle is not visible or it is around the full image.
In the script ... it is possible to set fix coordinates for the "CutROI()" function or use the full image in place of the red rectangle area.

Here more code that could be useful ... from the cutout to data with the function ToFloats(0) and temp with Array[...].

Code: Select all

    if (dumpdata):
        try:
            cutout = args.Frame.CutROI(SharpCap.Transforms.SelectionRect)
            dt = (datetime.datetime.now() - t0).total_seconds()
            Time_frame.append(dt)
            data = cutout.ToFloats(0)
            info = cutout.Info
            temp = Array[System.Single](info.Height,info.Width)
            actual_max = 0
            #sum_spalten = []
            #sum_zeilen = []
            for i in range(info.Height):
                for j in range(info.Width):
                    value = data[i,j]
                    if value > actual_max:
                        actual_max = value
            Max_frame.append(actual_max)

            for i in range(1, info.Height - 1):
                for j in range(1, info.Width - 1):
                    temp[i,j] = data[i,0] + ((j - 1)*(data[i,info.Width-1] - data[i,0])/(info.Width - 1)) + \
                                data[0,j] + ((i - 1)*(data[info.Height-1,j] - data[0,j])/(info.Height - 1))
                    temp[i,j] = data[i,j] - temp[i,j]/2.0

Regards,
Jean-Francois

Re: Real Time access to frame pixels with Python

Posted: Sat Feb 21, 2026 12:02 am
by Paulinho
Many thanks (merci beaucoup), Jean-Francois.
I had seen your name come up in several searches and was indeed hoping you might have some suggestions.
Very much appreciated.
I shall experiment with your code and see what I can do :)
Cheers.
Paul

Re: Real Time access to frame pixels with Python

Posted: Mon Feb 23, 2026 2:40 am
by Paulinho
Jean-Francois.
A quick update and we can close this topic.
Many thanks once again.
I have the code all working and now just need a sunny day to test my algorithm in real life and tinker with it. I am very happy.
All the best.
Paul

Re: Real Time access to frame pixels with Python

Posted: Mon Feb 23, 2026 8:44 am
by Jean-Francois
Hello Paul,

Thanks for your thanks :-)

I'm a little bit interested to see your script. Can you upload it in the forum ?

Note that some years ago, I had the idea to write a program doing the SHG processing directly in SharpCap.
In my "INTI" capture script for SHG and telescope command, it is possible to start the film processing directly after the capture with the TheSmiths INTI software. It is possible to write a compiled C# program for the processing and use the frame address from SharpCap IronPython script.

Regards,
Jean-Francois

Re: Real Time access to frame pixels with Python

Posted: Mon Feb 23, 2026 11:43 am
by Paulinho
Hi, Jean-Francois.
Once I have it working in real life (which may be several days away given the weather where I am), I'll happily post it.
I'm fairly new to Python and my coding is not that elegant yet, but if the idea/algorithm works as I hope it will, others may find it helpful.
Cheers.
Paul

Re: Real Time access to frame pixels with Python

Posted: Thu Apr 23, 2026 2:45 pm
by Paulinho
Hi, Jean-Francois.
A quick update. Thanks to your excellent help, I now have my script working very nicely. In fact I have gone several steps further in terms of functionality than I originally imagined and pretty much have a complete, automated SHG700 scan controller working from a Windows Form. It's all done in Python (running under SharpCap), which I have learnt along the way and is probably not as elegant as it could be. Nonetheless, once I am happy that it is as robust as I can make it, I'll share it here.
Cheers.
Paul

Re: Real Time access to frame pixels with Python

Posted: Fri Aug 21, 2026 9:38 am
by mconsidine
Hi,
Is this script available to try? I have an SHG700 that I am looking to script. Any suggestions would be appreciated.
Regards,
mconsidine