Separating out a specific range of colors from images from the Axis CameraBy Austin Steeno - 1/11/09 (Last revised 1/11/09) ------------------------------------------------------------------------- This tutorial assumes you have basic knowledge of how to use LabView 8.5. ------------------------------------------------------------------------- Items to note:
------------------------------------------------------------------------- In this tutorial we are going to separate out a range of colors
(AKA the color of the pink fabric found in the KOP) from pictures
taken by the Axis camera and display the original image as well as
an image showing where colors within the specified range exist.
Now, go ahead and open up the "Basic Robot Main" VI.
Go ahead and switch over to the block diagram and scroll down to the camera Image processing loop. (You can go ahead and delete the note boxes to make space if you'd like)
The following explanation is optional if you do not wish to read it! ------------------------------------------------------------------------- Ok, before we move on I feel I need to explain something. Since we want to display both the original image and an image showing where the colors we selected are we are going to have to do one thing that can come up and bite you if you don't remember it. (Trust me, its was so simple and obvious yet it gave me a good bit of confusion my first time around.) What I did was I took the image output from the Get Image subVI and hooked it up to a display output and to a function to separate out the colors. I took the image output from the color separation function and hooked it up to its own output. When I ran the VI, to my surprise, both of the displays showed the image resulting from the color separation function. What's happening is the images from the camera are being placed in a specified location in memory and whenever you run some function that modifies the image if you do not specify where to write the data for the modified image, it uses the same location the original image came from. (I'm not 100% sure on the reasons, but it seems the images don't get dispatched to the display functions until all the image processing is done.. This would likely be solvable if the image output functions had Error connectors, but alas, they do not.) Because of this we must create a second place in memory to store our modified image, which is why we are doing the next few steps. ------------------------------------------------------------------------- Now, open your functions palette and navigate to: FIRST Vision » Image Management and select "IMAQ Create".
Place this function just outside the image processing loop.
Right click on the Image Name connector and navigate to: Create » Constant. Enter in "Pink Target" ... Or whatever else you would like to name this image.
Now, right click the Image Type connecter and select: Create » Constant and make sure it is set to Grayscale 8-bit.
Ok, we'll come back to that later. Now lets go ahead and add the color threshold function that will separate out the colors we want. Right click somewhere inside the image processing loop and navigate to: FIRST Vision » Image Conversion and select "IMAQ ColorThreshold".
Go ahead and place this function inside the larger case structure inside the image processing loop.
Now, click on the Color Mode connector of the new subVI and select: Create » Constant. Make sure it is set to RGB.
Then right click the Replace Value connector and choose: Create » Constant, setting the value of the constant to 255. (Pure white)
Next, we're going to want to specify which range of colors to select. Now we could just create a bunch of constants and I could give you values to use... However, the settings will vary from person to person because of the differences in lighting. So instead, we'll create some controls and I'll give you some values to start with and you can fine tune it from there. So, go ahead and right click the "Red or Hue Range" connector and select: Create » Control.
Repeat the previous step for the "Green or Sat Range" and "Blue or Luma or Val or Inten Range" connectors. Place the control icons wherever you'd like to keep things organized.
Now, switch over the your Front Panel and organize it. You could organize it somewhat like this:
Now that we're on the front panel, we'll go ahead and add some displays so that we can view the image coming in from the camera and the one we've created. Right click anywhere on the front panel and select: Vision » Image Display.
Repeat the previous step and move and resize the displays as necessary to fit them both on the screen. Also, rename them, naming one "Full View" and the other "Target". (Or any other name, just remember which is which)
Alright, now, switch back over to the block diagram. Locate the two Image displays you just created and place them inside the image processing loop as shown:
Next, create a wire between the Get Image subVI and the Full View Display.
Now, create a branch off the wire we just created and connect it to the "Image Src" connector of the IMAQ ColorThreshold subVI.
Then, create a wire between the "New Image" output of the IMAQ Create subVI we added near the beginning to the "Image Dst" connector of the IMAQ ColorThreshold subVI.
Finally, connect the "Image Dst Out" output of the IMAQ ColorThreshold subVI to the Target Display.
Alright, we're almost ready to test it out! Now, switch back over to the front panel and fill in the values for the color range. I used the following values: Red - 130 min, 255max; Green - 0min, 150max; Blue - 0min, 200max. This set of values should separate out the color of the pink fabric that came in your 2009 KOP!
Thats it!
Go ahead and save everything and hit run! AND DON'T FORGET TO HIT THE ENABLE VISION BUTTON! Hopefully, once it's running (give it at least 15seconds after the code is done downloading) you'll see something similar to this:
If your Target Display is pure (or mostly) white try raising the red minimum and lowering the green and blue maximums. If your Target Display is pure (or mostly) black try lowering the red minimum and raising the green and blue maximums.
-------------------------------------------------------------------------
I hope you found this tutorial helpful. If you see any errors, have any suggestion or have any questions please feel free to contact me at ajsteeno@cox.net or you can PM TotalChaos on ChiefDelphi.
|
||||