LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need basic image processing, but only have Linux

Solved!
Go to solution
Hello, I'm fairly inexperienced and working on a project in which a camera is attached to a moving X-Y stage. The goal is for the camera to track worms moving below in real-time, then follow them. To do this, I need some very basic image processing. However, I don't know how to control the motors for the X-Y stage without a Linux-only tool, so I'm using Linux LabVIEW, which apparently doesn't support NI Vision or MATLAB script nodes. I need to do basic image processing (described below) very quickly, using the images I capture in LabVIEW. I know Python, Java, MATLAB, and a little C. Right now all I can think of is making a C library that does the processing (despite my relative inexperience), then calling it from LabVIEW. This would be nice since LabVIEW can pass the image to C by reference, whereas I don't know how to interface with MATLAB or Python without, say, a TCP connection, which wouldn't be able to use pass-by-reference (I think?) Are there any other ways to get this done? Maybe a clever way to interface with MATLAB, or is there a way to get Vision in LabVIEW for Linux? The most important thing is just to find the center of mass of the very black worm, so that should be easy: just restrict the image to a region of interest, threshold it, pick the largest connected blob, and calculate its center of mass. However, I might later also want to find calibration marks on the image; I think it would be easiest to just draw long, straight lines, under the camera, then detect those somehow. Thank you!
0 Kudos
Message 1 of 14
(3,103 Views)

Hi mjstone,

 

Unfortunately, Vision Development Module (VDM) is not supported on Linux; however, LabVIEW 8.6 and later for Linux should support MathScript nodes (see this link).

 

 

Another option would be to use OpenCV for the machine vision as it is free and you could code in Python.

------------------------------
Bill E. | Applications Engineer | National Instruments
0 Kudos
Message 2 of 14
(3,069 Views)
Thanks for the reply! OpenCV does seem like a good choice. My only question is, what is the best way to invoke Python code from LabVIEW? I need to be able to pass the image array to the Python code by reference for speed, I imagine.
0 Kudos
Message 3 of 14
(3,066 Views)

There are a couple of different ways to pass the image to the dll (that will be doing the processing).

 

The best way would be to convert it to an array (using the IMAQ ImageToArray.vi) and then pass the array reference to the dll. Here is an excellent community example that discusses this.

 

 

Passing the actual pointer could be difficult as it is a specific data structure (see this post). This post discusses a potential way of doing it but passing the array would be a more robust solution (albeit a slower one).

------------------------------
Bill E. | Applications Engineer | National Instruments
0 Kudos
Message 4 of 14
(3,045 Views)
Heh, that won't be a problem - we Linux users don't get IMAQ either! I had to hack around with some open source libraries to take the picture in the first place, so it is already in array format. But I still don't know how to pass a reference to Python from LabVIEW (since as far as I know you can't make Python dlls). If nobody knows how, I'm in the middle of upgrading my C knowledge to C++ right now, so I'll be able to make a C++ wrapper dll around OpenCV soon.
0 Kudos
Message 5 of 14
(3,039 Views)

So MJStone, I was hovering over the me too button. Until I hit the part about worms. Please extrapolate, why worms?

0 Kudos
Message 6 of 14
(3,038 Views)

*sigh* I'm an engineer in a bio lab. They're not the kind of worms you're used to, but these guys devote their entire existence to http://en.wikipedia.org/wiki/Planarians . Incidentally, they do like to feed normal worms to them, live. It's a bit scary watching 10 of the little buggers latch onto one. They want high-zoom pictures over a long time (weeks), but  they currently have to swivel the camera by hand constantly as the planarians move.

0 Kudos
Message 7 of 14
(3,033 Views)

IMG_2552.jpg

 

Are they similar to this bugger on my arm?

I know nothing of flatworms. 

0 Kudos
Message 8 of 14
(3,030 Views)

They're only about 1 cm long. Also they have cute little eyespots that look like googly eyes if you squint a bit: http://islandwood.org/kids/stream_health/Images/planarian2.jpg

0 Kudos
Message 9 of 14
(3,028 Views)

So, I ended up trying to write a simple C++ wrapper function. Right now, I'm not even doing the image processing, just setting a region of interest and saving. However, in order to do this, I need to make an instance of the OpenCV Mat class, and apparently LabVIEW can't handle any sort of C++ classes. When I try to import the library, LabVIEW tells me that it cannot find the file (which is pretty much the catchall error, for some reason, and pops up in a lot of cases where you do something wrong with the Call Library Node).

 

Thus, I tried making a C wrapper around my C++ wrapper. Same error. Any ideas why? Here's the code:

 

C++ WRAPPER: opencvl.cxx

#include <opencv2/opencv.hpp>
#include "opencvlv.h"

using namespace cv;

int saveROI(unsigned char *pixels, unsigned int width, unsigned int height, unsigned int roix, unsigned int roiy, unsigned int roiwidth, unsigned int roiheight, char *filename)
{
    Mat roi(height, width, CV_8UC1, pixels);
    roi = Mat(roi, Rect(roix, roiy, roiwidth, roiheight));
    imwrite(filename, roi);
    return 0;
}

 

C++ HEADER: opencvlv.h

extern int saveROI(unsigned char *pixels, unsigned int width, unsigned int height, unsigned int roix, unsigned int roiy, unsigned int roiwidth, unsigned int roiheight, char *filename);

 

C WRAPPER: opencvlvwrap.c

#include "opencvlvcwrap.h"
#include "opencvlv.h"

int saveROICWrap(unsigned char *pixels, unsigned int width, unsigned int height, unsigned int roix, unsigned int roiy, unsigned int roiwidth, unsigned int roiheight, char *filename)
{
    saveROI(pixels, width, height, roix, roiy, roiwidth, roiheight, filename);
    return 0;
}

 

C HEADER: opencvlvwrap.h

extern int saveROI(unsigned char *pixels, unsigned int width, unsigned int height, unsigned int roix, unsigned int roiy, unsigned int roiwidth, unsigned int roiheight, char *filename);

 

Not much time left to work on this project and I'm getting held up by the little things...

0 Kudos
Message 10 of 14
(3,001 Views)