Shnur
Mar 31 2009, 11:24 PM
I have a VB code that works very well and I need to rewrite it in C++ builder and don't know how if you could help me it would be great.
Here is the link to the code: http://rapidshare.com/files/216031946/vb_laser_ranger.rar.html
It includes the code and a prog called videoOCX that need to be installed to run it.
Here is the link to the code: http://rapidshare.com/files/216031946/vb_laser_ranger.rar.html
It includes the code and a prog called videoOCX that need to be installed to run it.
CODE:
Private Sub exit_Click()
'only if running...
If (Timer1.Enabled) Then
Timer1.Enabled = False 'Stop Timer
VideoOCX.Stop
VideoOCX.Close
End If
End
End Sub
Private Sub Start_Click() 'Init VideoOCX Control, allocate memory and start grabbing
If (Not Timer1.Enabled) Then
Start.Caption = "Stop"
' Disable internal error messages in VideoOCX
VideoOCX.SetErrorMessages False
' Init control
If (Not VideoOCX.Init) Then
' Init failed. Display error message and end sub
MsgBox VideoOCX.GetLastErrorString, vbOKOnly, "VideoOCX Error"
End
Else
' Allocate memory for global image handle
capture_image = VideoOCX.GetColorImageHandle
' result_image = VideoOCX_Processed.GetColorImageHandle
Timer1.Enabled = True 'Start capture timer
' Start Capture mode
If (Not VideoOCX.Start) Then
' Start failed. Display error message and end sub
MsgBox VideoOCX.GetLastErrorString, vbOKOnly, "VideoOCX Error"
End
End If
End If
Else
Start.Caption = "Start"
Timer1.Enabled = False 'Stop Timer
VideoOCX.Stop
VideoOCX.Close
End If
End Sub
Private Sub Timer1_Timer()
' Timer for capturing - handles videoOCXTools
Dim matrix As Variant
Dim height, width As Integer
Dim r, c As Integer
Dim max_r, max_c As Integer
Dim max_red As Integer
Dim gain, offset As Variant
Dim h_cm As Variant
Dim range As Integer
Dim pixels_from_center As Integer
' Calibrated parameter for pixel to distance conversion
gain = 0.0024259348
offset = -0.056514344
h_cm = 5.842
max_red = 0
' Capture an image
If (VideoOCX.Capture(capture_image)) Then
' VideoOCX.Show capture_image
' Matrix transformation initialization
matrix = VideoOCX.GetMatrix(capture_image)
height = VideoOCX.GetHeight
width = VideoOCX.GetWidth
' Image processing code
' The laser dot should not be seen above the middle row (with a little pad)
For r = height / 2 - 20 To height - 1
' Our physical setup is roughly calibrated to make the laser
' dot in the middle columns...dont bother lookng too far away
For c = width / 2 - 25 To width / 2 + 24
' Look for the largest red pixel value in the scene (red laser)
If (matrix(c, r, 2) > max_red) Then
max_red = matrix(c, r, 2)
max_r = r
max_c = c
End If
Next c
Next r
' Calculate the distance for the laser dot from middle of frame
pixels_from_center = max_r - 120
' Calculate range in cm based on calibrated parameters
range = h_cm / Tan(pixels_from_center * gain + offset)
' Print laser dot position row and column to screen
row_val.Caption = max_r
col_val.Caption = max_c
' Print range to laser illuminated object to screen
range_val.Caption = range
' Draw a red vertical line to intersect target
For r = 0 To height - 1
matrix(max_c, r, 2) = 255
Next r
' Draw a red horizontal line to intersect target
For c = 0 To width - 1
matrix(c, max_r, 2) = 255
Next c
VideoOCX.ReleaseMatrixToImageHandle (capture_image)
End If
VideoOCX.Show capture_image
End Sub
'only if running...
If (Timer1.Enabled) Then
Timer1.Enabled = False 'Stop Timer
VideoOCX.Stop
VideoOCX.Close
End If
End
End Sub
Private Sub Start_Click() 'Init VideoOCX Control, allocate memory and start grabbing
If (Not Timer1.Enabled) Then
Start.Caption = "Stop"
' Disable internal error messages in VideoOCX
VideoOCX.SetErrorMessages False
' Init control
If (Not VideoOCX.Init) Then
' Init failed. Display error message and end sub
MsgBox VideoOCX.GetLastErrorString, vbOKOnly, "VideoOCX Error"
End
Else
' Allocate memory for global image handle
capture_image = VideoOCX.GetColorImageHandle
' result_image = VideoOCX_Processed.GetColorImageHandle
Timer1.Enabled = True 'Start capture timer
' Start Capture mode
If (Not VideoOCX.Start) Then
' Start failed. Display error message and end sub
MsgBox VideoOCX.GetLastErrorString, vbOKOnly, "VideoOCX Error"
End
End If
End If
Else
Start.Caption = "Start"
Timer1.Enabled = False 'Stop Timer
VideoOCX.Stop
VideoOCX.Close
End If
End Sub
Private Sub Timer1_Timer()
' Timer for capturing - handles videoOCXTools
Dim matrix As Variant
Dim height, width As Integer
Dim r, c As Integer
Dim max_r, max_c As Integer
Dim max_red As Integer
Dim gain, offset As Variant
Dim h_cm As Variant
Dim range As Integer
Dim pixels_from_center As Integer
' Calibrated parameter for pixel to distance conversion
gain = 0.0024259348
offset = -0.056514344
h_cm = 5.842
max_red = 0
' Capture an image
If (VideoOCX.Capture(capture_image)) Then
' VideoOCX.Show capture_image
' Matrix transformation initialization
matrix = VideoOCX.GetMatrix(capture_image)
height = VideoOCX.GetHeight
width = VideoOCX.GetWidth
' Image processing code
' The laser dot should not be seen above the middle row (with a little pad)
For r = height / 2 - 20 To height - 1
' Our physical setup is roughly calibrated to make the laser
' dot in the middle columns...dont bother lookng too far away
For c = width / 2 - 25 To width / 2 + 24
' Look for the largest red pixel value in the scene (red laser)
If (matrix(c, r, 2) > max_red) Then
max_red = matrix(c, r, 2)
max_r = r
max_c = c
End If
Next c
Next r
' Calculate the distance for the laser dot from middle of frame
pixels_from_center = max_r - 120
' Calculate range in cm based on calibrated parameters
range = h_cm / Tan(pixels_from_center * gain + offset)
' Print laser dot position row and column to screen
row_val.Caption = max_r
col_val.Caption = max_c
' Print range to laser illuminated object to screen
range_val.Caption = range
' Draw a red vertical line to intersect target
For r = 0 To height - 1
matrix(max_c, r, 2) = 255
Next r
' Draw a red horizontal line to intersect target
For c = 0 To width - 1
matrix(c, max_r, 2) = 255
Next c
VideoOCX.ReleaseMatrixToImageHandle (capture_image)
End If
VideoOCX.Show capture_image
End Sub
Shnur
Apr 1 2009, 9:54 PM
any ideas T_T
Ajay
Apr 2 2009, 4:17 AM
Hi shnur,
I know borland is good
but i feel vb is simpler.
I wish i could help.. why u want to go towards console type program rather to have a GUI one?
I know borland is good
but i feel vb is simpler.I wish i could help.. why u want to go towards console type program rather to have a GUI one?