請問用JAVA抓取CCD影像並儲存的問題 |
尚未結案
|
marksman7296
一般會員 發表:1 回覆:1 積分:0 註冊:2004-08-04 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
懶懶泥
一般會員 發表:22 回覆:41 積分:12 註冊:2003-02-11 發送簡訊給我 |
我有一個sample,不過不知道合不何你用! import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.format.*;
import javax.media.util.*; /**
* Grabs a frame from a Webcam, overlays the current date and time, and saves the frame as a PNG to c:\webcam.png
*
* @author David
* @version 1.0, 16/01/2004
*/
public class FrameGrab
{
public static void main(String[] args) throws Exception
{
// Create capture device
CaptureDeviceInfo deviceInfo = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
Player player = Manager.createRealizedPlayer(deviceInfo.getLocator());
player.start();
// Wait a few seconds for camera to initialise (otherwise img==null)
Thread.sleep(2500);
// Grab a frame from the capture device
FrameGrabbingControl frameGrabber = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
Buffer buf = frameGrabber.grabFrame();
// Convert frame to an buffered image so it can be processed and saved
Image img = (new BufferToImage((VideoFormat)buf.getFormat()).createImage(buf));
BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
g.drawImage(img, null, null);
// Overlay curent time on image
g.setColor(Color.RED);
g.setFont(new Font("Verdana", Font.BOLD, 16));
g.drawString((new Date()).toString(), 10, 25); // Save image to disk as PNG
ImageIO.write(buffImg, "png", new File("c:\\webcam.png"));
// Stop using webcam
player.close();
player.deallocate();
System.exit(0);
}
}
|
懶懶泥
一般會員 發表:22 回覆:41 積分:12 註冊:2003-02-11 發送簡訊給我 |
我有一個sample,不過不知道合不何你用! import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.format.*;
import javax.media.util.*; /**
* Grabs a frame from a Webcam, overlays the current date and time, and saves the frame as a PNG to c:\webcam.png
*
* @author David
* @version 1.0, 16/01/2004
*/
public class FrameGrab
{
public static void main(String[] args) throws Exception
{
// Create capture device
CaptureDeviceInfo deviceInfo = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
Player player = Manager.createRealizedPlayer(deviceInfo.getLocator());
player.start();
// Wait a few seconds for camera to initialise (otherwise img==null)
Thread.sleep(2500);
// Grab a frame from the capture device
FrameGrabbingControl frameGrabber = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
Buffer buf = frameGrabber.grabFrame();
// Convert frame to an buffered image so it can be processed and saved
Image img = (new BufferToImage((VideoFormat)buf.getFormat()).createImage(buf));
BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
g.drawImage(img, null, null);
// Overlay curent time on image
g.setColor(Color.RED);
g.setFont(new Font("Verdana", Font.BOLD, 16));
g.drawString((new Date()).toString(), 10, 25); // Save image to disk as PNG
ImageIO.write(buffImg, "png", new File("c:\\webcam.png"));
// Stop using webcam
player.close();
player.deallocate();
System.exit(0);
}
}
|
marksman7296
一般會員 發表:1 回覆:1 積分:0 註冊:2004-08-04 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |