| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 510 人关注过本帖
标题:动态物体的检测代码!!!!求大家帮忙看看有什么问题~~~
只看楼主 加入收藏
wxadrtyu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-12-20
结帖率:0
收藏
已结贴  问题点数:20 回复次数:6 
动态物体的检测代码!!!!求大家帮忙看看有什么问题~~~
[code]Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Dim Video_Handle As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Dim I As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Command1_Click() '打开视频
Dim AVI_Name As String, AVI As String
AVI_Name = "C:\Users\LSC\Desktop\qwe.avi"
mciSendString "close MyAVI", "", 0, 0 '关闭之前可能打开的减轻计算机负担
AVI = "open " & AVI_Name & " alias MyAVI parent " & Picture1.hwnd & " style child"
mciSendString AVI, "", 0, 0 '打开指定文件
Picture1.ScaleMode = 3 '设置视频的坐标单位为PIX
AVI = "put MyAVI window at 0 0 " & Picture1.ScaleWidth & " " & Picture1.ScaleHeight
mciSendString AVI, "", 0, 0 '在picturebox输出视频第一帧
End Sub
Private Sub Command2_Click() '开始播放
If Text6.Text = "" Then
MsgBox "请输入比例后按确认"
Exit Sub
End If
If Picture2.Visible = False Then
MsgBox "请输入标记1,按Q获得"
Exit Sub
End If
If Picture3.Visible = False Then
MsgBox "请输入标记2,按W获得"
Exit Sub
End If
If Picture4.Visible = False Then
MsgBox "请输入标记3,按E获得"
Exit Sub
End If
If Picture5.Visible = False Then
MsgBox "请输入标记4,按R获得"
Exit Sub
End If
If Picture6.Visible = False Then
MsgBox "请输入标记5,按T获得"
Exit Sub
End If
If Picture7.Visible = False Then
MsgBox "请输入标记6,按Y获得"
Exit Sub
End If

I = I + 1
If I / 2 <> Int(I / 2) Then '播放
mciSendString "play MyAVI", "", 0, 0
Else '暂停
mciSendString "pause MyAVI", "", 0, 0
End If
Sleep (100)
Dim h As Long, dc As Long, dc2 As Long, dc3 As Long, dc4 As Long, dc5 As Long, h1 As Long, dc1 As Long
Dim Xa As Long, Xb As Long, Xc As Long, Xd As Long, Xe As Long
Dim Ra As Byte, Ga As Byte, Ba As Byte, Rb As Byte, Gb As Byte, Bb As Byte, Rc As Byte, Gc As Byte, Bc As Byte, Rd As Byte, Gd As Byte, Bd As Byte, Re As Byte, Ge As Byte, Be As Byte, R1 As Byte, G1 As Byte, B1 As Byte
Dim X1a As Long, X1b As Long, X1c As Long, X1d As Long, X1e As Long
Dim X2a As Long, X2b As Long, X2c As Long, X2d As Long, X2e As Long
Dim X3a As Long, X3b As Long, X3c As Long, X3d As Long, X3e As Long
Dim X4a As Long, X4b As Long, X4c As Long, X4d As Long, X4e As Long
Dim X5a As Long, X5b As Long, X5c As Long, X5d As Long, X5e As Long


Dim R1a As Byte, G1a As Byte, B1a As Byte, R1b As Byte, G1b As Byte, B1b As Byte, R1c As Byte, G1c As Byte, B1c As Byte, R1d As Byte, G1d As Byte, B1d As Byte, R1e As Byte, G1e As Byte, B1e As Byte
Dim R2a As Byte, G2a As Byte, B2a As Byte, R2b As Byte, G2b As Byte, B2b As Byte, R2c As Byte, G2c As Byte, B2c As Byte, R2d As Byte, G2d As Byte, B2d As Byte, R2e As Byte, G2e As Byte, B2e As Byte
Dim R3a As Byte, G3a As Byte, B3a As Byte, R3b As Byte, G3b As Byte, B3b As Byte, R3c As Byte, G3c As Byte, B3c As Byte, R3d As Byte, G3d As Byte, B3d As Byte, R3e As Byte, G3e As Byte, B3e As Byte
Dim R4a As Byte, G4a As Byte, B4a As Byte, R4b As Byte, G4b As Byte, B4b As Byte, R4c As Byte, G4c As Byte, B4c As Byte, R4d As Byte, G4d As Byte, B4d As Byte, R4e As Byte, G4e As Byte, B4e As Byte
Dim R5a As Byte, G5a As Byte, B5a As Byte, R5b As Byte, G5b As Byte, B5b As Byte, R5c As Byte, G5c As Byte, B5c As Byte, R5d As Byte, G5d As Byte, B5d As Byte, R5e As Byte, G5e As Byte, B5e As Byte

