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
Custom Reticule // Paint over image
- admin
- Site Admin
- Posts: 13344
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Custom Reticule // Paint over image
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.
Robin
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
}
}
}
Re: Custom Reticule // Paint over image
Hi Robin,
If I am not wrong it should be something like:
But it paints nothing. Am I missing something?
T&R
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
T&R
- admin
- Site Admin
- Posts: 13344
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Custom Reticule // Paint over image
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
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