Google Answers Logo
View Question
 
Q: Linux or Windows data acquisition system advice ( Answered,   2 Comments )
Question  
Subject: Linux or Windows data acquisition system advice
Category: Computers > Hardware
Asked by: srussell-ga
List Price: $100.00
Posted: 12 Dec 2002 13:49 PST
Expires: 11 Jan 2003 13:49 PST
Question ID: 123788
Advice on building a simple process control lab PC running either
Linux or Windows

I am seeking recommendations on how to assemble a PC which to be used
in a series of simple process control experiments.  I need the PC to
do the following:
1.	Acquire images from a camera controlled by the PC.
2.	Store the images in an array so that I can write a program to
manipulate the captured value in each image in series.  (More on this
shortly).
3.	Output three numerical values to be calculated in the program I
write as analog voltages (for control purposes).

These functions will be executed serially under program control.  I
desire to execute the control loop at a rate of 30 frames per second
(fps).  However, a slower solution down to 3 frames per second is
acceptable, and rates higher than 30 fps would be idea.  The images
should have a resolution of at least 250x250 pixels.  Light intensity
is not limited.

Because this control loop will be run serially, there is no need to
store the image data.  The numerical calculations to be done by the
program will be simple, consisting of such things as locating the
maximum pixel value and counting the number of pixels that exceed a
threshold intensity.  Thus, I expect that computer processing speed is
not dictated by the numerical processing.

The output voltages should be less than 10 volts and can have an
output impedance of anything less than 10,000 ohms.  Additional
digital outputs to control lights would be useful but are not
required.

I myself am an old guy decently competent in numerical processing but
without much competence or interest in manipulating DLL libraries,
getting handles to processes, managing libraries at link time, etc. 
So, I am hoping to find a solution that allows me to focus on the
problem rather than the mechanics.  I do not particular care if the
recommend solution runs Linux or some Windows flavor.  I have found a
few USB-based data acquisition products.  I have also found one
particular software program, described at the site
http://www.imagingcontrol.com/ic/features/overview/, that might be
useful.  However, rather than spend considerable time assembling ( and
probably failing for a while), I want some advice from people more
familiar with the mechanics and available products than myself.  Fry’s
Electronics is not much use, sigh.

A satisfactory answer would be a recommended Webcam, image capture
program, and analog I/O device, advice on how to tie these to
Visual Basic, for example, and directions on where to purchase the
identified components commercially.  I imagine that the complete
solution will
cost less than $1000 plus the cost of the PC.

I am willing to attend a hands-on class if necessary to get this
built.  I am also willing to pay someone to do the system assembly or
to simply buy a completed system.  My preference would be to have an
answer on the recommended approach first, however.
Answer  
Subject: Re: Linux or Windows data acquisition system advice
Answered By: webadept-ga on 13 Dec 2002 11:25 PST
 
Hi, 

I have a solution for you which will place the OS you are asking about
into "either/or" with equal value. There is a camera that I've used
for several years now that works with this type of setup very well and
your program can access the images as a simple file read, taking out
all the DLL and OS needs in accessing the camera. Very simple and very
effective. The speed is good enough, and can be adjusted.

The camera is here, or at least one place to purchase it is here:
http://www.thinkgeek.com/computing/input/netcams/36a0/

This web cam is complete (has its own OS, CPU and webserver) and hooks
straight into your network, and is pretty easy to setup and get
working. The options from this point are to get the image from the
camera using FTP from your program, or.. have the camera FTP the image
to the computer you are using, Or, access the image fromt the camera's
webpage using VB, or..(there is quite a list of things you can do from
this point)... the choice would depend on how many computers need to
access the same image at the same time. If your program is CPU heavy,
you may wish to get the picture from several CPU's and do seperate
calculations.

I'm not sure what you are really doing with this, but you might be
intereseted in this camera as well:

http://www.thinkgeek.com/computing/input/netcams/3810/

Much more expensive but it has a built in Motion Sensor on it as well
as all the other features of the previous camera. So if you only want
the image to change when something has moved, then this is a good
system for that type of monitoring. I wrote a program not too long ago
using this camera to watch a security post. Worked very well.

As for tieing this to your Visual Basic program, its pretty straight
forward from this point. Everything is done for the interface. You
will need a small hub, a network card for the PC, and some RJ45 line
to connect. If you don't have a network already installed in your
place, just write a Clarification request and I'll put together a
"quick down and dirty" home network instruction answer for you that
will get the camera working and let 5-10 computers access the camera
or one PC access 5-10 cameras. Of course this 5-10 number set is only
limited by how much you want to spend on hubs. There are hubs out
there that will let 200 computers connect to the same camera and the
camera won't care a bit.

