05-29-2007 08:21 PM
Imports
NationalInstruments.CWIMAQControls<ComClass(VisionTool.ClassId, VisionTool.InterfaceId, VisionTool.EventsId)> _
Public
Class VisionTool***all variable initialization
Public IMAQVision As NationalInstruments.CWIMAQControls.AxCWIMAQVision Dim myImage As NationalInstruments.CWIMAQControls.CWIMAQImage#
Region "COM GUIDs" Public Sub New() *constructor MyBase.New()IMAQVision =
New NationalInstruments.CWIMAQControls.AxCWIMAQVisionIMAQVision.createcontrol()
*all other initializations
errorCode = CWIMAQ1394.CameraOpen2("cam0", CWIMAQ1394.CameraMode.IMG1394_CAMERA_MODE_CONTROLLER, sid)
errorCode = CWIMAQ1394.SetupGrabCW(sid) End Sub Public Function GetLedColor() As Integer Dim roi As New CWIMAQRegions Dim roiRect As New CWIMAQRectangleroiRect.Initialize(111, 54, 7, 15)
ViewRect.AddRectangle(roiRect)
IMAQVision.LearnColor(myImage, ColInfo, ViewRect)
IMAQVision.MatchColor(myImage, ColInfo, Scores, ViewRect)
Return 2 End FunctionEnd
Classthe other file is a console application that calls the vision.vb library.it just creates an object of the VisionTool class, and calls the GetLedColor() function,and prints the value returned( 2) to console..
i am not sure whether i used any Windows App methods,but the program halts at LearnColor only..when i commented it out,it worked fine..
thanks alot for all ur help..
have a good day!!!
05-30-2007 09:26 AM
Dim
myImage As NationalInstruments.CWIMAQControls.CWIMAQImageFor i = 0 To 100
For j = 0 To 100
data(i, j) = i + j
Next j
Next i
myImage.ArrayToImage(data)
status = IMAQVision.LearnColor(myImage, ColInfo)
In the console app, I simply instantiated the VisionTool class and then called the GetLedColor method and all worked correctly. Perhaps that type property is essential.
Let me know if this helps any!
Best Regards,
05-30-2007 08:03 PM
hi jonathan,
thanks for ur help..i really appreciate u going thru all that trouble..
but perhaps i was not clear in my previous post..actually the problem is solved ..after i inserted the IMAQVision.createcontrol(), it worked fine..and i must apologise for something else,too.i did insert the type property..but in my quest to simplify my codes in the post,i accidently deleted that piece of code.i am so sorry for troubling u
here is my constructor,which does all the initializations.
MyBase.New()IMAQVision =
New NationalInstruments.CWIMAQControls.AxCWIMAQVisionIMAQVision.CreateControl()
'image initializationmyImage =
New NationalInstruments.CWIMAQControls.CWIMAQImagemyImage.Type = NationalInstruments.CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeRGB32
'timer initializationt1 =
New System.Timers.Timer(250)errorCode = CWIMAQ1394.CameraOpen2("cam0", CWIMAQ1394.CameraMode.IMG1394_CAMERA_MODE_CONTROLLER, sid)
If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) ThenConsole.WriteLine(" camera error!!")
GoTo ErrorHandler End Ift1.Enabled =
TrueerrorCode = CWIMAQ1394.SetupGrabCW(sid)
If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) ThenConsole.WriteLine(" grab error!!")
GoTo ErrorHandler End IfErrorHandler:
If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then 'DisplayError(errorCode) End If End Subso,now the library works fine..but there is something that affects its performance though..there seems to be some delay in saving the image into the variable,so i had to insert a system delay in GetLedColor.then there is also some kind of delay in storing the results of LearnColor in ColInfo,so i had to insert another delay before MatchColor..though these 2 delays add up to less than 1 sec,it still slows down the execution.if it is possible,i would like my application to be a real time kinda thing..and when i call this library from MS DOS command prompt,it takes forever to return the value(especially the first time).i wonder if this is a problem in NI Vision itself,or whether it has something to with the computer speed as well.
any ideas?
thank you
05-30-2007 08:22 PM - edited 05-30-2007 08:22 PM
Message Edited by Jonathan N on 05-30-2007 08:23 PM
06-06-2007 10:06 AM