dc = GetDC(0)
dc1 = GetDC(0)
dc2 = GetDC(0)
dc3 = GetDC(0)
dc4 = GetDC(0)
dc5 = GetDC(0)



X1c = GetPixel(dc1, heng1 + 16, zong1)
X1a = GetPixel(dc1, heng1, zong1)
X1b = GetPixel(dc1, heng1 - 16, zong1)
X1d = GetPixel(dc1, heng1 + 8, zong1)
X1e = GetPixel(dc1, heng1 - 8, zong1)
Xa = GetPixel(dc, heng, zong)
Xb = GetPixel(dc, heng - 16, zong)
Xc = GetPixel(dc, heng + 16, zong)
Xd = GetPixel(dc, heng + 8, zong)
Xe = GetPixel(dc, heng - 8, zong)
X2a = GetPixel(dc2, heng2, zong2)
X2b = GetPixel(dc2, heng2 - 16, zong2)
X2c = GetPixel(dc2, heng2 + 16, zong2)
X2d = GetPixel(dc2, heng2 + 8, zong2)
X2e = GetPixel(dc2, heng2 - 8, zong2)
X3a = GetPixel(dc3, heng3, zong2)
X3b = GetPixel(dc3, heng3 - 16, zong3)
X3c = GetPixel(dc3, heng3 + 16, zong3)
X3d = GetPixel(dc3, heng3 + 8, zong3)
X3e = GetPixel(dc3, heng3 - 8, zong3)
X4a = GetPixel(dc4, heng4, zong4)
X4b = GetPixel(dc4, heng4 - 16, zong4)
X4c = GetPixel(dc4, heng4 + 16, zong4)
X4d = GetPixel(dc4, heng4 + 8, zong4)
X4e = GetPixel(dc4, heng4 - 8, zong4)
X5a = GetPixel(dc5, heng5, zong5)
X5b = GetPixel(dc5, heng5 - 16, zong5)
X5c = GetPixel(dc5, heng5 + 16, zong5)
X5d = GetPixel(dc5, heng5 + 8, zong5)
X5e = GetPixel(dc5, heng5 - 8, zong5)

'/////////////////////取得检测点的灰度值///////////////////////

Ra = (Xa Mod 256) \ 16 '取得红色值
Ga = (Xa Mod 65536) \ 256 '取得绿色值
Ba = (Xa Mod 16777216) \ 65536 '取得蓝色值
Ca = Ra / 3 + Ga / 3 + Ba / 3 '取得灰度值


Rb = (Xb Mod 256) \ 16
Gb = (Xb Mod 65536) \ 256
Bb = (Xb Mod 16777216) \ 65536
Cb = Rb / 3 + Gb / 3 + Bb / 3


Rc = (Xc Mod 256) \ 16
Gc = (Xc Mod 65536) \ 256
Bc = (Xc Mod 16777216) \ 65536
ReleaseDC dc, 0
Cc = Rc / 3 + Gc / 3 + Bc / 3

Rd = (Xd Mod 256) \ 16
Gd = (Xd Mod 65536) \ 256
Bd = (Xd Mod 16777216) \ 65536
ReleaseDC dc, 0
Cd = Rd / 3 + Gd / 3 + Bd / 3

