2012-05-17 3 views
0

웹캠에서 이미지를 캡처 할 수 있어야하는 Java 프로젝트에 gstreamer 라이브러리를 사용하고 있습니다.웹캠에서 이미지를 캡처하는 방법 WHITEST는 이미 Java Gstreamer로 웹캠에서 스트리밍하고 있습니까?

이미 웹캠 스트림을 표시하는 코드가 있습니다. 옆에있는 버튼을 눌러 이미지를 캡처하는 방법을 알 수 없습니다.

인터넷을 검색했지만 스트림을 표시하거나 이미지를 캡처하는 코드 조각 만 찾을 수는 있지만 둘 다 설명하지 않은 코드 ... 코드 조각을 병합하려했지만 그럴 수 없습니다. 나를 위해 일해도.

이 기능을 사용하려면 어떻게해야합니까?

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); 
      } 
     }); 

    } 
} 

답변

0

camerabin2를 살펴 보셨습니까? 이것은 당신을 위해 (뷰 파인더, 이미지 캡처, 비디오 캡쳐, 효과, ...) 당신을 위해 전체 카메라 워크 플로우를 구현합니다. 기본 접근 방법은 두 번째 스트림을 티 오프하고 선택한 이미지를 캡처하는 것입니다 (예 : 밸브! jpegenc! multifilesink를 사용하고 선택한 이미지에 대해 밸브 열기). 또는 이미지 절약 파이프 또는 출력 선택기를 사용하여 버퍼 프로브 (hacky)를 사용하십시오.