12-16-2010 09:57 AM
I have succesfully created AdaptiveThreshold application using Vision Assistant for image with gradient illumination. It is working perfectly.
Then i generated .NET code from the project. The problem is, .NET code always produce error when i ran the application. The error came up when i want to apply LowPass filter.
Here is the code generated by Vision Assistant (i also attached the complet VS project and the sample image on the folder):
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Text;
using NationalInstruments.Vision.WindowsForms;
using NationalInstruments.Vision;
using NationalInstruments.Vision.Analysis;
using Vision_Assistant.Utilities;
namespace Vision_Assistant
{
static class Image_Processing
{
//public static ReadTextReport vaOCRReport;
public static PaletteType ProcessImage(VisionImage image)
{
// Initialize the IVA_Data structure to pass results and coordinate systems.
IVA_Data ivaData = new IVA_Data(9, 0);
// Image Buffer: Push
Functions.IVA_PushBuffer(ivaData, image, 0);
// Extract Color Plane
using (VisionImage plane = new VisionImage(ImageType.U8, 7))
{
// Extract the luminance plane and copy it to the main image.
Algorithms.ExtractColorPlanes(image, ColorMode.Hsl, null, null, plane);
Algorithms.Copy(plane, image);
}
// Filters: Low Pass - Filters an image using a non-linear filter.
VisionImage lowpassImage = new VisionImage(ImageType.U8);
Algorithms.LowPass(image, lowpassImage, new LowPassOptions(25, 25, 5));
// Image Buffer: Push
Functions.IVA_PushBuffer(ivaData, image, 1);
// Operators: Subtract Image
Algorithms.Subtract(image, Functions.IVA_GetBuffer(ivaData, 0), image);
// Thresholds an image into 2 classes by using local thresholding.
LocalThresholdOptions vaLocalThresholdOptions = new LocalThresholdOptions();
vaLocalThresholdOptions.DeviationWeight = 0;
vaLocalThresholdOptions.Method = LocalThresholdMethod.NiBlack;
vaLocalThresholdOptions.ParticleType = ParticleType.Bright;
vaLocalThresholdOptions.ReplaceValue = 1;
vaLocalThresholdOptions.WindowHeight = 50;
vaLocalThresholdOptions.WindowWidth = 50;
Algorithms.LocalThreshold(image, image, vaLocalThresholdOptions);
// Filters an image using a non-linear filter.
// First, increase the border size, if necessary.
if (image.BorderWidth < Math.Max(3, 3))
{
image.BorderWidth = Math.Max(3, 3);
}
// For each pixel, the algorithm takes the neighborhood specified by the given filter sizes
// and replaces the pixel with the nth smallest value in the neighborhood.
Algorithms.NthOrder(image, image, 3, 3, (int)Math.Floor(3 * 3 / 2.0));
// Lookup Table: Equalize
// Calculates the histogram of the image and redistributes pixel values
// accross the desired range to maintain the same pixel value distribution.
Range equalizeRange = new Range(0, 255);
if (image.Type != ImageType.U8)
{
equalizeRange.Maximum = 0;
}
Algorithms.Equalize(image, image, null, equalizeRange, null);
// Lookup Table: Reverse - Inverts the pixel intensities of the image.
Algorithms.Inverse(image, image, null);
return PaletteType.Binary;
}
}
}
Please help.
Best Regards
12-16-2010 11:11 AM
Can you please attach the Vision Assistant script?
Thanks.
Christophe
12-16-2010 05:48 PM
Here is the script.
Best Regards
12-20-2010 12:45 AM
Here's stack error :
NationalInstruments.Vision.VisionException was unhandled
Message=Exception of type 'NationalInstruments.Vision.VisionException' was thrown.
Source=NationalInstruments.Vision.Common
VisionErrorText=Invalid image border.
StackTrace:
at NationalInstruments.Vision.Internal.Utilities.ThrowError()
at NationalInstruments.Vision.Internal.Utilities.ThrowError(Int32 success)
at NationalInstruments.Vision.Analysis.Algorithms.LowPass(VisionImage source, VisionImage destination, LowPassOptions options, VisionImage mask)
at NationalInstruments.Vision.Analysis.Algorithms.LowPass(VisionImage source, VisionImage destination, LowPassOptions options)
at Vision_Assistant.Image_Processing.ProcessImage(VisionImage image) in C:\Users\kusumy\Documents\National Instruments\Vision Assitance\OCR Processing. NET 2008\ImageProcessing.cs:line 35
at Vision_Assistant.Form1.RunButton_Click(Object sender, EventArgs e) in C:\Users\kusumy\Documents\National Instruments\Vision Assitance\OCR Processing. NET 2008\Form1.cs:line 36
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Vision_Assistant.Program.Main() in C:\Users\kusumy\Documents\National Instruments\Vision Assitance\OCR Processing. NET 2008\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Please help
Best Regards
12-20-2010 01:01 AM
The problem is solved after manually set image border width before applying low pass filter.
Best Regards