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

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条回答 默认 最新

  • testcs_dn
    微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();
    
    
    点赞 评论
  • ak199015
    ak199015 2015-05-17 14:34

    啊 兄弟 真牛啊! 这个GITHUB这么高端 我是咋搜的 我在网上找了半天没找到呢

    点赞 评论
  • testcs_dn
    微wx笑 2015-05-17 21:30

    搜索分辨率相关的是根本搜索不到这个的;
    我也是抱着试试看的态度,因为搜索分辨率根本找不到有用的信息;
    所以想到去JavaCV的官网看看有没有什么帮助。

    点赞 评论
  • u010030591
    云上月去 2015-11-01 11:24

    我想问下,调用摄像头获取的图像全黑是怎么回事,笔记本摄像头灯亮了,摄像头应该是启动了

    点赞 评论

相关推荐