与电脑竞争

时间:2019-06-13 11:48:48

标签: vb.net

我想避免分数提高后再运行Button1.PerformClick()。

我尝试了退出子,但这没用。

While passing blob from the network i am getting detection of (1,512) but it should be three dimension. 
# construct a blob from the frame, pass it through the network,
# obtain our output predictions, and initialize the list of
# bounding box rectangles
# frame size is (888, 500, 3)
#blob shape is (1,3,112,96)
#detection shape is (1, 512) 
#code

    blob = cv2.dnn.blobFromImage(frame, 1.0, (96, 112),
    (104, 117, 123),swapRB=True, crop=False )
    print(blob.shape)
    net.setInput(blob)
    detections = net.forward()
    print(detections.shape)
    rects = []
    for i in range(0, detections.shape[2]):
        if detections[0, 0, i, 2] > 0.5:
            box = detections[0, 0, i, 3:7] * np.array([W, H, W, H])
            rects.append(box.astype("int"))
            (startX, startY, endX, endY) = box.astype("int")
            cv2.rectangle(frame, (startX, startY), (endX, endY),
            (0, 255, 0), 2)
即使单击了button2,也会自动单击

button3。

1 个答案:

答案 0 :(得分:0)

您对这段代码的想法非常困惑。首先,您必须打开Option Strict(请参阅我的评论)。这将帮助您了解何时将字符串与数字进行比较,这可能会导致意外结果。文本属性是字符串,可能无法成功与数字进行比较。

第二,为控件使用描述性名称。这将帮助您清除思路

由于您在vb.net中工作,请使用.net中提供的Random类。声明为 表单级别变量。然后,您只需使用.Next方法即可。

我不确定为什么要让Button1.Click不运行,但是有一个.Enabled属性,您可以将其设置为False。

如果您要从多个事件过程中调用代码,请编写自己的Sub或Function并从事件过程中调用它们。

Private Rand As New Random
Private a, b As Integer

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'The text boxes 3 and 4 need a text value that will convert to a valid Integer
    TextBox1.Text = "0" 'Computer's Number
    TextBox2.Text = "0" 'Players's Number
    TextBox3.Text = "0" 'Computer's Score
    TextBox4.Text = "0" 'Player's Score
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    a = Rand.Next
    b = Rand.Next
    TextBox1.Text = a.ToString 'Display Computer's number
    TextBox2.Text = b.ToString 'Display 
    If a = b Then
        MessageBox.Show("It's a tie, try again")
    ElseIf a > b Then
        MessageBox.Show("Computer Wins")
        TextBox3.Text = (CInt(TextBox3.Text) + 1).ToString
    ElseIf a < b Then
        MessageBox.Show("You Win")
        TextBox4.Text = (CInt(TextBox4.Text) + 1).ToString
    End If
    If CInt(TextBox3.Text) = 10 Then 'When the computers score = 10
        Form2.Show()
    End If
End Sub
相关问题