我想在我的Java應用程序中流式傳輸我的攝像頭以獲得一些圖像處理內容。我正在使用OpenCV和Java庫文件。使用Java在opencv中的攝像頭流
我得到了如何捕捉圖像,但如何像視頻一樣捕捉和顯示幀。
請在下面的代碼或其他替代方法建議修改。
我使用Java Swing Application開發。
package openc;
import org.opencv.core.*;
public class openc {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
openc window = new openc();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public openc() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Canvas canvas = new Canvas();
frame.getContentPane().add(canvas, BorderLayout.CENTER);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture camera = new VideoCapture(0);
if(!camera.isOpened()){
System.out.println("Error");
}
else {
Mat iframe = new Mat();
while(true){
if (camera.read(iframe)){
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
iframe.width() + " Height " + iframe.height());
while(true){
Highgui.imwrite(canvas, iframe);
}
}
}
}
camera.release();
}
}
Highgui.imwrite(canvas,iframe); //可能不會編譯 – berak 2014-09-03 13:49:32
檢查JavaCV。可能你會在那裏得到教程! – 2014-09-03 13:54:46