0
    private void ProcessFrame(object sender, EventArgs arg)
    {
        Wrapper cam = new Wrapper();

        //show the image in the EmguCV ImageBox
        WebcamPictureBox.Image = cam.start_cam(capture).Resize(390, 243, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC).ToBitmap();
        FaceDetectedLabel.Text = "Faces Detected : " + cam.facesdetected.ToString();
    }

私は C# Windows アプリケーションに取り組んでいます。私は簡単な質問で立ち往生しています:

条件で if else を実行するにはどうすればよいですか: If " cam.facesdetected.ToString() " if equal or more 2 do sth, else do nothing.

これを試してみましたが、うまくいかないようです。誰でも私を助けることができますか?

        cam.facesdetected = abc;
        MessageBox.Show("The detected faces is:" + abc);

        if (abc >= 2)
        {
            //Do action 
        }

        else
        {
            //Do nothing
        }
4

5 に答える 5

2

あなたは出来る:

if (Convert.ToInt32(abc) > 2)
   DoWork()

ABCを最初は整数として宣言するのが賢明でしょうが、それが常に整数である場合。

于 2012-12-04T18:02:09.810 に答える
2

私はあなたがあなたのifステートメントを逆に持っていると信じています。

abc = cam.facesdetected;

これで、リストしたように、を操作できますabc

于 2012-12-04T18:02:27.690 に答える
0

左側の変数は右側の変数でのみ割り当てることができます

LHS=RHS

あなたはそれを間違って割り当てたに違いありませんabc = cam.facesdetected;

TryParse方法を使用して、2以上であるかどうかを確認できます。

   bool result = Int32.TryParse(abc, out number);
      if (result)
      {
         if(number>=2)
        {
          //dowork;   
         }   
      }
于 2012-12-04T18:02:58.017 に答える
0

数字を使用する.ToString()場合は使用しないでください。

間違った方法で変数を割り当てています。これは

var abc = cam.facesdetected;

cam.facesdetected が数値でない場合は、使用します

var abc = Convert.ToInt32(cam.facesdetected);

その後

if (Convert.ToInt32(abc) >= 2)
{
   //Do action 
}
于 2012-12-04T18:10:56.040 に答える
0

新しい変数を割り当てずに使用する必要があると思います。abc変数を使用する必要はありません。次のように直接使用できますcam.facesdetected(数値だと思います):

    MessageBox.Show("The detected faces is:" + cam.facesdetected.ToString());

    if (cam.facesdetected >= 2)
    {
        //Do action 
    }

    else
    {
        //Do nothing
    }
于 2012-12-04T18:08:50.420 に答える