LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Image Analysis Threshold won't work in program program freezes

Solved!
Go to solution

I am a new user to labview and I probably have an error in my code but the only problem is that there are no error messages I get from my code and it runs up to a point at which the program freezes and I can't click any buttons on the Front Panel. Basically everything works up to when I want to choose the Threshold of my image at this stage it creates an image of the values in the threshold buttons but I can't adjust the values anymore to find out the best values.

 

I should say that I have tried my Threshold code on its own and it seems to work fine so I am really confused as to what is getting muddled up!

 

Any help on what might be wrong would be helpful. I have added the VI and an image that I am analyzing.

 

The process currently goes as follows, you load the image, then choose a colour plane (usually green) that gets extracted. Then you draw a line on the border of the object and it rotates the image to make it straight and then you choose a ROI and it cuts the main object out. Finally at the point when you should be choosing a Threshold it hangs.

 

 

Thanks for any help!

Download All
0 Kudos
Message 1 of 6
(2,525 Views)
Solution
Accepted by Nanoparticles

Hi,

 

The root of your problem is in how you have used multiple event structures. Typically, a program should just have one event structure, which handles all events during the program. The vision functions were all working correctly!

 

From looking at what you are trying to do, I think it would be worth using a well known architecture called the state machine with events. I'll attach some code framework to show you what it might look like for you, you can adapt it to suit your program. I hope its enough for you to get an idea of what I'm trying to show you, it doesn't have any code in it yet, but I think it gets the idea across, and if you combine it with the link below on state machines, it may help you to set out your code in a better architecture.

 

A few links you may find helpful:

Event programming: http://www.ni.com/white-paper/3331/en

Caveats for using events: http://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/caveatsrecmndtnsevnts/

State machine: http://www.ni.com/white-paper/2926/en

 

let me know if you have any more questions.

Ian S
Applications Engineer CLA
National Instruments UK&Ireland
Message 2 of 6
(2,509 Views)

Hi

Thanks for the advice! I will try and work my code into the new structure will let you know if I get it to work!

 

Cheers

 

David

0 Kudos
Message 3 of 6
(2,502 Views)

Hi again Ian,

 

It seems to be working I still havent quite finished but this seems to resolve the problem so far. Hope things carry on working.

 

I have a question regarding the state machine though. It seems that when I wish to add a new case to the case structure I need to modify each event commant with the updated version since they don't automatically update. I hope you understand waht I mean. Do you have any idea if there is an easy way to add another case to the structure without having to replace all case variables in the entire program?

 

Thanks!

0 Kudos
Message 4 of 6
(2,479 Views)

I should slap myself on the wrist for missing out a really important part of the state machine.

If you right click on one of the enums, and click "make type def", it makes it into a type def (duh!). If you then open up the type definition (under right click again) and save it, you can use the type defined control everywhere instead of the old enums I put in (just drag it in from a file browser/project window/copy and paste etc). Then when you want a new case, you simply edit the type definition control, and all the enums will update! Then you just add the extra cases to the case structure (right click on border>>add case for every value)

 

The use of a type defined enum makes the whole state machine much easier to code, you can easily add new cases this way.

 

Labview help for type defs:

http://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/creating_type_defs/

 

Glad to hear you are implementing the idea. I'm not sure if you are still hiding controls, but it might be better to use the disable property rather than visible property, then you can see everything at once, but control when users can press each button.

Ian S
Applications Engineer CLA
National Instruments UK&Ireland
0 Kudos
Message 5 of 6
(2,468 Views)

thanks very much that helps a lot! I think I can get the stuff doen with this structure now 😄 thanks for the kind help.

0 Kudos
Message 6 of 6
(2,451 Views)