Re = (Xe Mod 256) \ 16
Ge = (Xe Mod 65536) \ 256
Be = (Xe Mod 16777216) \ 65536
ReleaseDC dc, 0
Ce = Re / 3 + Ge / 3 + Be / 3


R1a = (X1a Mod 256) \ 16
G1a = (X1a Mod 65536) \ 256
B1a = (X1a Mod 16777216) \ 65536
C1a = R1a / 3 + G1a / 3 + B1a / 3



R1b = (X1b Mod 256) \ 16
G1b = (X1b Mod 65536) \ 256
B1b = (X1b Mod 16777216) \ 65536
C1b = R1b / 3 + G1b / 3 + B1b / 3


R1c = (X1c Mod 256) \ 16
G1c = (X1c Mod 65536) \ 256
B1c = (X1c Mod 16777216) \ 65536
C1c = R1c / 3 + G1c / 3 + B1c / 3

R1d = (X1d Mod 256) \ 16
G1d = (X1d Mod 65536) \ 256
B1d = (X1d Mod 16777216) \ 65536
C1d = R1d / 3 + G1d / 3 + B1d / 3

R1e = (X1e Mod 256) \ 16
G1e = (X1e Mod 65536) \ 256
B1e = (X1e Mod 16777216) \ 65536
C1e = R1e / 3 + G1e / 3 + B1e / 3

R2a = (X2a Mod 256) \ 16
G3a = (X2a Mod 65536) \ 256
B2a = (X2a Mod 16777216) \ 65536
C2a = R2a / 3 + G2a / 3 + B2a / 3



R2b = (X2b Mod 256) \ 16
G2b = (X2b Mod 65536) \ 256
B2b = (X2b Mod 16777216) \ 65536
C2b = R2b / 3 + G2b / 3 + B2b / 3


R2c = (X2c Mod 256) \ 16
G2c = (X2c Mod 65536) \ 256
B2c = (X2c Mod 16777216) \ 65536
C2c = R2c / 3 + G2c / 3 + B2c / 3

R2d = (X2d Mod 256) \ 16
G2d = (X2d Mod 65536) \ 256
B2d = (X2d Mod 16777216) \ 65536
C2d = R2d / 3 + G2d / 3 + B2d / 3

R2e = (X2e Mod 256) \ 16
G2e = (X2e Mod 65536) \ 256
B2e = (X2e Mod 16777216) \ 65536
C2e = R2e / 3 + G2e / 3 + B2e / 3

R3a = (X3a Mod 256) \ 16
G3a = (X3a Mod 65536) \ 256
B3a = (X3a Mod 16777216) \ 65536
C3a = R3a / 3 + G3a / 3 + B3a / 3



R3b = (X3b Mod 256) \ 16
G3b = (X3b Mod 65536) \ 256
B3b = (X3b Mod 16777216) \ 65536
C3b = R3b / 3 + G3b / 3 + B3b / 3


R3c = (X3c Mod 256) \ 16
G3c = (X3c Mod 65536) \ 256
B3c = (X3c Mod 16777216) \ 65536
C3c = R3c / 3 + G3c / 3 + B3c / 3

R3d = (X3d Mod 256) \ 16
G3d = (X3d Mod 65536) \ 256
B3d = (X3d Mod 16777216) \ 65536
C3d = R3d / 3 + G3d / 3 + B3d / 3

R3e = (X3e Mod 256) \ 16
G3e = (X3e Mod 65536) \ 256
B3e = (X3e Mod 16777216) \ 65536
C3e = R3e / 3 + G3e / 3 + B3e / 3

R4a = (X4a Mod 256) \ 16
G4a = (X4a Mod 65536) \ 256
B4a = (X4a Mod 16777216) \ 65536
C4a = R4a / 3 + G4a / 3 + B4a / 3



R4b = (X4b Mod 256) \ 16
G4b = (X4b Mod 65536) \ 256
B4b = (X4b Mod 16777216) \ 65536
C4b = R4b / 3 + G4b / 3 + B4b / 3


R4c = (X4c Mod 256) \ 16
G4c = (X4c Mod 65536) \ 256
B4c = (X4c Mod 16777216) \ 65536
C4c = R4c / 3 + G4c / 3 + B4c / 3

R4d = (X4d Mod 256) \ 16
G4d = (X4d Mod 65536) \ 256
B4d = (X4d Mod 16777216) \ 65536
C4d = R4d / 3 + G4d / 3 + B4d / 3

R4e = (X4e Mod 256) \ 16
G4e = (X4e Mod 65536) \ 256
B4e = (X4e Mod 16777216) \ 65536
C4e = R4e / 3 + G4e / 3 + B4e / 3

R5a = (X5a Mod 256) \ 16
G5a = (X5a Mod 65536) \ 256
B5a = (X5a Mod 16777216) \ 65536
C5a = R5a / 3 + G5a / 3 + B5a / 3



R5b = (X5b Mod 256) \ 16
G5b = (X5b Mod 65536) \ 256
B5b = (X5b Mod 16777216) \ 65536
C5b = R5b / 3 + G5b / 3 + B5b / 3


R5c = (X5c Mod 256) \ 16
G5c = (X5c Mod 65536) \ 256
B5c = (X5c Mod 16777216) \ 65536
C5c = R5c / 3 + G5c / 3 + B5c / 3

R5d = (X5d Mod 256) \ 16
G5d = (X5d Mod 65536) \ 256
B5d = (X5d Mod 16777216) \ 65536
C5d = R5d / 3 + G5d / 3 + B5d / 3

R5e = (X5e Mod 256) \ 16
G5e = (X5e Mod 65536) \ 256
B5e = (X5e Mod 16777216) \ 65536
C5e = R5e / 3 + G5e / 3 + B5e / 3



'//////////////////////////////////////////////////

'释放DC 设置定时器
ReleaseDC dc1, 0
ReleaseDC dc3, 0
ReleaseDC dc5, 0
Timer1.Interval = 10
Timer1.Enabled = True
Timer2.Interval = 10
Timer2.Enabled = False
Timer5.Interval = 10
Timer5.Enabled = True
Timer6.Interval = 10
Timer6.Enabled = False
Timer7.Interval = 10
Timer7.Enabled = True
Timer8.Interval = 10
Timer8.Enabled = False
End Sub
Private Sub Command3_Click() '关闭视频,结束统计
 I = 0: Form_Unload 0
 Timer1.Enabled = False
 Timer2.Enabled = False
 Timer5.Enabled = False
 Timer6.Enabled = False
 Timer7.Enabled = False
 Timer8.Enabled = False
 
 End Sub
 
Private Sub Command4_Click()
Text1.Text = "0辆"
Text2.Text = ""
Text3.Text = ""
M = 0
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
End Sub

Private Sub Command5_Click()
If Picture2.Visible = False Then
MsgBox "请输入标记1,按Q获得"
Exit Sub
End If
If Picture3.Visible = False Then
MsgBox "请输入标记2,按W获得"
Exit Sub
End If
If Picture4.Visible = False Then
MsgBox "请输入标记3,按E获得"
Exit Sub
End If
If Picture5.Visible = False Then
MsgBox "请输入标记4,按R获得"
Exit Sub
End If
If Picture6.Visible = False Then
MsgBox "请输入标记5,按T获得"
Exit Sub
End If
If Picture7.Visible = False Then
MsgBox "请输入标记6,按Y获得"
Exit Sub
End If
If Text6.Text = "" Then
MsgBox "请输入比例"
Exit Sub
End If
S = Val(Text6.Text) * Abs((zong - zong1))
S2 = Val(Text6.Text) * Abs((zong2 - zong3))
S3 = Val(Text6.Text) * Abs((zong4 - zong5))
Label4.Caption = S
Label5.Caption = S2
Label6.Caption = S3

Text5.SetFocus
End Sub

Private Sub Form_Unload(Cancel As Integer)
mciSendString "close MyAVI", "", 0, 0
End Sub
Private Sub Form_Load()
M = 0
Text1.Text = M & "辆"
Timer4.Enabled = True
Timer4.Interval = 10
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False

End Sub

'//////检测扫描点与背景之间的灰度差,当超过设定阈值时计数//////////////
Private Sub Timer1_Timer()
Dim h As Long, dc As Long
Dim Xa As Long, Xb As Long, Xc As Long, Xd As Long, Xe As Long

Dim Ra As Byte, Ga As Byte, Ba As Byte, Rb As Byte, Gb As Byte, Bb As Byte, Rc As Byte, Gc As Byte, Bc As Byte, Rd As Byte, Gd As Byte, Bd As Byte, Re As Byte, Ge As Byte, Be As Byte

dc = GetDC(0)
Xa = GetPixel(dc, heng, zong)
Ra = (Xa Mod 256) \ 16
Ga = (Xa Mod 65536) \ 256
Ba = (Xa Mod 16777216) \ 65536
ReleaseDC dc, 0
Na = Ra / 3 + Ga / 3 + Ba / 3
Za = Int(Abs(Na - Ca))

Xb = GetPixel(dc, heng - 16, zong)
Rb = (Xb Mod 256) \ 16
Gb = (Xb Mod 65536) \ 256
Bb = (Xb Mod 16777216) \ 65536
ReleaseDC dc, 0
Nb = Ra / 3 + Ga / 3 + Ba / 3
Zb = Int(Abs(Nb - Cb))

Xc = GetPixel(dc, heng + 16, zong)
Rc = (Xc Mod 256) \ 16
Gc = (Xc Mod 65536) \ 256
Bc = (Xc Mod 16777216) \ 65536
ReleaseDC dc, 0
Nc = Rc / 3 + Gc / 3 + Bc / 3
Zc = Int(Abs(Nc - Cc))

Xd = GetPixel(dc, heng + 8, zong)
Rd = (Xd Mod 256) \ 16
Gd = (Xd Mod 65536) \ 256
Bd = (Xd Mod 16777216) \ 65536
ReleaseDC dc, 0
Nd = Rd / 3 + Gd / 3 + Bd / 3
Zd = Int(Abs(Nd - Cd))

Xe = GetPixel(dc, heng - 8, zong)
Re = (Xc Mod 256) \ 16
Ge = (Xc Mod 65536) \ 256
Be = (Xc Mod 16777216) \ 65536
ReleaseDC dc, 0
Ne = Re / 3 + Ge / 3 + Be / 3
Ze = Int(Abs(Ne - Ce))



Text5.Text = Za & "*" & Zb & "*" & Zc & "*" & Zd & "*" & Ze

If Za > 25 Or Zb > 25 Or Zc > 25 Or Zc > 25 Or Zc > 25 Then
Sleep (50)
Else
Exit Sub
End If
If Za > 25 Or Zb > 25 Or Zc > 25 Or Zc > 25 Or Zc > 25 Then
M = M + 1
Text1.Text = M & "辆"
T1 = GetTickCount()
DoEvents
Sleep (50)
Else
Exit Sub
End If
Timer2.Enabled = True
DoEvents
Timer1.Enabled = False
End Sub

'/////////第二个检测点////////////////
Private Sub Timer2_Timer()
Dim dc1 As Long
Dim X1a As Long, X1b As Long, X1c As Long, X1d As Long, X1e As Long
Dim R1a As Byte, G1a As Byte, B1a As Byte, R1b As Byte, G1b As Byte, B1b As Byte, R1c As Byte, G1c As Byte, B1c As Byte, R1d As Byte, G1d As Byte, B1d As Byte, R1e As Byte, G1e As Byte, B1e As Byte
Dim T As Single
Dim V As Single


dc1 = GetDC(0)
X1a = GetPixel(dc1, heng1, zong1)
R1a = (X1a Mod 256) \ 16
G1a = (X1a Mod 65536) \ 256
B1a = (X1a Mod 16777216) \ 65536
ReleaseDC dc1, 0
N1a = R1a / 3 + G1a / 3 + B1a / 3
Z1a = Int(Abs(N1a - C1a))

X1b = GetPixel(dc1, heng1 - 16, zong1)
R1b = (X1b Mod 256) \ 16
G1b = (X1b Mod 65536) \ 256
B1b = (X1b Mod 16777216) \ 65536
ReleaseDC dc1, 0
N1b = R1b / 3 + G1b / 3 + B1b / 3
Z1b = Int(Abs(N1b - C1b))

X1c = GetPixel(dc1, heng1 + 16, zong1)
R1c = (X1c Mod 256) \ 16
G1c = (X1c Mod 65536) \ 256
B1c = (X1c Mod 16777216) \ 65536
ReleaseDC dc1, 0
N1c = R1c / 3 + G1c / 3 + B1c / 3
Z1c = Int(Abs(N1c - C1c))

X1d = GetPixel(dc1, heng1 + 8, zong1)
R1d = (X1d Mod 256) \ 16
G1d = (X1d Mod 65536) \ 256
B1d = (X1d Mod 16777216) \ 65536
ReleaseDC dc1, 0
N1d = R1d / 3 + G1d / 3 + B1d / 3
Z1d = Int(Abs(N1d - C1d))

X1e = GetPixel(dc1, heng1 - 8, zong1)
R1e = (X1e Mod 256) \ 16
G1e = (X1e Mod 65536) \ 256
B1e = (X1e Mod 16777216) \ 65536
ReleaseDC dc1, 0
N1e = R1e / 3 + G1e / 3 + B1e / 3
Z1e = Int(Abs(N1e - C1e))
If Z1a > 45 Or Z1b > 45 Or Z1c > 45 Or Z1d > 45 Or Z1e > 45 Then
Sleep (50)
Else
Exit Sub
End If

If Z1a > 45 Or Z1b > 45 Or Z1c > 45 Or Z1e > 45 Or Z1d > 45 Then
T2 = GetTickCount()
T = T2 - T1
V = Format(3.6 * S / T, "#0")

Text2.Text = Text2.Text & Space(1) & V & "Km/h" & Chr(13) & Chr(10)
Text3.Text = Text3.Text & M & Chr(13) & Chr(10)
Sleep (600)
Else
Exit Sub
End If
Timer1.Enabled = True
DoEvents
Timer2.Enabled = False
End Sub

'/////////自定义检测点/////////////

Private Sub Timer4_Timer()
Dim P As POINTAPI
GetCursorPos P '获取鼠标屏幕中的位置
ScreenToClient Me.hwnd, P '转换为本窗体的坐标
If GetAsyncKeyState(vbKeyQ) Then '按下Q键时
Picture2.Visible = True
heng = P.X + 8 + Me.Left / 15
zong = P.Y + 30 + Me.Top / 15
Xheng = P.X - 16
Xzong = P.Y - 2
Picture2.Left = Xheng * 15
Picture2.Top = Xzong * 15
End If
If GetAsyncKeyState(vbKeyW) Then
Picture3.Visible = True
heng1 = P.X + 8 + Me.Left / 15
zong1 = P.Y + 30 + Me.Top / 15
Xheng = P.X - 16
Xzong = P.Y - 2
Picture3.Left = Xheng * 15
Picture3.Top = Xzong * 15
End If
If GetAsyncKeyState(vbKeyE) Then
Picture4.Visible = True
heng2 = P.X + 8 + Me.Left / 15
zong2 = P.Y + 30 + Me.Top / 15
Xheng = P.X - 16
Xzong = P.Y - 2
Picture4.Left = Xheng * 15
Picture4.Top = Xzong * 15
End If
If GetAsyncKeyState(vbKeyR) Then
Picture5.Visible = True
heng3 = P.X + 8 + Me.Left / 15
zong3 = P.Y + 30 + Me.Top / 15
Xheng = P.X - 16
Xzong = P.Y - 2
Picture5.Left = Xheng * 15
Picture5.Top = Xzong * 15
End If
If GetAsyncKeyState(vbKeyT) Then
Picture6.Visible = True
heng4 = P.X + 8 + Me.Left / 15
zong4 = P.Y + 30 + Me.Top / 15
Xheng = P.X - 16
Xzong = P.Y - 2
Picture6.Left = Xheng * 15
Picture6.Top = Xzong * 15
End If
If GetAsyncKeyState(vbKeyY) Then
Picture7.Visible = True
heng5 = P.X + 8 + Me.Left / 15
zong5 = P.Y + 30 + Me.Top / 15
Xheng = P.X - 16
Xzong = P.Y - 2
Picture7.Left = Xheng * 15
Picture7.Top = Xzong * 15
End If
End Sub
Private Sub Timer5_Timer()
Dim dc2 As Long
Dim X2a As Long, X2b As Long, X2c As Long, X2d As Long, X2e As Long
Dim R2a As Byte, G2a As Byte, B2a As Byte, R2b As Byte, G2b As Byte, B2b As Byte, R2c As Byte, G2c As Byte, B2c As Byte, R2d As Byte, G2d As Byte, B2d As Byte, R2e As Byte, G2e As Byte, B2e As Byte
Dim T2 As Single
Dim V As Single


dc2 = GetDC(0)
X2a = GetPixel(dc2, heng2, zong2)
R2a = (X2a Mod 256) \ 16
G2a = (X2a Mod 65536) \ 256
B2a = (X2a Mod 16777216) \ 65536
ReleaseDC dc2, 0
N2a = R2a / 3 + G2a / 3 + B2a / 3
Z2a = Int(Abs(N2a - C2a))

X2b = GetPixel(dc2, heng2 - 16, zong2)
R2b = (X2b Mod 256) \ 16
G2b = (X2b Mod 65536) \ 256
B2b = (X2b Mod 16777216) \ 65536
ReleaseDC dc2, 0
N2b = R2b / 3 + G2b / 3 + B2b / 3
Z2b = Int(Abs(N2b - C2b))

X2c = GetPixel(dc2, heng2 + 16, zong2)
R2c = (X2c Mod 256) \ 16
G2c = (X2c Mod 65536) \ 256
B2c = (X2c Mod 16777216) \ 65536
ReleaseDC dc2, 0
N2c = R2c / 3 + G2c / 3 + B2c / 3
Z2c = Int(Abs(N2c - C2c))

X2d = GetPixel(dc2, heng2 + 8, zong2)
R2d = (X2d Mod 256) \ 16
G2d = (X2d Mod 65536) \ 256
B2d = (X2d Mod 16777216) \ 65536
ReleaseDC dc2, 0
N2d = R2d / 3 + G2d / 3 + B2d / 3
Z2d = Int(Abs(N2d - C2d))

X2e = GetPixel(dc2, heng2 - 8, zong2)
R2e = (X2e Mod 256) \ 16
G2e = (X2e Mod 65536) \ 256
B2e = (X2e Mod 16777216) \ 65536
ReleaseDC dc2, 0
N2e = R2e / 3 + G2e / 3 + B2e / 3
Z2e = Int(Abs(N2e - C2e))



Text10.Text = Z2a & "*" & Z2b & "*" & Z2c & "*" & Z2d & "*" & Z2e

If Z2a > 25 Or Z2b > 25 Or Z2c > 25 Or Z2d > 25 Or Z2e > 25 Then
Sleep (50)
Else
Exit Sub
End If

If Z2a > 25 Or Z2b > 25 Or Z2c > 25 Or Z2d > 25 Or Z2e > 25 Then

M1 = M1 + 1
Text12.Text = M1 & "辆"


T12 = GetTickCount()
DoEvents
Sleep (50)
Else
Exit Sub
End If
Timer6.Enabled = True
DoEvents
Timer5.Enabled = False
End Sub
Private Sub Timer6_Timer()
Dim dc3 As Long
Dim X3a As Long, X3b As Long, X3c As Long, X3d As Long, X3e As Long
Dim R3a As Byte, G3a As Byte, B3a As Byte, R3b As Byte, G3b As Byte, B3b As Byte, R3c As Byte, G3c As Byte, B3c As Byte, R3d As Byte, G3d As Byte, B3d As Byte, R3e As Byte, G3e As Byte, B3e As Byte
Dim T2 As Single
Dim V2 As Single


