當前位置: 首頁>>代碼示例>>Java>>正文


Java Webcam.setViewSize方法代碼示例

本文整理匯總了Java中com.github.sarxos.webcam.Webcam.setViewSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Webcam.setViewSize方法的具體用法?Java Webcam.setViewSize怎麽用?Java Webcam.setViewSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.sarxos.webcam.Webcam的用法示例。


在下文中一共展示了Webcam.setViewSize方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: takePic

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public void takePic() {
	// get default webcam and open it
	Webcam webcam = Webcam.getDefault();

	Dimension[] nonStandardResolutions = new Dimension[] { WebcamResolution.PAL.getSize(),
			WebcamResolution.HD720.getSize(), new Dimension(2000, 1000), new Dimension(1000, 500), };
	webcam.setCustomViewSizes(nonStandardResolutions);
	webcam.setViewSize(WebcamResolution.HD720.getSize());
	webcam.open();

	// get image
	BufferedImage image = webcam.getImage();

	// save image to PNG file
	try {
		ImageIO.write(image, "PNG", new File("src/capture/test.png"));
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	webcam.close();
}
 
開發者ID:badarshahzad,項目名稱:SudoTimer,代碼行數:23,代碼來源:MainViewController.java

示例2: Capture

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public static void Capture(String filePath, String fileName, int widthx, int heighty) throws IOException {
        Webcam webcam = Webcam.getDefault();
        if (webcam != null) {
//            System.out.println("Webcam: " + webcam.getName());
            webcam.setViewSize(new Dimension(widthx, heighty));
            webcam.open();
            ImageIO.write(webcam.getImage(), "PNG", new File(filePath + fileName + ".png"));
            webcam.close();
        }
    }
 
開發者ID:tiagorlampert,項目名稱:sAINT,代碼行數:11,代碼來源:Cam.java

示例3: run

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
@Override
		public void run() {

			Webcam webcam = Webcam.getDefault();
			webcam.setViewSize(WebcamResolution.VGA.getSize());
			webcam.open();

			JFrame frame=new JFrame();
			frame.setTitle("webcam capture");
//			frame.setLayout(new FlowLayout());
			JLabel lbl = new JLabel();
			frame.add(lbl);
			frame.setVisible(true);
			
			while (true) {
				if (!webcam.isOpen()) break;

				BufferedImage image = webcam.getImage();
				if (image == null) break;

				frame.setSize(image.getWidth(),image.getHeight());
				lbl.setIcon(new ImageIcon(image));
			}
		}
 
開發者ID:cycronix,項目名稱:cloudturbine,代碼行數:25,代碼來源:CTwebcam.java

示例4: main

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {

		Webcam webcam = Webcam.getDefault();
		webcam.setViewSize(WebcamResolution.VGA.getSize());

		WebcamPanel panel = new WebcamPanel(webcam);
		panel.setFPSDisplayed(true);
//		panel.setDisplayDebugInfo(true);
		panel.setImageSizeDisplayed(true);
		panel.setMirrored(true);

		JFrame window = new JFrame("Test webcam panel");
		window.add(panel);
		window.setResizable(true);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.pack();
		window.setVisible(true);
	}
 
開發者ID:cycronix,項目名稱:cloudturbine,代碼行數:19,代碼來源:CTcamera.java

示例5: chooseWebcam

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public static Webcam chooseWebcam()
{
	registerAllIPCams("ipcams.txt");
	Webcam.setDriver(new CompositeDriver());
	Webcam w = (Webcam) JOptionPane.showInputDialog(null, "Choose a webcam", "Select webcam", 
			JOptionPane.PLAIN_MESSAGE, null, 
			Webcam.getWebcams().toArray(),Webcam.getDefault());
	if(w==null)
	{
		System.exit(1);
	}

	PrettyDimension[] dims = new PrettyDimension[w.getViewSizes().length];
	for(int i=0;i<dims.length;i++)
	{
		dims[i] = new PrettyDimension(w.getViewSizes()[i]);
	}
	
	Dimension d = (Dimension) JOptionPane.showInputDialog(null, "Choose a resolution", "Select resolution", 
			JOptionPane.PLAIN_MESSAGE, null, 
			dims,dims[dims.length-1]);
	
	if(d == null)
	{
		System.exit(1);
	}

	w.setViewSize(d);
	
	return w;
}
 
開發者ID:ForOhForError,項目名稱:MTG-Card-Recognizer,代碼行數:32,代碼來源:WebcamUtils.java

示例6: ScanDialog

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
/**
 * Create the dialog
 *
 * @param       parent          Parent frame
 * @param       webcam          Web camera
 */
public ScanDialog(JDialog parent, Webcam webcam) {
    super(parent, "Scan QR Code", Dialog.ModalityType.DOCUMENT_MODAL);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    //
    // Create the webcam panel (this will display the webcam stream to the user)
    //
    this.webcam = webcam;
    webcam.setViewSize(WebcamResolution.VGA.getSize());
    webcamPanel = new WebcamPanel(webcam);
    webcamPanel.setMirrored(true);
    //
    // Create the buttons (Cancel)
    //
    JPanel buttonPane = new ButtonPane(this, 10, new String[] {"Cancel", "cancel"});
    //
    // Set up the content pane
    //
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    contentPane.setOpaque(true);
    contentPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
    contentPane.add(webcamPanel);
    contentPane.add(Box.createVerticalStrut(15));
    contentPane.add(buttonPane);
    setContentPane(contentPane);
    //
    // Set up the barcode reader to look for just QR codes
    //
    barcodeReader = new MultiFormatReader();
    Map<DecodeHintType, Object> hints = new HashMap<>();
    List<BarcodeFormat> formats = new ArrayList<>();
    formats.add(BarcodeFormat.QR_CODE);
    hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
    barcodeReader.setHints(hints);
    //
    // Listen for webcam events (we will scan webcam images looking for a QR code)
    //
    webcam.addWebcamListener(this);
}
 
開發者ID:ScripterRon,項目名稱:BitcoinWallet,代碼行數:46,代碼來源:ScanDialog.java

示例7: webCam

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
private BufferedImage webCam()
{	
	//**get default webcam..set resolution..open it
	Webcam webcam = Webcam.getDefault();
	webcam.setViewSize(WebcamResolution.VGA.getSize());
	webcam.open();
	
	BufferedImage pic = webcam.getImage();
	webcam.close(); // Not sure if webcam should stay open or be closed after each use.
	return pic;
}
 
開發者ID:lo9key,項目名稱:ASCII_Art,代碼行數:12,代碼來源:GUI_ButtonPanel.java

示例8: initCamera

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
static WebcamData initCamera(String cc, String camName)
{
	LinkedHashMap<String, Webcam> detectedCameras = new LinkedHashMap<String, Webcam>();
	List<Webcam> cams = Webcam.getWebcams();
	Webcam webcam = null;
	for (Webcam cam : cams)
	{
		detectedCameras.put(cam.getName(), cam);
		if (cam.getName().startsWith(camName))
		{
			webcam = cam;
		}
	}
	if (webcam == null)
	{
		throw new WebcamInitException("Webcam listed in config was not found: " + camName);
	}
	WebcamData data = new WebcamData(cc, webcam);
	webcam.setImageTransformer(new WebcamTransformer());
	log.info("Initializing webcam: " + camName);
	Dimension[] sizes = webcam.getViewSizes();
	Dimension dimension = null;
	for (Dimension d : sizes)
	{
		log.info("Found image dimension: " + d.getWidth() + "x" + d.getHeight());
		if (d.getWidth() == 320)
		{
			dimension = d;
		}
	}
	if (dimension == null)
	{
		dimension = sizes[0];
	}
	log.info("Selected image dimension: " + dimension.getWidth() + "x" + dimension.getHeight());
	if (!webcam.getViewSize().equals(dimension))
	{
		webcam.setViewSize(dimension);
	}
	webcam.open(true);
	webcam.addWebcamListener(data);
	System.out.println(webcam.getViewSize());
	((WebcamDefaultDevice) webcam.getDevice()).FAULTY = false;
	return data;
}
 
開發者ID:PolyphasicDevTeam,項目名稱:NoMoreOversleeps,代碼行數:46,代碼來源:WebcamCapture.java

示例9: run

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
@Override
public void run(EyeballsConfiguration eyeballsConfiguration, Environment environment) throws Exception {

    Security.addProvider(new BouncyCastleProvider());

    createUnderylingStorageDirectories(eyeballsConfiguration);

    if (eyeballsConfiguration.getUseAuth()) {
        environment.jersey().register(new AuthDynamicFeature(
                new BasicCredentialAuthFilter.Builder<BasicAuthenticator.EyeballUser>()
                        .setAuthenticator(new BasicAuthenticator(eyeballsConfiguration))
                        .setRealm("Eyeballs Motion Detection Server")
                        .buildAuthFilter()));
    }
    DB db = buildMapDb(eyeballsConfiguration);
    BTreeMap<String, MotionEvent> motionEventStore = db.createTreeMap("motionEventStore")
            .valueSerializer(new LocalEventSerializer())
            .makeOrGet();

    Webcam webcam = Webcam.getDefault();
    if (webcam == null) {
        throw new RuntimeException("No webcam present, or not available to the current user.");
    }

    PictureTakingService pictureTakingService = new PictureTakingService(webcam);
    webcam.addWebcamListener(pictureTakingService);

    Dimension[] dimensions = (Dimension[]) Arrays.stream(WebcamResolution.values())
            .map(WebcamResolution::getSize)
            .collect(Collectors.toList())
            .toArray();

    webcam.setCustomViewSizes(dimensions);
    webcam.setViewSize(new Dimension(eyeballsConfiguration.getImageWidth(), eyeballsConfiguration.getImageHeight()));
    webcam.open();

    MotionEventProcessor.Builder processorBuilder = new MotionEventProcessor.Builder();

    if (eyeballsConfiguration.getUseSftp()) {
        processorBuilder.addMotionEventConsumer(new SftpMotionEventConsumer(eyeballsConfiguration));
    }

    if (eyeballsConfiguration.getUseDropbox()) {
        processorBuilder.addMotionEventConsumer(new DropboxMotionEventConsumer(eyeballsConfiguration));
    }

    if (eyeballsConfiguration.getUseLocalPersistence()) {
        LocalFSMotionEventConsumer localFSMotionEventConsumer = new LocalFSMotionEventConsumer(db, eyeballsConfiguration, motionEventStore);
        processorBuilder.addMotionEventConsumer(localFSMotionEventConsumer);
        processorBuilder.motionEventPersitence(localFSMotionEventConsumer);
    }

    if (eyeballsConfiguration.getUseDropboxPersistence()) {
        processorBuilder.motionEventPersitence(new DropBoxMotionEventPersistence(eyeballsConfiguration, motionEventStore));
    }

    processorBuilder.motionEventStore(motionEventStore);

    MotionEventProcessor motionEventProcessor = processorBuilder.build();

    MotionDetectionService motionDetectionService = new MotionDetectionService(eyeballsConfiguration,
            new SaveMotionDetectedListener(motionEventProcessor, eyeballsConfiguration));
    motionDetectionService.startAndWait();

    EyeballsResource eyeballsResource = new EyeballsResource(webcam, motionEventProcessor, pictureTakingService);

    environment.jersey().register(eyeballsResource);
}
 
開發者ID:chriskearney,項目名稱:eyeballs,代碼行數:69,代碼來源:EyeballsApplication.java

示例10: main

import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	new File("img").mkdir();
	
	Reader.init();
	
	JFrame f = new JFrame();
	
	JButton button = new JButton(new AbstractAction("Read aloud!") {
		private static final long serialVersionUID = 1L;
		
		@Override
		public void actionPerformed(ActionEvent e) {
			if (image != null) {
				try {
					Reader.parse(image);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		}
	});
	button.setMnemonic(KeyEvent.VK_SPACE);
	
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	Dimension size = new Dimension(1280, 720);
	
	f.add(button);
	f.setSize(size.width, size.height);
	f.setLocationRelativeTo(null);
	f.setVisible(true);
	
	Webcam webcam = Webcam.getDefault();
	webcam.setCustomViewSizes(new Dimension[] { size });
	webcam.setViewSize(webcam.getCustomViewSizes()[0]);
	
	webcam.open();
	
	while (true) {
		image = webcam.getImage();
		button.setIcon(new ImageIcon(image));
		button.setOpaque(true);
		f.pack();
	}
}
 
開發者ID:Dakror,項目名稱:WebcamParser,代碼行數:46,代碼來源:WebcamParser.java


注:本文中的com.github.sarxos.webcam.Webcam.setViewSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。