[英]How to capture image from webcam WHILST already streaming from webcam too with Java Gstreamer?
我正在将gstreamer库用于需要能够从网络摄像头捕获图像的Java项目。
我已经有显示网络摄像头视频流的代码,只是无法按一下旁边的按钮就知道如何捕获图像。
我已经在互联网上搜索过,但是只能找到显示流或捕获图像的代码段,但是都没有说明这两个代码...我试图合并这些代码段,但这对我不起作用要么。
我要怎么做才能使它正常工作?
public class WebcamPanel extends JPanel {
private static Pipeline pipe;
public WebcamPanel(){
String[] args = {};
args = Gst.init("Webcam", args);
pipe = new Pipeline("pipeline");
final Element videosrc = ElementFactory.make("dshowvideosrc", "source");
final Element videofilter = ElementFactory.make("capsfilter", "flt");
videofilter.setCaps(Caps.fromString("video/x-raw-yuv, width=320, height=240"));
setLayout(new GridBagLayout());
final GridBagConstraints c = new GridBagConstraints();
JButton takePic = new JButton();
takePic.setPreferredSize(new Dimension(50,50));
c.gridx = 0;
c.insets = new Insets(0,10,0,0);
add(takePic,c);
c.gridx = 2;
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(0,40,0,0);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
VideoComponent videoComponent = new VideoComponent();
Element videosink = videoComponent.getElement();
// This gives 2nd window with stream from webcam
// Element videosink = ElementFactory.make("xvimagesink", "sink");
pipe.addMany(videosrc, videofilter, videosink);
Element.linkMany(videosrc, videofilter, videosink);
videoComponent.setPreferredSize(new Dimension(320, 240));
add(videoComponent,c);
videoComponent.setVisible(true);
// Start the pipeline processing
pipe.setState(State.PLAYING);
}
});
}
}
你看看camerabin2了吗? 这将为您实现整个相机工作流程(取景器,图像捕获,视频字幕,效果等)。 基本方法是开通第二个流并从第二个流中捕获选定的图像(例如,使用valve!jpegenc!multifilesink并为选定的图像打开该阀),或者对图像保存管道使用输出选择器,或者使用缓冲探针(hacky)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.