스나군 작업실

JavaCV: Capture/save/flip image and show live image on CanvasFrame from camera 본문

Java/라이브러리

JavaCV: Capture/save/flip image and show live image on CanvasFrame from camera

스나군 2012. 1. 4. 20:37
원문 : http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/javacv-capture-save-flip-show-live.html



JAVA CODE:
import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage; import com.googlecode.javacv.CanvasFrame; import com.googlecode.javacv.FrameGrabber; import com.googlecode.javacv.VideoInputFrameGrabber; import com.googlecode.javacv.cpp.opencv_core.IplImage; public class GrabberShow implements Runnable { //final int INTERVAL=1000;///you may use interval IplImage image; CanvasFrame canvas = new CanvasFrame("Web Cam"); public GrabberShow() { canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); } @Override public void run() { FrameGrabber grabber = new VideoInputFrameGrabber(1); int i=0; try { grabber.start(); IplImage img; while (true) { img = grabber.grab(); if (img != null) { cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise cvSaveImage((i++)+"-aa.jpg", img); // show image on window canvas.showImage(img); } //Thread.sleep(INTERVAL); } } catch (Exception e) { } } }


Test: public class TestGrabber { public static void main(String[] args) { GrabberShow gs = new GrabberShow(); Thread th = new Thread(gs); th.start(); } }

'Java > 라이브러리' 카테고리의 다른 글

JavaCV : Capture Image from webcam  (0) 2012.01.04
OpenCV-JavaCV : eclipse project configuration windows 7  (0) 2012.01.04
Comments