dc3 = GetDC(0)
X3a = GetPixel(dc3, heng3, zong3)
R3a = (X3a Mod 256) \ 16
G3a = (X3a Mod 65536) \ 256
B3a = (X3a Mod 16777216) \ 65536
ReleaseDC dc3, 0
N3a = R3a / 3 + G3a / 3 + B3a / 3
Z3a = Int(Abs(N3a - C3a))

X3b = GetPixel(dc3, heng3 - 16, zong3)
R3b = (X3b Mod 256) \ 16
G3b = (X3b Mod 65536) \ 256
B3b = (X3b Mod 16777216) \ 65536
ReleaseDC dc3, 0
N3b = R3b / 3 + G3b / 3 + B3b / 3
Z3b = Int(Abs(N3b - C3b))

X3c = GetPixel(dc3, heng3 + 16, zong3)
R3c = (X3c Mod 256) \ 16
G3c = (X3c Mod 65536) \ 256
B3c = (X3c Mod 16777216) \ 65536
ReleaseDC dc3, 0
N3c = R3c / 3 + G3c / 3 + B3c / 3
Z3c = Int(Abs(N3c - C3c))

X3d = GetPixel(dc3, heng3 + 8, zong3)
R3d = (X3d Mod 256) \ 16
G3d = (X3d Mod 65536) \ 256
B3d = (X3d Mod 16777216) \ 65536
ReleaseDC dc3, 0
N3d = R3d / 3 + G3d / 3 + B3d / 3
Z3d = Int(Abs(N3d - C3d))

X3e = GetPixel(dc3, heng3 - 8, zong3)
R3e = (X3e Mod 256) \ 16
G3e = (X3e Mod 65536) \ 256
B3e = (X3e Mod 16777216) \ 65536
ReleaseDC dc3, 0
N3e = R3e / 3 + G3e / 3 + B3e / 3
Z3e = Int(Abs(N3e - C3e))
If Z3a > 45 Or Z3b > 45 Or Z3c > 45 Or Z3d > 45 Or Z3e > 45 Then
Sleep (50)
Else
Exit Sub
End If
If Z3a > 45 Or Z3b > 45 Or Z3c > 45 Or Z3e > 45 Or Z3d > 45 Then

T22 = GetTickCount()
T2 = T22 - T12
V2 = Format(3.6 * S2 / T2, "#0")

Text9.Text = Text9.Text & Space(1) & V2 & "Km/h" & Chr(13) & Chr(10)
Text4.Text = Text4.Text & M & Chr(13) & Chr(10)
Sleep (600)
Else
Exit Sub
End If
Timer5.Enabled = True
DoEvents
Timer6.Enabled = False
End Sub
搜索更多相关主题的帖子: 动态 检测 
2013-12-20 22:04
wxadrtyu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-12-20
收藏
得分:0 
问题主要是我这个程序是设置了4个picture控件分别检测两个位置,但是有问题~~~
但是两个的时候就没有问题~~这是怎么回事?
2013-12-20 22:21
seafish011
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:167
专家分:694
注 册:2011-11-8
收藏
得分:7 
你发这么多代码出来,倒不如直接发个编译程序出来
2013-12-20 23:49
wxadrtyu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-12-20
收藏
得分:0 
回复 3楼 seafish011
怎么发??
2013-12-21 10:21
seafish011
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:167
专家分:694
注 册:2011-11-8
收藏
得分:0 
如果你的源程序代码不涉及保密协议或者担心泄漏的话,那就整个工程代码打包发出来,这样的话方便大家测试调试。如果不方便发源代码的话,那就新建个工程把相关代码及控件添加好了再打包发上来。
2013-12-21 12:55
vbvcr51
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:18
帖 子:364
专家分:1724
注 册:2013-11-3
收藏
得分:7 
是的。发这么代码干什么。菜的连问题都不会问了。
2013-12-21 15:09
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:7 
目测这样的东东用vb6.0

无知
2013-12-24 13:28
快速回复:动态物体的检测代码!!!!求大家帮忙看看有什么问题~~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029129 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved