free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Rickey's World :: Discussion Forums :: Project Development :: Project Help
 
<< Previous thread | Next thread >>
HELP need to change from VB to borland C++ builder
Moderators: Ajay Bhargav, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph, ExperimenterUK, DavesGarage
Author Post
Shnur
Tue Mar 31 2009, 11:24PM
 User Offline
Registered Member #13546
Joined: Mon Dec 29 2008, 07:37AM

Posts: 6
Thanked 0 times in 0 posts
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.



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





Back to top

Shnur
Wed Apr 01 2009, 09:54PM
 User Offline
Registered Member #13546
Joined: Mon Dec 29 2008, 07:37AM

Posts: 6
Thanked 0 times in 0 posts
any ideas T_T
Back to top

Ajay Bhargav
Thu Apr 02 2009, 04:17AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 7567
Thanked 1331 times in 1255 posts
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?

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top

 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems