Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use JMF to turn on the camera to get the image

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, I learned to turn on the camera with JMF in JAVA. This Mini Program is still a little difficult for me. Then I found some information on the Internet, the information on the Internet is many and miscellaneous, for us newcomers, do not have the ability to distinguish, take a lot of detours. Now I will show my learning process.

1. Build an environment

My computer is win7 64-bit; then download JDK (search JDK on Baidu) jdk-8u92-windows-i586.exe on orcale's official website (JDK must be 32-bit, at least on my computer. I never succeeded in installing 64-bit. Finally, I found out that JMF is 32-bit, and the supporting JDK must also be 32-bit. This is how I understand it. (hehe); then download JMF (search JMF directly in Baidu, you can directly jump to the JMF download on the official website of oracle, which is much more convenient than looking for it directly on the official website of oracle) jmf-2_1_1e-windows-i586.exe,JMF is recommended to be installed under jdk, which eliminates the configuration environment variables.

two。 Environment configuration and testing

JDK and JMF are installed, and then there is the configuration of JDK environment variables, which in turn opens: computer right-click Properties > Advanced system Settings > Environment variables > system variables 1) the new JAVA_HOME variable is the installation path of jdk just now D:\ Application\ java\ jdk1.6.0_25

2) PATH variable% JAVA_HOME%\ bin;%JAVA_HOME%\ jre\ bin

3) CLASSPATH variable.;% JAVA_HOME%\ lib\ dt.jar;%JAVA_HOME%\ lib\ tools.jar (to be added. (indicates current path) check: WIN+R > CMD > javac java java-version indicates that the configuration is successful

Then there is JMF: open the jmfregistry.exe program in the JMF installation directory

After installation, you need to restart the computer before you can use it; a shortcut to JMStudio will be generated on the desktop and open it.

File > Capture will be installed successfully with audio, video, etc., and then you can see yourself through the camera. At this point, our running environment is installed, and then we write code to call the camera.

3. Code

You can use notepad or notepad++. Notepad++ has a plug-in NppAStyle plug-in that formats java code.

Basic principle and process of JMF camera

Get camera information "create camera and capture data stream" create form and panel "load the captured data stream into the form to play

Import java.awt.BorderLayout

Import java.awt.Component

Import javax.media.*;// contains all the media code

Import javax.swing.JFrame; / / create a form through JFrame

Import javax.swing.JPanel; / / A container class

Public class Camera extends JFrame {/ / inherits the framework of the form

Public static Player player = null; / / defines a player variable. Player is a class in the media package

Private CaptureDeviceInfo deviceInfo = null; / / define the intercept device registration information for the manager

Private MediaLocator mediaLocator = null

Private Component component = null

Private JPanel vedioPanel = null

String str = "vfw:Microsoft WDM Image Capture (Win32): 0"; / / get the string of the local camera

Public Camera () {

Init ()

}

Public void init () {

DeviceInfo = CaptureDeviceManager.getDevice (str); / / get the reference of the acquisition device (camera) according to the string

MediaLocator = deviceInfo.getLocator (); / / get the MediaLocator object from the CaptureDevicesInfo object and use it to create a DataSource data source object

/ / get the reference of the locator of the capture device. You need to create a video player based on this reference.

Try {

Player = Manager.createRealizedPlayer (mediaLocator); / / use mediaLocator to get a player and create a player object

Component = player.getVisualComponent (); / / the image part of the player object on which multimedia images can be played

If (component! = null) {

/ *

Set some properties of the form

, /

VedioPanel = new JPanel (); / / Panel container

VedioPanel.add (component, BorderLayout.NORTH)

This.add (vedioPanel)

This.pack (); / / automatically assign form size

This.setResizable (false)

This.setDefaultCloseOperation (EXIT_ON_CLOSE); / / sets the closing of the form

This.setVisible (true)

Player.start (); / / play the captured data stream

}

} catch (Exception e) {

E.printStackTrace ()

}

}

Public static void main (String [] args) {/ / main function

New Camera ()

}

}

In order to understand this thing, the eldest brother suggested that I take this program apart and test it with Mini Program. Due to the limited foundation, I finally came up with only one Mini Program for getting device information, and the window was a little difficult.

Import javax.media.*

Public class INFO {

Public static void main (String [] args) {

CaptureDeviceInfo deviceInfo = null

String str2 = "vfw:Microsoft WDM Image Capture (Win32): 0"; / / get the string of the local camera

DeviceInfo = CaptureDeviceManager.getDevice (str2)

System.out.println ("Local camera Information:" + deviceInfo)

}

}

Although this is a relatively simple Mini Program, but I spent a lot of time to do, in the process also learned some things, at the beginning of anything, but also accompanied by the computer, some do not understand the questions are found in google& Baidu, so that the source code is also. This is the first blog post, there will be a lot of mistakes in the above, welcome to point out

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report