맞춤검색
2009.03.13 13:53

Android Emulator에서의 웹캠(Web Cam) 데이터를 보여주는 코드(IP를 이용한 방식)

<출처: http://www.tomgibara.com/android>

Live Camera Previews in Android

This code replaces an earlier version which is still available

The Android SDK provided by Google doesn't provide any camera emulation beyond a stand-in animation (see below). Since Google haven't yet provided a working implementation (or even a date by which one will be available), I'm publishing the source code for a set of temporary classes that I wrote to overcome this limitation. It's the first code I wrote on the Android platform, and it was written in haste, though it has functioned very well for me.

The code is public domain. I make no warranty as to its fitness for any particular purpose.

The code consists of:

  • CameraSource
    A light interface that protects client code from the choice of camera.
  • GenuineCamera
    A CameraSource implementation that uses the device's camera.
  • HttpCamera
    A CameraSource implementation that GETs images over an HTTP connection.
  • SocketCamera
    A CameraSource implementation that obtains images directly over a TCP/IP connection.
  • BitmapCamera
    A CameraSource implementation that uses a supplied bitmap.
  • WebcamBroadcaster
    A small Java application that uses JMF to broadcast captured stills over the network.

Results

When drawing the output of the genuine camera to screen, you will see something that looks like this:

Device's Camera preview output.

When drawing the output of a remote camera that is obtaining frames from a running webcam broadcaster you would see this (if you were stood over my desk).

Still obtained from a webcam broadcaster.

To save myself more time, I chose to produce a small settings configuration activity too (the code for which is not included).

A simple configuration activity for the camera settings.

Usage

Using a camera source is very simple:

CameraSource cs = new SocketCamera("192.168.0.100", 9889, 320, 240, true); if (!cs.open()) { /* deal with failure to obtain camera */ } while(/*some condition*/) { cs.capture(canvas) //capture the frame onto the canvas } cs.close();

The HttpCamera implementation should be able to obtain stills from any HTTP serving webcam or webcam software. At present I am using WebCam2000 which I run under Windows XP.

Fabian Necci kindly emailed me to let me know that he has successfully used this code on a MacBook using EvoCam to publish JPEG frames to an internal web server. Other software should be available on other systems.

Torben Vesterager has used the code with his MacBook Pro laptop which has Apple's own iSight built-in. He reports that the camera only supports YUVFormats and so had to change the code in the WebcamBroadcaster to use YUVFormat instead of RGBFormat.

Jeffrey Sharkey has used Gentoo Linux with a Logitech QuickCam express using the WebcamBroadcaster and the Linux-native JMF library. He followed this by using DV4Linux to get JMF to recognize his firewire MiniDV camera. This gave him much clearer pictures in Android; he wrapped his JMF calls using the dv4lstart utility:

dv4lstart jmfinit dv4lstart java WebcamBroadcaster
If you successfully use this code on a platform other than those listed above, or have used other webcam software, please let me know so that I can include it in this documentation for the benefit of others.

The SocketCamera implementation relies on a WebcamBroadcaster to be serving webcam stills from the address & port specified in its constructor.

To run a WebcamBroadcaster you will need JMF installed and you may need to supply the library location to the JVM when you run the application (this depends on how you install it). For example, on my machine (currently Windows XP) I use:

java "-Djava.library.path=C:\Program Files\JMF2.1.1e\lib" WebcamBroadcaster

You can pass the following combination of parameters to the application, all of which are strictly positive integers (all dimensions in pixels):

  • WebcamBroadcaster port
  • WebcamBroadcaster width height
  • WebcamBroadcaster width height port

Alternatively, you may provide no parameters, in which case the defaults are width: 320, height: 240 and port: 9889.


예전 코드가 아니라서 약간의 변형이 필요하다.
사용자의 노트에는 이 방식으로는 1~2s 의 딜레이가 생겼고 프레임이 끊기는 문제가 발생하였다고 하는데..
하여간 애뮬레이터에 웹캠 데이터를 받는 방법을 찾고 있었던 나로써는 행운인듯...

Trackback 2 Comment 2
  1. monster turbine pro gold audiophile in-ear speakers 2012.10.22 12:02 신고 address edit & del reply

    필요하다. Making use of state-of-the-art style and design and effective speaker isolation technology, dr. dre beats make far better utilization of energy and vitality to additional boost the power of sensation low. Hip-hop is definitely an important component of the component, and hip-hop and road dance are important for the other component could be the music, http://greatmonsterbeats.com/products/turbine-pro-gold-audiophile-in%252dear-speakers.html turbine pro gold audiophile in-ear speakers

  2. timberland hombre 2012.12.23 01:30 신고 address edit & del reply

    Southwest Airlines has announced a discount sale of its most popular routes through the summer, http://timberlandbotases.com zapatillas timberland mujer. This sale is for people who is planning a family vacation but also for the romantic retreat ang a girlfriend getaway, http://timberlandbotases.com timberland niños.With flights valid through Oct, http://timberlandbotases.com timberland botas mujer. 28, you have plenty of options, http://timberlandbotases.com timberland botas outlet!Here are some popular one-way fares starting at $49:, http://timberlandbotases.com timberland calzado? Boston flights to Baltimore??Cleveland flights to Chicago??Phoenix flights to Las Vegas??Denver flights to Salt Lake City??Dallas flights to Austin, http://timberlandbotases.com timberland botas dama??Los Angeles flights to OaklandRelated articles:


    http://rebirthstudio.tistory.com/179 La Cour de Cassation a validé mardi la remise du Rwandais hutu Callixte Mbarushimana à la Cour pé

    http://phoenixjournals.tistory.com/46 Le blocus du QG d'Alassane Ouattara à Abidjan "sera levé" si les ex-rebelles qui s'y trouvent vont



티스토리 툴바