ak199015
2015-05-17 13:35
采纳率: 100%
浏览 5.3k
已采纳

JavaCV调用摄像头如何调节分辨率?高分 求高手

求高手! 想用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();     
}

}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

  • 微wx笑 2015-05-17 13:49
    最佳回答

    参考官方的例子: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();
    
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题