📄 videomodule.java
字号:
package cie.mobile.video;
import name.lxm.robot.arch.*;
import java.awt.Image;
import java.awt.image.BufferedImage;
public class VideoModule implements Module, Runnable
{
private String module_name;
private SimpleOutPort video_port = null;
private String[] port_names = {"video"};
private String x_size;
private String y_size;
private ModuleDoc doc;
private FrameGrabber grabber;
private Thread t_this;
private boolean bRun = false;
private String video_driver;
public VideoModule()
{
}
public String getName()
{
return module_name;
}
public int getLayer()
{
return doc.getLayer();
}
public Port getPort(String name)
{
if(port_names[0].equals(name))
return video_port;
return null;
}
public ModuleDoc getModuleDoc()
{
return doc;
}
public void init(ModuleDoc cfg) throws Exception
{
doc = cfg;
module_name = doc.getName();
video_driver = doc.getParamValue("driver");
video_port = new SimpleOutPort(this, port_names[0]);
x_size = doc.getParamValue("x_size");
y_size = doc.getParamValue("y_size");
grabber = new FrameGrabber(video_driver, x_size, y_size);
}
public void start() throws Exception
{
grabber.start();
t_this = new Thread(this);
bRun = true;
t_this.start();
}
public void stop() throws Exception
{
bRun = false;
int i = 0;
while(t_this.isAlive() && i < 5)
{
try{
Thread.sleep(50);
}catch(InterruptedException e)
{}
}
if(t_this.isAlive())
throw new Exception("Cannot Stop the module " + module_name);
}
public void destroy() throws Exception
{
}
public void run()
{
BufferedImage image;
while(bRun)
{
image = grabber.getBufferedImage();
video_port.setValue(this, image, 2000);
//System.out.println("Send a frame");
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -