Custom Reticule // Paint over image

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
JesusRL
Posts: 70
Joined: Wed Aug 05, 2020 4:36 pm
Location: Madrid

Custom Reticule // Paint over image

#1

Post by JesusRL »

Hi,

I would like to be able to paint a 'custom reticule' in my images. Basically paint over the image.

The shapes (basically a circles) and positions would be defined programatically. So its not a fixed pattern, as reticules are.

Is there any way to do this?

T&R
User avatar
admin
Site Admin
Posts: 13173
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Custom Reticule // Paint over image

#2

Post by admin »

Hi,

Not really documented, but you can hook the BeforeFrameDisplay event on the camera. This will get called just before the frame is debayered/bit depth reduced before displaying it.

In C# the following code should allow you to draw on the image and have those changes reflected on the screen - it ought to be possible to translate this into Python.

Code: Select all

        private void CameraOnBeforeFrameDisplay(object sender, FrameDisplayEventArgs frameDisplayEventArgs)
        {
            using (var db = frameDisplayEventArgs.Frame.GetDrawableBitmap())
            {
                using (var g = db.GetGraphics())
                {
                    // draw stuff
                }
            }
        }
Robin
JesusRL
Posts: 70
Joined: Wed Aug 05, 2020 4:36 pm
Location: Madrid

Re: Custom Reticule // Paint over image

#3

Post by JesusRL »

Hi Robin,

If I am not wrong it should be something like:

Code: Select all

clr.AddReference('System.Drawing')
from System.Drawing import Color, Pen

def Handler(*args):
	dbitmap = args[1].Frame.GetDrawableBitmap()
	gbitmap = dbitmap.GetGraphics()
	#Just a test to paint something
	for x in range(100):
		gbitmap.DrawLine(Pen(Color.FromName("Red"), 3), 100, 100, 100, 300)

SharpCap.SelectedCamera.BeforeFrameDisplay += Handler
But it paints nothing. Am I missing something?

T&R
User avatar
admin
Site Admin
Posts: 13173
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Custom Reticule // Paint over image

#4

Post by admin »

Hi,

You need to call .Dispose() on the gbitmap and the dbitmap (in that order). Calling it on the gbitmap is just good resource management. Calling it on the dbitmap is what copies the changes you have made back to the frame data.

The 'using' statements in C# automatically call .Dispose() as you exit them.

Cheers, Robin
Post Reply