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

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笑 Java领域优质创作者 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条)

报告相同问题?

悬赏问题

  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费