VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Tracking"
   ClientHeight    =   3015
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3150
   LinkTopic       =   "Form1"
   ScaleHeight     =   3015
   ScaleWidth      =   3150
   StartUpPosition =   3  'Windows の既定値
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   50
      Left            =   0
      Top             =   0
   End
   Begin VB.CommandButton cmdStop 
      Caption         =   "Stop"
      Height          =   435
      Left            =   1620
      TabIndex        =   11
      Top             =   1980
      Width           =   1335
   End
   Begin VB.TextBox txtVar 
      Height          =   315
      Index           =   1
      Left            =   1860
      TabIndex        =   10
      Text            =   "F12"
      Top             =   1500
      Width           =   915
   End
   Begin VB.TextBox txtImg 
      Alignment       =   1  '右揃え
      Height          =   315
      Index           =   1
      Left            =   1860
      TabIndex        =   7
      Text            =   "11"
      Top             =   660
      Width           =   915
   End
   Begin VB.TextBox txtImg 
      Alignment       =   1  '右揃え
      Height          =   315
      Index           =   0
      Left            =   1860
      TabIndex        =   5
      Text            =   "1"
      Top             =   240
      Width           =   915
   End
   Begin VB.TextBox txtVar 
      Height          =   315
      Index           =   0
      Left            =   1860
      TabIndex        =   1
      Text            =   "F11"
      Top             =   1080
      Width           =   915
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "Start"
      Height          =   435
      Left            =   240
      TabIndex        =   0
      Top             =   1980
      Width           =   1335
   End
   Begin VB.Label lblTrack 
      Alignment       =   1  '右揃え
      BackStyle       =   0  '透明
      Caption         =   "Y output variable : "
      Height          =   255
      Index           =   3
      Left            =   360
      TabIndex        =   9
      Top             =   1560
      Width           =   1455
   End
   Begin VB.Label lblTrack 
      Alignment       =   1  '右揃え
      BackStyle       =   0  '透明
      Caption         =   "X output variable : "
      Height          =   255
      Index           =   2
      Left            =   360
      TabIndex        =   8
      Top             =   1140
      Width           =   1455
   End
   Begin VB.Label lblTrack 
      Alignment       =   1  '右揃え
      BackStyle       =   0  '透明
      Caption         =   "Target Image ID : "
      Height          =   255
      Index           =   1
      Left            =   360
      TabIndex        =   6
      Top             =   720
      Width           =   1455
   End
   Begin VB.Label lblTrack 
      Alignment       =   1  '右揃え
      BackStyle       =   0  '透明
      Caption         =   "Live Camera ID : "
      Height          =   255
      Index           =   0
      Left            =   360
      TabIndex        =   4
      Top             =   300
      Width           =   1455
   End
   Begin VB.Label lblRes 
      Appearance      =   0  'ﾌﾗｯﾄ
      BackColor       =   &H80000005&
      BackStyle       =   0  '透明
      BorderStyle     =   1  '実線
      Caption         =   "0, 0"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   1620
      TabIndex        =   3
      Top             =   2580
      Width           =   1335
   End
   Begin VB.Label Label1 
      Alignment       =   1  '右揃え
      Caption         =   "Result (X, Y) : "
      Height          =   195
      Left            =   240
      TabIndex        =   2
      Top             =   2580
      Width           =   1275
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim m_caoEng As CaoEngine
Dim m_caoWs As CaoWorkspace

Dim m_caoVis As CaoController
Dim m_camImg As CaoFile

Dim m_caoRob As CaoController
Dim m_robVarX As CaoVariable
Dim m_robVarY As CaoVariable


' Initialize
Private Sub Form_Load()

    Set m_caoEng = New CaoEngine
    Set m_caoWs = m_caoEng.Workspaces(0)
    
End Sub

' Start
Private Sub cmdStart_Click()

    ' Clear ORiN objects
    m_caoWs.Controllers.Clear
    DoEvents
    
    ' Create ORiN objects
    Set m_caoVis = m_caoWs.AddController("usb_cam", "CaoProv.OpenCV", "", "")
    Set m_camImg = m_caoVis.AddFile("img1", "ID=" & txtImg(0))
    
    Set m_caoRob = m_caoWs.AddController("denso_robo", "CaoProv.DENSO.NetwoRC", "", "Conn=eth:192.168.0.1")
    Set m_robVarX = m_caoRob.AddVariable(txtVar(0))
    Set m_robVarY = m_caoRob.AddVariable(txtVar(1))
    
    ' Start tracking
    Timer1.Enabled = True
    
End Sub

' Stop
Private Sub cmdStop_Click()
    
    Timer1.Enabled = False

End Sub


' Tracking
Private Sub Timer1_Timer()

    Dim res As Variant
    Dim pos As Variant
    
    ' ターゲットサーチ
    res = m_camImg.MatchTemplate2(CLng(txtImg(1)), 3, 0.8, 0, 360, 1, 3, 1, 0)  ' 要パラメータ調整
    
    ' 結果転送(To DENSO RC)
    pos = res(0)
    m_robVarX.Value = pos(0)
    m_robVarY.Value = pos(1)
    lblRes.Caption = pos(0) & ", " & pos(1)

End Sub

