2012-04-02 67 views
0

在我的代碼的一部分,有時我有:我如何檢查圖像的類型?

Image<Gray, byte> imtemp = cap.QueryGrayFrame(); 

Image<Bgr, byte> imtemp = cap.QueryFrame(); 

取決於如果視頻幀是灰度或彩色。

現在在一個函數中,我想寫一個命令來檢查變量imtemp是BGR類型還是Gray。我應該如何編寫這樣的if語句?

僞代碼可能是這樣的:

if (the imtemp is BGR) do 
else if (imtemo is grayscale) do.... 

感謝

+1

你就不能檢查,如果'imtermp是圖片'或'imtermp是圖片'? – 2012-04-02 18:22:42

+0

是的,但我應該如何編寫if語句命令? – 2012-04-02 18:33:06

回答

1

你可以寫你的,如果別的喜歡:

if (imtemp is Image<Gray, byte>) 
{ 
    //The image is from QueryGrayFrame 
} 
else if (imtermp is Image<Bgr, byte>) 
{ 
    //The image is from QueryFrame 
} 
+0

是的,但該檢查的可接受命令是什麼? {c#沒有任何命令} – 2012-04-02 19:22:28

+0

你試過了嗎?另外C#確實有[是](http://msdn.microsoft.com/en-us/library/scekt9xw%28v=vs.71%29.aspx)運算符。 – 2012-04-02 19:26:55