loading
 
VB Script array
Anonymous
10 years
Hi

I am using RR in a slightly diferent way to most by reading the forum. I am using it for machine vision, to try and read a 7 segment display and send the value ot a text file. I have had the display reader VBS code running, but now when I try to start it, I get a type mismatch error for the arrays starting on line 9. Code is listed below. I haven't changed anything and it just stopped working.

A rough explanation of the code is: Each of the 7 segments in on the screen is checked for colour by a single pixel whose location is defined by the arrays at the top of the code. The code then does a comparison for lit segments and sets a variable with the decimal value.

Dim Pixels
Dim SegVal
Dim SegLit
Dim SegArray
Dim SegBin
Dim SegDec


SegArray(1,1) =136
SegArray(1,2) =102
SegArray(2,1) =123
SegArray(2,2) =94
SegArray(3,1) =148
SegArray(3,2) =95
SegArray(4,1) =136
SegArray(4,2) =87
SegArray(5,1) =123
SegArray(5,2) =80
SegArray(6,1) =148
SegArray(6,2) =80
SegArray(7,1) =136
SegArray(7,2) =72


pixels = GetPixels()

for i = 1 to 7
pxl = ((SegArray(i,2) * 320) + SegArray(i,1)) * 3
SegVal(i) = Pixels(pxl) + Pixels(pxl+1) + Pixels(pxl+2)
if SegVal(i) > 50 Then
    SegLit(i) = 1
Else
    SegLit(i) = 0
End If


next

SegBin = SegLit(7) + (2 * SegLit(6)) + (4 * SegLit(5)) + (8 * SegLit(4)) + (16 * SegLit(3)) + (32 * SegLit(2)) + (64 * SegLit(1))

SetVariable "Seg1", SegLit(1)
SetVariable "Seg2", SegLit(2)
SetVariable "Seg3", SegLit(3)
SetVariable "Seg4", SegLit(4)
SetVariable "Seg5", SegLit(5)
SetVariable "Seg6", SegLit(6)
SetVariable "Seg7", SegLit(7)



Select Case SegBin

Case 18    
  SegDec = 1

Case 58    
  SegDec = 4

Case 82
  SegDec = 7

Case 91
  SegDec = 3

Case 93    
  SegDec = 2

Case 107
  SegDec = 5

Case 111
  SegDec = 6

Case 119
  SegDec = 0

Case 122
  SegDec = 9

Case 127
  SegDec = 8

Case Else
  SegDec = -1

End Select

SetVariable "DecOut", SegDec
Anonymous 10 years
Hi,

Actually we use RoboRealm for a lot of machine vision applications ... works nicely for that domain and image processing quite nicely.

You need to add ReDim statements to your code as in

Dim Pixels
Dim SegVal
Dim SegLit
Dim SegArray
Dim SegBin
Dim SegDec

ReDim SegArray(10,10)
ReDim SegVal(7)
ReDim SegLit(7)

Note the 3 ReDim statements which are needed to tell VBScript that they are to be used as arrays as apposed to variables.

Would you mind posting the image that you are using? We'd like to see the full process and perhaps add it as a tutorial.

Thanks,
STeven.
VBA Array
Anonymous
10 years
Thanks Steven

Wrote the forum question in a bit of a hurry and left off my name and the image. The image is now attached. This is not the actual image I was using to get the code right, but it is the final image I want the system to read. It is a temperature readout on an old industrial board. The project is still a work in progress with a timer and connection to a database to save the 'read' values still to be written. The other thin to note is the order of the segments that the code reads as the SegLit array. They are:

    ----   =1
   |     |  =2 and 3
    ----   = 4
   |     |  = 5 and 6
    ----   = 7

Thanks again.

Once I have the full app up and running well I will post it for you

Cheers

James
(Australia)
Anonymous 10 years
James,

We thought this would be a nice application as there are many situations where the only way to read a device is by simply understanding the visual digits from the device and converting those pixels into actual digital numbers.

Thus, in addition to your solution we have included an example that uses the shape matching module to "read" or OCR the digits in your image. The trick is to create a trainable folder that includes each of the digits as binary (B&W) images to be recognized. As you are only using digits that would require 10 images. Each image is named with the number they represent.

We've attached a robofile below that includes your image with the processing (threshold and smoothing) that helps to better recognize the letters. Note that you will need to include the attached images into a folder and train the shape matching on that folder for this to work. Your numbers would then be shown in the lower right corner as RoboRealm variables. You can then export these numbers using other modules.

The advantage to this technique is that it is translation, rotation and scale invariant in case your guage moves relative to the camera.

Note that you will have to redownload RR (1.7.22.3) as we made some changes to the shapematching to better handle letters with holes in them.

STeven.






program.robo

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