This setup really opens up options for you if you are trying to watch
"changes over time" with various items needed to be watched. You may
be able, depending on the program, access up to 10 cameras with a
single PC and program. But again, I'm a bit in the dark as to what you
are trying to do and how.

Thanks, 

webadept-ga

Request for Answer Clarification by srussell-ga on 14 Dec 2002 14:41 PST
Thank you for your work on this.  I may not have been clear enough,
and my problem may be more elementary than you think.

I am fairly skilled in building networks, etc.  I am unskilled in
knowing how to get VB (or anything else) to interface to ANY media
data type.

First, how would I get VB to read the file?  Pointing me to a code
sample would be a grat help.  What is the device type/id/object that I
would use for the read?

Second, I do not know how to access the likely data type in VB as an
array of pixels.  I did connect to a number of external webcams over
the Internet, and I found of course that they return a JPEG image. 
Nice and displayable in windows, but how can I manipulate the pixels? 
For example, presuming that the camera you have referred me to gives a
JPEG file, how do I get VB to change that file into an object (type
.pict ??) that I can access as an array of monochrome (or RGB, or
anything else) values?  Where in VB do I look to find how to access
execute the http or FTB transfer?

At the moment, I have a simple USB webcam.  Can I get Windows to give
me a list of attached devices so that I can command the webcam using
some message?  If this is tough, accessing the camera as a peer device
is a good idea, but I still have the primary problem of generating the
request in VB and then changing the data type into something I can
manipulate on a numerical, pixel-by-pixel, basis.  I bet the answer is
simple, and that I am just ignorant of where to start.  (VB help
including the Microsoft Knowledge Base does not seem to have any
relevant docs on .pict or multimedia device manipulation).

Finally, I still have the smaller problem of writing a voltage out to
do control.  I plan on using a soundblaster interface to simply
generate a signal of variable amplitude and then full-wave rectify and
filter that to generate a DC control voltage.  Alternatively, I have
found that Jameco (www.jameco.com) sells DAQ boards, made by
Measurement Computing, that will meet the requirement given, again,
that I find how to interface VB to the drivers.  I think I can solve
this problem on my own once I know how to get a camera image into a
number-crunchable form.

Thanks

Srussell

Clarification of Answer by webadept-ga on 14 Dec 2002 18:04 PST
Visual Basic Renders any image into a bitmap regardless of the image
type mentioned.

It appears that you have a "good idea" and have more interest in the
outcome of this program than in how to make it, this being so you are
looking for a quick "down and dirty" way of getting through the
programming aspect and back to the real project.

I've found for you hear two sets of example and tutorial sites that
will give you a clear understanding of how to work with images and how
to work with serial port communications. I know this might not be
enough to complete your project (it might be, but at this point I'm
still very vague as to what you need, and it also appears you may not
want to be more descriptive to your project which is fine, we deal
with hushed questioners all the time )

What I need you to do at this point is to read these, and work with
them. When you get done either you will have all the answers you are
looking for, or be able to give me a clear description or what they
didn't cover. At that point I'll be able to find the missing pieces
and get your project answer completed.

Here are links for Image Reading and manipulation

VB Helper: HowTo: Read and Write an image's pixls using GetDIBits and
SetDIBits
http://www.vb-helper.com/howto_getdibits.html

Image Processing in VB 
http://vbaccelerator.nuwebhost.com/codelib/gfx/imgproc.htm

Tanner's VB World
http://tannerhelland.tripod.com/VBFreeSourceCode.htm

Tutorial: How to read RGB values for each pixel from an Image in
Visual Basic
http://www.imaginghardware.com/Tutorials/Docs/T00003A.asp


Serial Port Communications and Other notes close to this for control
of other devices

Visual Basic serial port communications
http://www.jspayne.com/io/easyins3.html

Serial Port Programming
http://members.tripod.com/~Malzev/radiodoc/serial.htm

A Tutorial to Understand Serial Port Interfacing communications using
Visual Basic

"Serial Interfacing is one of the most commonly used medium for data
acquisition and control using computers. Herein in this tutorial we
learn how to interface the serial port using Visual Basic Programming.
Serial Interfacing provides an easier way of data acquisition and
control using computers. This tutorial is for people who would want to
use serial port communications for their work."
http://www.pages.drexel.edu/~bns23/tutorial.html

Serial Port Communications
http://www.granite.ab.ca/access/serialport.htm


