我正试图从闪烁的光线中解读莫尔斯。 我有一个正在看光源的相机,光源在莫尔斯电码中闪烁某个字母或信息。
我正在尝试计算灯光所在的帧数,并根据该数字,然后是点或短划线。当灯闪烁时,我输出的是用户界面上的文本框中的点还是破折号,然后在一段时间没有收到任何闪烁后,可以安全地假设这是消息的结束所以我可以将整个邮件输出到文本框中。
现在我只做信件,没有复杂的信息,而且只在某些时候才有效。 似乎随机出现的问题是
我怎样才能解决上述问题?而且我想知道是否有人有一些提示如何使这个代码更有效?
以下是我现在的代码。我正在使用60fps(或者它说的)相机VS2010和Emgu CV
int led_on = 0;
for(int i = x; i < height; i+=pixeljump)
{
for(int j = y; j< width; j+=pixeljump)
{
byte a = frameColorDisplay->Data[i,j,0]; //once i find the first spot of light, I'm only concerned with the pixels in the i
if(a > 225){ //in the immediate vicinity because the camera and the light source are stationary
frameOn++;
frameOff = 0;
led_on = 1;
x = i;
y = j;
pixeljump = 1;
height = i + 10;
width = j + 10;
//tbMorse->Text = "I see the light";
break;
}
}
}
if(led_on == 0){
frameOff++;
}
if((frameOff > 15) && ((frameOn > 15) && (frameOn <=25))){ //if the number of frames the light is on is between 15 and 25, its a dot
tbMorse->Text = "That's a dot";
//tbMorse->Text=String::Format("{0:F}",frameOn);
Morse+= ".";
frameOn = 0;
frameOff = 0;
signalreceived = 1;
}else if((frameOff > 15) && (frameOn > 25)){ //if it's greater than 25, it's a dash
tbMorse->Text = "That's a dash";
//tbMorse->Text=String::Format("{0:F}",frameOn);
Morse+= "-";
frameOn = 0;
frameOff = 0;
signalreceived = 1;
}
if((frameOff > 60) && (signalreceived == 1)){ //if it's off for a full second, its safe to send the message
text += Morse2Text(Morse);
String ^managedString = marshal_as<String^>( text );
//String ^managedString = marshal_as<String^>( Morse );
tbMorse->Text = managedString;
text.clear();
Morse.clear();
signalreceived = 0;
frameOn = 0;
frameOff = 0;
}
这些是我对全局变量的声明
int frameOn = 0;
int frameOff = 0;
int x = 0;
int y = 0;
int pixeljump = 25;
int height;
int width;
int signalreceived = 0;
string Morse;
string text;
string Morse2Text(string morse);
高度和宽度最初初始化为框架的高度和宽度。 Morse2Text函数接受一串点和破折号,通过一大块if语句来查看点和破折号对应的内容,并返回点和破折号的字母值。