LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract image from VLC active x to LabVIEW image (JPEG or PNG or IMAQ Image)

I have IP camera over NVR which support RTSP.

learned from VLC scripting in LabVIEW by GriffinRU , view live steaming video under .NET picture box was success fully. However, can't figure out how to grab the image into LabVIEW (e.g. JPEG, PNG or IMAQ image). 

 

I tried following the instruction from Convert a .NET PictureBox to an IMAQ Image but always fail with error (1172) :

Error 1172 occurred at Invoke Node Error calling method System.Drawing.Image.Save, (System.ArgumentNullException: Key cannot be null. Parameter name: key)

Possible reason(s):

LabVIEW: (Hex 0x494) A .NET exception occurred in an external assembly. For information about correcting this error, copy the following exception (in bold), and search the Microsoft Developer Network (MSDN) Web site or the Web for a possible explanation.
System.ArgumentNullException in PicBox to PNGstring (SubVI).vi->VLC - Play Stream&Snapshot&speed.vi

 

here is the error occurs: on image save methodhere is the error occurs: on image save method

 

when I put probes, I found that the refnum of the image is 0 (zero = not a refnum), while the refnum of the picture box is present (not-zero). though I'm not sure if this is the cause or not.

Probes.jpg

 

any better Idea?

Message 1 of 13
(983 Views)
Forgot to mention, I'm using:
LabVIEW 2020 (32-bit)
under Windows 64-bit
VLC 32-bit (tried with 64 bit, got error immediately while LabVIEW call libvlc_new function in libvlc.dll )
Message 2 of 13
(981 Views)

Check out this post for some example code that may solve your issue:

https://forums.ni.com/t5/LabVIEW/NET-picturebox-convert-to-LabView-image/m-p/3125944#M897890

 

Edit:

Specifically, check out Get Image Data From PictureBox.vi

Get Image Data From PictureBox.viGet Image Data From PictureBox.vi

 

_______________________________________________________________
"Computers are useless. They can only give you answers." - Pablo Picasso
0 Kudos
Message 3 of 13
(974 Views)

Suggestion: you also need to be much more careful to close EVERY reference you open. Some objects are IDisposable objects, and must be Disposed later (by using the Dispose method, not just by calling Close Reference). A thing like Color is a struct, not a disposable object, so it does not need to be Disposed; however, its LabVIEW refnum must be closed (using Close Reference).

 

You may not notice the leaks in a small program, but if you ever call this function in a loop you will eventually reach LabVIEW's internal refnum limit and crash the program with an Out of Memory error.

 

When in doubt, close it out!

_______________________________________________________________
"Computers are useless. They can only give you answers." - Pablo Picasso
0 Kudos
Message 4 of 13
(970 Views)
0 Kudos
Message 5 of 13
(930 Views)

Posting a picture of someone else's code makes it difficult to debug your code.

 

The Image refnum should not be confused with the PictureBox refnum. The Image object is not being set correctly if it is not being read correctly.

 

Additionally, the if the Image object in the PictureBox control is replaced with a new one, the new one must be inserted before the old one is Disposed (even if it is just a constant) to avoid a .NET exception as in the following examples (from the Image Manipulation DotNET zip):

 

Open In a Loop.viOpen In a Loop.vi

 

Open In a Loop FIXED.viOpen In a Loop FIXED.vi

 

_______________________________________________________________
"Computers are useless. They can only give you answers." - Pablo Picasso
0 Kudos
Message 6 of 13
(927 Views)

@ThamS wrote:

 

 

here is the error occurs: on image save methodhere is the error occurs: on image save method

 

any better Idea?


so, the error ocurs, when the image data  is meant to be saved to the Memory Stream ... how annoying

 

 in contrast to the knowledgebase article, you don't close the Image Reference - as rwunderl mentioned in post 3

maybe you also need to add the Image.Dispose method - as rwunderl mentioned in post 6

 

does this have any effect, e.g. is the refnum of the image still 0?

 

 

 

 

 

 

 

0 Kudos
Message 7 of 13
(895 Views)

@alexderjuengere wrote:


so, the error ocurs, when the image data  is meant to be saved to the Memory Stream ... how annoying

The error happens at the Save method because that is the first time you are trying to use the Image object. My argument is that the PictureBox does not have a valid Image object in the first place, and THAT is why the error occurs. You could run the PicBox to PNGstring vi with no inputs at all and get the 1172 error "System.ArgumentNullException" from .NET.

 


@alexderjuengere wrote:

does this have any effect, e.g. is the refnum of the image still 0?

Disposing and Closing are good things to do, but they will not retroactively make the refnum valid.

 

In the example I first directed you to, the Image object of the PictureBox is created from an image file on disk:

Load Image.vi - simplified for clarityLoad Image.vi - simplified for clarity

 

This is a valid Image object. The Image object is then set to the PictureBox in the Display Image function:

Display Image.viDisplay Image.vi

 

Now the PictureBox has a valid Image object. Then later on when Image is read to invoke the Save method, it is still going to be a valid Image object.

 

Your Save will never work, because the Image object is invalid. We have determined that. Where is your application generating and setting the Image of the PictureBox? That is what I am trying to get you to debug. That is what is broken.

_______________________________________________________________
"Computers are useless. They can only give you answers." - Pablo Picasso
0 Kudos
Message 8 of 13
(887 Views)

Hi rwunderl

Hi alexderjuengere

Thank you for your both effort so far.

 

I think my probelm is, the VLC activeX seems doesn't really create image on picture box. instead it just use the windows handler of the .NET picturebox to show the frame on top of picturebox control. (I'm refereing to  VLC scripting in LabVIEW by GriffinRU)

what do you guys think?

 

I attached my code project in rar.

 

 

0 Kudos
Message 9 of 13
(848 Views)
Some Body could figure out any better idea?
0 Kudos
Message 10 of 13
(811 Views)