问题描述
我使用的是我们购买的热成像仪的SDK。实际上我是一个PHP Web开发人员,现在我必须用.Net编写代码
private void OnDetect(CallbackEventArgument callbackArgument)
{
var detectionResult = callbackArgument.GetDetectionResult();
var firstDetection = detectionResult.Sequence.Items.First();
var message = string.Empty;
ImageArgument fullSizeImage = null;
switch (detectionResult.Type)
{
case T3DDetectionType.OBSERVATION:
message = "Track ID: " + firstDetection.TrackId;
fullSizeImage = detectionResult.RGBImage;
break;
case T3DDetectionType.DEPTH_LIVEnesS:
case T3DDetectionType.THERMAL_LIVEnesS:
message = "Track ID: " + firstDetection.TrackId + " score: " + (firstDetection as Liveness).score.ToString("N0");
fullSizeImage = detectionResult.FullImage;
break;
case T3DDetectionType.TEMPERATURE:
message = "Temperature: " + (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
fullSizeImage = detectionResult.FullImage;
break;
}
因此,我想做的是能够在案件之后获取(firstDetection as Liveness).score.ToString("N0")
,firstDetection.TrackId
和(firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C"
的数据并创建一个JSON。
创建json可行,但是我无法调用数据。
解决方法
如果您希望在switch语句中使用某些内容,则只需执行以下操作:
- 在switch语句之前声明一个变量
string firstDetection = string.Empty;
- 然后将所需的值分配给开关盒内的该变量。
case T3DDetectionType.TEMPERATURE:
message = "Temperature: " + (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
firstDetection = (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
fullSizeImage = detectionResult.FullImage;
break;
现在,在switch语句之后,您将在变量firstDetection
中拥有所需的值。