loading
 
VBScript saving to file help
bizso09 from Arctic Ocean  [2 posts]
8 years
Hi I wonder if someone with more experience than I have in VBScript could help me.

I'm tracking multiple blobs (circa 90 per image) from a video file. I need to export the data into a file in the following format:

IMAGE_COUNT, BLOB_TRACKING_X, blob COG coordinates

I need to do this for all images as they are processed, and I need to iterate through the blobs currently being tracked (BLOB_TRACKING_IDS) and print out the Center of Gravity for each blob in the current frame.

BLOB_TRACKING_X is a blob such as BLOB_TRACKING_2345, and "blob COG coordinates" is a list of past COG for that blob particular blob

This is what I got so far, but it doesnt work

Dim blobIds() As Integer
Dim currBlob As String
Dim currBlobNum As String
Dim CRLF = Chr(13) & Chr(10)
Dim currImg
Dim cogs
Dim fi
Dim fso

set fso = CreateObject("Scripting.FileSystemObject")
set fi = fso.OpenTextFile("c:\test.txt", 8, true)
blobIds = GetArrayVariable("BLOB_TRACKING_IDS")
currImg = GetStrVariable("IMAGE_COUNT")


For i = 1 To blobIds.GetLength()
    currBlob = CStr(blobIds(i-1))
    currBlobNum = "BLOB_TRACKING_" & currBlob
    cogs = CStr(GetVariable(currBlobNum))
    fi.writeLine (currImg & ", " & currBlob & ", " & cogs & CRLF)
Next i

set fi = nothing
set fso = nothing


Any help would be much appreciated.
Thx
Anonymous 8 years
Biz,

You're on the right track but a couple of issues might be of concern. When saving the cog list that list is constantly growing until the object is lost. So saving that list each time will probably be very redundant. You probably just want to save the current detected coordinates of each object in the file and process it afterwards (or during) for just those coordinates.

Also not the use of GetArrayVariable to get variables that are in fact arrays.

Note that the VBScript is a subset of VB and does not understand types as it is a variant language. Thus Dim X As String doesn't really work in VB.

Below is a script that you may find useful for saving the information as you specify. It appears to work with 2.4.5.

Dim blobIds
Dim currBlob
Dim currBlobNum
Dim currImg
Dim cogs
Dim fi
Dim fso

set fso = CreateObject("Scripting.FileSystemObject")
set fi = fso.OpenTextFile("c:\\test.txt", 8, true)
blobIds = GetArrayVariable("BLOB_TRACKING_IDS")
currImg = GetStrVariable("IMAGE_COUNT")

For i = 0 To ubound(blobIds)
    currBlob = blobIds(i)
    cogs = GetArrayVariable("BLOB_TRACKING_" & currBlob)
    fi.writeLine ((i+1) & ", " & currBlob & ", " & cogs(ubound(cogs)-1) & "," & cogs(ubound(cogs))  & vbCRLF)
Next

set fi = nothing
set fso = nothing

STeven.
bizso09 from Arctic Ocean  [2 posts] 8 years
Hi Steven,
Thx for ur help, I've never used VBScript nor VB before. I tried to put a program together from the documentation u have on the VBScript module help page.

Fortunately, shortly after I posted this, I managed to sort it out. However thx for ur reply, ur program is more efficient: this is what I got, but it does the same thing, except it prints out the image n.o. instead of the counter.

I've also read somewhere that UBound isn't very reliable to get the length of the array, though it may be good enough in this case ?!


blobIds = GetArrayVariable("BLOB_TRACKING_IDS")
currImg = GetStrVariable("IMAGE_COUNT")

set fso = CreateObject("Scripting.FileSystemObject")
set fi = fso.OpenTextFile("c:\coordinates.txt", 8, true)

For i = 0 To UBound(blobIds)
    currBlob = CStr(blobIds(i))
    currBlobNum = "BLOB_TRACKING_" & currBlob
    cogs = GetArrayVariable(currBlobNum)
    line = currImg & ", " & currBlob
    cog = CStr(cogs(UBound(cogs)-1))
    line = line & ", " & cog
    cog = CStr(cogs(UBound(cogs)))
    line = line & ", " & cog
    line = line & vbCrLf
    fi.writeLine (line)
Next

set fi = nothing
set fso = nothing

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index