08-22-2009 02:44 PM
Hello,
I'm using VDM2009 with C#. When I hover my mouse over an ROI, the ROI changes from the color that I have set (e.g., green) to the inverse of the image behind the ROI. I have no idea why, or how to fix it. It looks very bad.
Any ideas how I can get the ROI to stay the color I set it to?
Thanks,
Neville
08-22-2009 04:10 PM
No way. You just haven't such deep control over it. It looks so bad many years, but no chages up to now, even submitted as feature request many times.
What you can is following: you can draw color overlay for better view. Unfortunately overlay located behind of roi, so you will need to "inset" overlay. Let's say - your roi is rectangle with coords 100,100,200,200. Now you should draw two rectangles as overlay: one with coords 99,99,201,201 and another one with coords 101,101,199,199. Now your ROI will be "duplicated" with thick color rectangle, and you will see it even with mouse over it. Will be a little bit complicated in case of polygons, but impossible is nothing.
best regards,
Andrey.
08-22-2009 04:21 PM
Hello Andrey,
Thanks so much for your reply. That's astonishing that it's been this bad for so long and there's no way to change it...
Regarding your suggestion, when I create an overlay on my video feed, it appears for an instant and then disappears.
How do I make the overlay persist with live video?
Thanks,
Neville
08-22-2009 04:31 PM
Just draw overlay every time after each image redraw.
In general it depends from your architecture. For example, IMAQ Copy will overwrite overlay. But IMAQ Fill will not delete it. The easiest way is just draw overlay again and again (especially if overlay not static, but changed for every frame - for example you want to overlay time clock or frame number over the image).
08-22-2009 05:00 PM
Hello Andrey,
Thanks so much for your suggestion. Unfortunately, I can't get it to work...
As you can see from my code below, I am writing text to a global overlay variable and then copying the overlay variable onto each image. Unfortunately, it appears to have no effect. The text overlay just flashes on my screen when the function OverlayTextOnImage is called.
What am I doing wrong?
Thanks,
Neville
Here is my code:
private ImaqdxSession MainSession = null; // This gets set somewhere else and is working great
private Overlay MainOverlay { get; set; }
//---------------------------------------------------------------
void acquisitionWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = (BackgroundWorker)sender;
// Keep acquiring until there is an error or a cancellation
while (!worker.CancellationPending)
{
try
{
// Grab the next image
uint bufNum;
MainSession.Grab(MainViewer.Image, true, out bufNum);
if (MainOverlay == null)
MainOverlay = MainViewer.Image.Overlays.Default;
MainOverlay.CopyTo(MainViewer.Image);
}
catch (ImaqdxException exception)
{
...
}
}
}
//---------------------------------------------------------------
private void OverlayTextOnImage(VisionImage image, string textToDisplay, PointContour textOrigin)
{
OverlayTextOptions textOptions = new OverlayTextOptions("Arial", 20);
MainOverlay.Clear();
// Overlay text onto the image. This will not change the image pixels.
MainOverlay.AddText(textToDisplay, textOrigin, Rgb32Value.RedColor, textOptions);
}
08-22-2009 05:29 PM
Oh, how hard is text-oriented language. You should switch to LabVIEW - much more easy for programming...
Can you show whole acqquisition loop? I can't see where you have called OverlayTextOnImage function in your code.
08-22-2009 05:35 PM
Hello Andrey,
I'm calculating the angle between two lines and I want to overlay the result on the image (e.g., "Angle: 45.7"). I call OverlayTextOnImage whenever the ROI changes (e.g., while the user is dragging a line, it updates the angle in realtime; when the user releases the mousebutton, the result should remain on the screen until the user starts dragging again).
Many thanks!
Neville
//---------------------------------------------------------------
private void MainViewer_RoiChanged(object sender, NationalInstruments.Vision.WindowsForms.ContoursChangedEventArgs e)
{
CalculateAndDisplayAngle();
}
//---------------------------------------------------------------
private void CalculateAndDisplayAngle()
{
PointContour textOrigin = new PointContour(Xmid - 100, Ymid - 100);
Contour myContour = MainViewer.Roi.GetContour(0);
switch (myContour.Type)
{
case ContourType.Polyline:
PolylineContour plc = (PolylineContour)myContour.Shape;
LineContour line1 = new LineContour(plc.Points[0], plc.Points[1]);
LineContour line2 = new LineContour(plc.Points[1], plc.Points[2]);
double angle = CalculateAngle(line1, line2);
string angleText = "Angle: " + angle.ToString("0.00");
OverlayTextOnImage(MainViewer.Image, angleText, textOrigin);
break;
}
}