程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> javacv-JavaCV調用攝像頭如何調節分辨率?高分 求高手

javacv-JavaCV調用攝像頭如何調節分辨率?高分 求高手

編輯:編程綜合問答
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();     
}

}

最佳回答:


參考官方的例子: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();

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved