求高手! 想用JavaCV獲取攝像頭圖像並拍照,買的高分辨率的攝像頭,可是拍出來的照片才55kb,遠不及直接連電腦拍出來的效果,請教如何在java程序中調節分辨率
http://blog.csdn.net/sivyer123/article/details/22411861 這是示例程序
public class video
{
public static void main(String[] args) throws Exception
{
final String savedImageFile = "d:\\my.jpg"; //拍攝所存儲的文件
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
grabber.start(); //開始獲取攝像頭數據
IplImage image =grabber.grab(); //將所獲取攝像頭數據放入IplImage
int width = image.width();
int height = image.height();
final BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D bGraphics = bImage.createGraphics();
CanvasFrame canvas = new CanvasFrame("Camera",1);
canvas.setCanvasSize(width, height);
canvas.getCanvas().addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
try{
ImageIO.write(bImage, "jpg", new File(savedImageFile));//數據寫入my.jpg
}
catch (IOException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
while(canvas.isVisible() && (image=grabber.grab()) != null){
canvas.showImage(image);
bGraphics.drawImage(image.getBufferedImage(),null,0,0);
}
cvReleaseImage(image);
grabber.stop();
canvas.dispose();
}
}
參考官方的例子:https://github.com/bytedeco/javacv/blob/master/samples/WebcamAndMicrophoneCapture.java
int captureWidth = 1280;
int captureHeight = 720;
// The available FrameGrabber classes include OpenCVFrameGrabber (opencv_highgui),
// DC1394FrameGrabber, FlyCaptureFrameGrabber, OpenKinectFrameGrabber,
// PS3EyeFrameGrabber, VideoInputFrameGrabber, and FFmpegFrameGrabber.
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(WEBCAM_DEVICE_INDEX);
grabber.setImageWidth(captureWidth);
grabber.setImageHeight(captureHeight);
grabber.start();