webadept-ga

Request for Answer Clarification by srussell-ga on 18 Dec 2002 12:55 PST
Sorry to be rather long in responding.... I looked at the sites which
you found and attempted to incorporate them to read a variety of image
data.  So far, I have spent considerable time without success.  More
detail:

To keep all simple, I used several images already in my PC.  These
consisted of bitmaps either resident as part of the OS (Win Prof 2000)
or images that I took with a still camera and saved as files,
manually.  I wrote some VB code using a copy of VB.Net, Standard
Edition.  The code was simple:  I created a PictureBox, and then
within the Click method of that object I attempted to read anything
using the sample code.  None of the sample codes shown in the
recommended links work, and all return errors saying that the object
classes do not exist as part of the PictureBox class.

I came across the following item on a MSDN website:  
"In Visual Basic 6.0, various graphics methods and properties were
used to draw on a form or PictureBox control. Graphics in Visual Basic
6.0 were based on Windows Graphics Device Interface (GDI) APIs.
In Visual Basic .NET, graphics are provided by the System.Drawing
namespace, which encapsulates the new GDI+ APIs. GDI+ expands upon the
graphics capabilities of Visual Basic 6.0, but the methods are not
compatible. When an application is upgraded from Visual Basic 6.0,
graphics methods are not upgraded.
The following example shows the code used to draw a circle in the
upper left corner of a form using Visual Basic 6.0 and Visual Basic
.NET:
' Visual Basic 6.0
Private Sub Form_Click()
   ' Set the ScaleMode to pixels.
   Me.ScaleMode = 3
   Me.Circle (50, 50), 50, vbRed
End Sub

' Visual Basic .NET
Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
   ' Create a Pen object.
   Dim pen As New Drawing.Pen(System.Drawing.Color.Red, 1)
   Me.CreateGraphics.DrawEllipse(pen, 0, 0, 100, 100)
   Pen.Dispose
End Sub
The following table lists Visual Basic 6.0 graphics properties and
methods and their Visual Basic .NET equivalents.
Point Method	No equivalent for forms or controls. For bitmaps, use
Bitmap.GetPixel Method."

I have attempted to re-cast the PictureBox object in VB.net as a
bitmap, but that does not seem to be supported in the Standard edition
of VB (and I have been unable to isolate any advice from Microsoft
about WHAT I CAN ACTUALLY DO, or as well NOT DO with VB Standard.  I
am coming to believe that I would need to become a full MSDN
subscriber ($2500) in order to have access to the relevant SDK in
order to use the needed object types and commands.  However, Microsoft
offers no advice.

So, I seem to be exactly where I did not want to be which is worrying
about obscure DLL and language mechanisms rather than working on my
experiments and the numerical calculation to support them.

I have found another site, http://www.adlink.com.tw/, that might offer
some help for both the image capture and for the voltage output which
was part of the original specification.  They supply drivers for Win
Pro 2000 and seem to support VB, but I fear that this is the old VB 6.
 Am contacting them.

I suspect that you, like me, are not an expert in the Windows program
mechanisms.  You suggested that I might have a "good idea" which I am
trying to develop, perhaps with an eye to helping that.  In fact, what
I need is not help in developing any hypothetical "good idea" but
rather help in just being able to read pixel values.

I will keep trying and keep you informed.  

Have engaged an engineer experienced with the windows environment to
assist.  I may turn to Linux, but Windows is more satisfactory as a
display and general lab environment.

One solution is to buy a ready-built machine vision solution, say,
Labview from National Instruments, but that is huge overkill and quite
expensive for what seems to me to be a simple problem.

Any other thoughts are appreciated.

Clarification of Answer by webadept-ga on 18 Dec 2002 14:54 PST
I'll write a fast program to do this for you and give you the source
code. It's pretty simple stuff. I'm a seasoned programmer on windows
and unix/linux. I'll get this together and post the program sometime
tonight or before the weekend at least, when I have a break in the
day.

Thanks, 

webadept-ga

Clarification of Answer by webadept-ga on 18 Dec 2002 22:00 PST
Wait... VB .Net??? Why are you doing this with VB.Net? .Net is for
making webpages and web applications. You started this with VB, not VB
.NET. And .Net would be the wrong tool for this type of work, it's
like using a hammer for a screwdriver, you can probably do it, but it
won't be pretty and it won't be stable. Are you stuck with that
language,? or can you switch over to VB 6 or C++ or Delphi or even
Perl would be better than using that (not great looking but much
faster in development).

webadept-ga

Clarification of Answer by webadept-ga on 19 Dec 2002 14:16 PST
Hi again, 

I don't have VB.NET so I can't make this for you. I spent last night
reading the Oreilly Book on all the differences between VB 6.0 and
VB.NET and there are so many that I can't possibly fake it with out
the program to check the code. So, here's what I can do, and that is
find example code which works with VB.NET rather than VB.

Serial Communications with VB.NET
http://66.216.11.86/cc/VBNetRs232.htm

AllAPI.net -- Serial Communications
http://www.allapi.net/classlib/class.php?id=15

Walkthrough 1 for VB.Net
http://arconline.esri.com/arcobjectsonline/GettingStarted/Walkthrough1VB.htm



VB2theMax: 
http://www.vb2themax.com/Item.asp?PageID=TipBank&Cat=1301&ID=538
While you can access individual pixels of a bitmap by means of the
GetPixel and SetPixel methods of the Bitmap object, in practice you
seldom want to use these methods, as they are simply too slow for most
cpu-intensive operations. Fortunately there is a faster way, which
consists of moving all the pixels to an array of bytes, process the
array, and move its elements back to the bitmap. You have to use the
Bitmap.LockBits method to get a BitmapData object, which you later use
to retrieve the address of pixels in memory.
This example shows how to create a "pixelation" effect on a
8-bit-per-pixel bitmap. Notice that you must modify this code for
other bitmap formats:
' load a bitmap
Dim bmp As New Bitmap("c:\winnt\coffee bean.bmp")
' get its size
Dim width As Integer = bmp.Width
Dim height As Integer = bmp.Height

' lock its bits, get a BitmapData object
' notice that you must know the bitmap format
Dim rect As New Rectangle(0, 0, width, height)
Dim bmpData As System.Drawing.Imaging.BitmapData =
bmp.LockBits(Nothing, _
    Drawing.Imaging.ImageLockMode.ReadWrite, _
    Drawing.Imaging.PixelFormat.Format8bppIndexed)
' get the address of its first scan line
Dim ptr As IntPtr = bmpData.Scan0

' prepare an array that will receive all the pixels
' this code is specific to a bitmap with 8 bits per pixels
' you must use a different array type for other formats
Dim bytes As Integer = width * height
Dim pixels(bytes - 1) As Byte
' copy the pixels into the array
Marshal.Copy(ptr, pixels, 0, bytes)

' process all the pixels in the array to create a pixelation effect
Dim r, c As Integer
For r = 0 To height - 1 Step 2
    For c = 0 To width - 1 Step 2
        ' get the index of the array element that corresponds to this
pixel
        ' notice that arrays are stored column-wise
        Dim index As Integer = c * height + r
        ' this is the color value of this pixel
        Dim colorValue As Byte = pixels(index)
        ' copy it to the 3 pixels to its right and below it
        pixels(index + 1) = colorValue
        pixels(index + height) = colorValue
        pixels(index + height + 1) = colorValue
    Next
Next

' copy the pixels back to the bitmap
Marshal.Copy(pixels, 0, ptr, bytes)
' unlock the bits
bmp.UnlockBits(bmpData)
' save the bitmap to another file
bmp.Save("c:\newbitmap.bmp")


Hope that covers it for you. If you decide to move to one of the other
languages I can give you a better working copy, or at least one that
I've written and checked personally.

webadept-ga
Comments  
Subject: Re: Linux or Windows data acquisition system advice
From: seizer-ga on 13 Dec 2002 04:16 PST
 
Hello srussell.

What an interesting question! I'm not sure I can answer all of your
question, but in the meantime, you might be interested in the article
below. It deals with using Java and the Java Media Framework to
acquire images from a Logitech webcam. Since you specify that you're
more interested in the problem solving aspect, rather than the
particular details along the way, I wonder if Java may not be the way
to go with this?

http://www.sun.com/developers/evangcentral/totallytech/jmf.html

Best of luck,

--seizer-ga
Subject: Re: Linux or Windows data acquisition system advice from seizer-ga
From: srussell-ga on 13 Dec 2002 08:19 PST
 
seizer-ga,

Thanks for this thought.  It does open up some possibilities, and I
will study these.  I also really like the implied portability.

I had been thinking that a quick hack for me might be to use an
"audio" output channel, via a Soundblaster compatible board, to output
the control value by "playing" .wav files simply containing the needed
voltage.  If this is feasible, and if I can make your Java suggestion
work, then perhaps the solution is less hardware intensive than I had
thought!  My.  Back to software configuration mechanics.  Need to read
about installing a Java software machine and programming for it.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy