JAVA Camera Call _ Instance---Win7__java

Source: Internet
Author: User

Original address: http://blog.csdn.net/zajin/article/details/9288239


I rookie-level characters, due to make personal face recognition login (JAVACV), Baidu Google one afternoon, find a simple sample code on the Internet to try, but always debugging, however, appear capturedevicemanager.getdevice as a null pointer. Depressed for an afternoon. Now I finally got it out. This is a souvenir, because on the internet for most of the day, found that this aspect of the introduction is not a lot, so also hope to be able to help the later learners, less take detours.


Function: Implement camera call

Steps: 1, to the Sun download JMF, and installation, after installation need to restart the computer. Download link http://www.oracle.com/technetwork/java/javase/download-142937.html

2. Create environment variables for setting JMF, "Computer"-> "System Properties"-> "Advanced Environment Settings"-> "Advanced"-> "Environment variables"

Variable name: "jmfhome" Variable Value: "C:\Program files\jmf2.1.1e"

Variable name: "CLASSPATH" Variable Value: ";%jmfhome%\lib\jmf.jar;%jmfhome%\lib\sound.jar"

As shown in figure:

3, open the installed JMF, in the C:\Program Files\jmf2.1.1e\bin directory to open "Jmfregistry.exe", select "Capture Devices" and then press the lower left corner "detect Capture Devices button, press a few more times until the "Vfw:microsoft WDM Image Capture (WIN32): 0" appears in the left-hand column, which means that JMF has registered the camera and can then be closed.

As shown in figure:

4, now you can program with Eclipse. Create a project, copy the sample code below, click the right mouse button to select Build path->configure builds path ...->libraries->add External JARs ... Then the installation of the JMF inside the \lib directory to import a few jar packages in.

As shown in figure:


5, the operation can be.

[Java]  View plain copy import java.awt.borderlayout;   import java.awt.component;   import javax.media.capturedeviceinfo;   import javax.media.manager;   import  javax.media.medialocator;   import javax.media.player;   import  javax.media.cdm.capturedevicemanager;   import javax.swing.jframe;   import  javax.swing.jpanel;   public class test extends jframe{        public  static Player player = null;        private CaptureDeviceInfo deviceInfo = null;        private medialocator medialocator = null;       private  component component = null;       private JPanel  vediopanel = null;              String   str1    =    "vfw:logitech   usb   video   camera:0";       //get USB Webcam string        String    str2   =    "vfw:microsoft wdm image capture  (WIN32): 0";     //get the local webcam string        // Creates a new  instance of cameratest        public test ()  {            init ();       }       public void init () {            deviceinfo = capturedevicemanager.getdevice (STR2);   //acquisition Device (camera) reference based on string       &NBSp;  //   system.out.println (deviceinfo);          //Displays the information         //   system.out.println of the Acquisition Device (camera) ( Deviceinfo.getname ())      //Display acquisition device (camera) device name             medialocator = deviceinfo.getlocator ();  //obtain a reference to the locator of the acquisition device, you need to create a video player based on this reference                       &nbs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.