LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Vision acquisition - resolution problem

You're right, that was the problem with two loops, the stop button is in the Producer loop. Thank you!

But there is another problem... My program has to work with greyscale and sometimes when I open the program it works for a long time. Then suddenly error pops "IMAQ Vision: Invalid image type." on my filter, pattern matching... (Att. Error_1), don't know why... 

I tried to use my older cam that has unfortunately too much delay for this project and I can't use it, errors are not popping, but the webcam is very simple, doesn't have much functions, basic camera.

When I'm using my newer webcam that has no delay sometimes this error pops up with an invalid image type. Maybe my newer cam is trying to calibrate itself and some parameters and some parameters go out of range?

Is there any way to check what's the problem? Maybe the color palette is too new? I have to use greyscale, but my cam is working on RGB? Maybe the lighting is changing in my room and the camera is trying to calculate it, then some problems occur?

Thank you for your time!

Download All
0 Kudos
Message 21 of 29
(274 Views)

You can set the Camera to use Greyscale.  Open MAX, select your Camera, go to Acquisition Attributes, and select Output Image Type.  I'm looking at my C920, and it's set to "Auto".  You might want to change that to Greyscale, or RGB U32, and see if that helps.

 

Bob Schor

0 Kudos
Message 22 of 29
(269 Views)

I've got a problem with MAX, I think it doesn't save any values, when I tried to change the resolution in MAX, and then opened the Vi it applied my maximum resolution possible...

 

When I'm trying to change in MAX to any greyscale, this error pops (Att. Error_grey), I can only use RGB U32, but I am not sure if it applies to my Vi, referring to the fact that it does not save me the resolution.

 

I see that my GreyMorphology is causing errors with the Invalid image type, I can see that in my image out, colors are changing from normal RGB to greyscale quickly and then the error Invalid image type pops. I don't know how it works, sometimes it can be in greyscale for a few minutes, sometimes it can't stabilize colors, maybe the filters are wrong? I'm using first: extract single color plane, then GrayMorphology, BCGLookup and Match Pattern, in order. I tried to use the same filters from Vision Assistant in order, but that was on that bad camera with too long delay, an old one with max resolution 640x360p 15FPS. The simpler, cheaper the camera, the fewer errors, I've noticed. That camera didn't have any functions.

 

Do you know any solutions for how to maybe with filters, (because probably my MAX doesn't save values to my Vi's) change from RGB to Greyscale? Maybe use some blocks before loops? Maybe I'm using this filters in my second loop in the wrong way? 

Download All
0 Kudos
Message 23 of 29
(244 Views)

@RiffLord wrote:

 

Do you know any solutions for how to maybe with filters, (because probably my MAX doesn't save values to my Vi's) change from RGB to Greyscale? Maybe use some blocks before loops? Maybe I'm using this filters in my second loop in the wrong way? 


To be sung to the tune of "Anything You Can Do, I Can Do Better" (from "Annie Get Your Gun", music by Irving Berlin) -- "Anything MAX can do, DAQmx Can Do Also" (and sometimes, Better).

 

The other thing to say is that one of the most challenging things to do in LabVIEW involves NI Vision.  When I started learning/using LabVIEW  (after years of text-based programming, including Macro-11), I started by learning/maintaining a fairly large (and mostly undocumented) 1000-VI LabVIEW  7 Real-Time Project, which used an Excel Workbook as both a "set of commands to be executed" and (one of) a storage location for trial results.  After several years of experience, a colleague came to me and asked me to help him with a project that involved recording 5-10 second videos of animal behaviors, my first introduction to LabVIEW Vision (fortunately in LabVIEW 12 or 13, I think).

 

This was a real "learning experience".  My colleague had been making AVI files already, but he wanted to use multiple cameras to handle multiple subjects (6-12) simultaneously, with recording sessions that lasted for about 2.5 hours, but saving only the 15-20 "interesting 5-10 second bits" for each subject.  We wrote a lot of "test code" where we used IMAQdx to configure our cameras and to learn how the IMAQdx functions worked.  Thank goodness there were two of us, one (my colleague) with some IMAQdx "experience" and another (to remain anonymous) who was "finicky" about writing "neat" LabVIEW code (even throw-away test routines) that were neat, orderly, with straight wires, everything sitting on Error Lines, sensible naming conventions, lots of little "helper VIs" (all with descriptions and "recognizable VI Icons" (even if only three short words, such as "Set FPS" or "Find Camera").

 

You need a colleague!  You need to write (lots of) LabVIEW NI Vision Code.  You need to be systematic.  If you want/need help from the Forums (i.e. to hope some of us can be mentors), you need to share your code (possibly all of it).

 

Bob Schor

0 Kudos
Message 24 of 29
(235 Views)

Well, I had a bit of fun writing the preceding note, but, boy, was I "off base" (that's a Baseball term).  You are 100%  correct -- when I try (using MAX) to make my WebCam "Grab" using a GreyScale encoding, I get exactly the same error that you do.  Surprise, Bob!  Sigh.

 

So here's what you may need to do -- save as a 640x480 30 FPS MJPG, then use IMAQdx to convert it to 8-bit Grayscale.  I'm not an "expert" on the color encodings, but at a recent NI Connect, I saw a suggestion that if you wanted to manipulate the colors of an Image, you were better off working with an HSL encoding (Hue, Saturation, and Intensity) than with RBG, because if what you want to manipulate is the "color", this maps to Hue (rather than trying to "mix" Red, Blue, and Green).  So I'd think that to convert RBG to B&W, you'd do RBG->HSL and use the Intensity channel as the U8 "Grayscale".

 

There may even be an IMAQdx function that will do this for you -- I haven't looked, but it's time for lunch ...

 

Bob Schor

Message 25 of 29
(224 Views)

Enjoy your meal! (probably too late :P)

So you recommend converting it to 8-bit Grayscale in or out of the loop? (and I don't understand, I have to first convert it to grayscale, then to HSL?) And you think it can be done before the producer loop? Or do it in a consumer loop before the Extract single color plane with intensity? I thought about doing it before the producer loop, but I don't know if it's possible? (Before capturing the first image?)

0 Kudos
Message 26 of 29
(213 Views)

Okay, I think I made a progress? For a while I didn't have any errors like "Invalid image type". I found https://forums.ni.com/t5/Example-Code/IMAQ-Color-Image-to-Grayscale/ta-p/353502 

I have to use the Intensity plane, so I just did it similarly with that change (He used Luminance, not Intensity). So first I used hsl U32, then with IMAQ cast image I changed it to grayscale U8 and then connected to extract single color plane, I don't have errors from the Invalid image type (I think so? Maybe later they will pop), but right now my Dequeue Element has an error (Att. Error_Dequeue). It seems to me that it does not affect the operation of the program, but it pops up when the program ends. 

Maybe you know why?

Thank you so much again, I'm making progress I think 😛

Download All
0 Kudos
Message 27 of 29
(198 Views)

OK, here's a lesson on Debugging and Finding the Problem.

 

I think the issue you are having involves the Producer/Consumer Design Pattern.  So when Life gives you a Lemon, make Lemonade!

 

Write a tiny VI that does the following:

  • Configures a Camera for Grab.
  • Creates an RGB Image for the Camera.
  • Creates a Queue for the Image (for Producer/Consumer Pattern).
  • Grabs and Enqueues (in a While Loop) an Image, with a Stop Control to stop the Producer.
  • Closes the Camera, ending Camera processing.
  • Enqueues a Sentinel (an empty Image), ending the Consumer Queue processing.
  • In a parallel While Loop, dequeue an Image.
  • See if the "Image" is not a Number, Path, or Refnum
    • If it is, that's the Sentinel, so do nothing with the Image, and exit the Consumer Loop.
    • Otherwise, display the Image.
  • When the Consumer exits, Release the Queue.
  • Merge the three Error Lines and pass to the Simple Error Handler.

Please do these steps, and see if you get a VI with no errors.  If so, run it and see what it produces.  If you have a WebCam on your PC, use that as the Camera.  Here's what you should get (do keep those Error Lines straight, please] --

BS Queue IMAQdx Viewer.png

 

What I really wrote was a slightly simpler version of this routine that used Stream Channel Wires instead of Queues.  Here is the Channel Wire version of the same routine:

BS Stream IMAQdx Viewer.png

 

The "unfamiliar" item in the Producer Loop is a Stream Channel Writer, which "adapts" to whatever is wired into it and "streams it" (ignoring "boundaries" like the While Loops) until it finds a Channel Reader (the item in the lower While Loop).  The "Stop" Control is wired to not only the Producer's Stop Indicator but also to a "last element?" terminal that passes the "Stop" signal to the Consumer, where it is used to stop the Consumer (and simultaneously stop the use of the Stream Channel).  Simpler to visualize, and the "data" in the Stream always flows "in the logical direction".

 

Both these simple demos produce the same results.  Code one (or both!) of them up, test them, then find the corresponding logic in your code and "fix the problem".

 

Bob Schor

 

Message 28 of 29
(189 Views)

Hi!

 

Sorry for not answering, had a hard time in school, but I passed the project! I couldn't do it without your help. Thanks a lot for everything to you and the other members who helped me!
Have a good day and wish you the best!

0 Kudos
Message 29 of 29
(130 Views)